Updated API in tests, updated IPaymentIntentCreationOptions and added Checkouts - Stripe (#36097)

* Started checkout finished PI

* Finished?

* Added checkout, updated API version and PI methods

* Added checkout, updated API version and PI methods

* Update index.d.ts

* Added missing IPaymentIntentCreationOptions option

* Fixed non-optional parameter
This commit is contained in:
opticalgenesis
2019-06-26 11:19:36 -07:00
committed by Benjamin Lichtman
parent 81d2311797
commit 8bba7f91ce
2 changed files with 212 additions and 6 deletions
+191 -5
View File
@@ -22,6 +22,7 @@
// Gokul Chandrasekaran <https://github.com/gokulchandra>
// Jamie Davies <https://github.com/viralpickaxe>
// Christopher Eck <https://github.com/chrisleck>
// Joshua Feltimo <https://github.com/opticalgenesis>
// Josiah <https://github.com/spacetag>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -53,6 +54,7 @@ declare class Stripe {
accounts: Stripe.resources.Accounts;
balance: Stripe.resources.Balance;
charges: Stripe.resources.Charges;
checkout: Stripe.resources.Checkout;
coupons: Stripe.resources.Coupons;
customers: Stripe.resources.Customers;
disputes: Stripe.resources.Disputes;
@@ -1742,6 +1744,176 @@ declare namespace Stripe {
}
}
namespace checkouts {
namespace sessions {
interface ICheckoutSession {
/**
* Unique ID for checkout session to pass to `redirectToCheckout` in Stripe.js
*/
id: string;
/**
* String of object type. Is always 'checkout.session'
*/
object: string;
/**
* Whether or not billing address was collected
*/
billing_address_collection?: string;
/**
* URL the customer will be redirected to upon cancellation
*/
cancel_url: string;
/**
* Unique reference to session
*/
client_reference_id?: string;
/**
* ID of customer
*/
customer?: string;
/**
* Email address of customer
*/
customer_email?: string;
/**
* The line items purchased
*/
display_items: ICheckoutLineItems[];
/**
* If the object is in live mode or not
*/
livemode: boolean;
/**
* Language tag of the checkout session
*/
locale?: string;
/**
* ID of payment intent created
*/
payment_intent?: string;
/**
* Array of accepted payment methods
*/
payment_method_types?: string[];
/**
* ID of subscription if one was created
*/
subscription?: string;
/**
* URL to redirect to upon success
*/
success_url: string;
}
interface ICheckoutCreationOptions {
/**
* The URL to return the customer to if they cancel payment
*/
cancel_url: string;
/**
* A list of accepted payment types.
* 'card' is currently the only supported options
*/
payment_method_types: string[];
/**
* The url to return to upon successful payment
*/
success_url: string;
/**
* Whether to collect shipping info.
* If 'required', info will always be collected.
* When 'auto' or not specified, info will be collected when required
*/
billing_address_collection?: 'required' | 'auto';
/**
* An optional unique ID to associate with the checkout
*/
client_reference_id?: string;
/**
* Must be used with @param line_items
* ID of existing customer to use
*/
customer?: string;
/**
* Email of the customer
*/
customer_email?: string;
/**
* A list of items the customer is purchasing. One-time.
*/
line_items?: ICheckoutLineItems[];
/**
* Language to use. If 'auto' or not specified, browser default is used
*/
locale?: 'auto' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'it' | 'ja' | 'nb' | 'nl' | 'pl' | 'pt' | 'sv' | 'zh';
/**
* Details for creation of payment intent
*/
payment_intent_data?: paymentIntents.IPaymentIntentCaptureOptions;
/**
* Use instead of @param line_items when using a subscription
*/
subscription_data?: subscriptions.ISubscription;
}
interface ICheckoutLineItems {
/**
* Amount to be collected per unit of item
*/
amount: number;
/**
* Currency to collect payment in
*/
currency: string;
/**
* The name of the item
*/
name: string;
/**
* The amount of item being purchased
*/
quantity: number;
/**
* An optional description for the item
*/
description?: string;
/**
* A list of images for the item
*/
images?: string[];
}
}
}
namespace customers {
/**
* Customer objects allow you to perform recurring charges and track multiple charges that are associated
@@ -3962,6 +4134,11 @@ declare namespace Stripe {
*/
currency: string;
/**
* The ID of the payment method used to pay
*/
payment_method?: string;
/**
* The list of payment method types (e.g. card) that this PaymentIntent is allowed to use.
*/
@@ -3982,6 +4159,11 @@ declare namespace Stripe {
*/
confirm?: boolean;
/**
* Whether to use the publishable key automatic method, or the secret key manual method
*/
confirmation_method?: 'automatic' | 'manual';
/**
* ID of the customer this PaymentIntent is for if one exists.
*/
@@ -4025,11 +4207,6 @@ declare namespace Stripe {
*/
shipping?: IShippingInformation;
/**
* ID of the Source object to attach to this PaymentIntent.
*/
source?: string;
/**
* Extra information about a PaymentIntent. This will appear on your customer’s statement when this PaymentIntent succeeds in creating a charge.
*/
@@ -7124,6 +7301,15 @@ declare namespace Stripe {
getMetadata(): void; // TODO: Implement placeholder method
}
class Checkout extends StripeResource {
sessions: Sessions;
}
class Sessions extends StripeResource {
create(data: checkouts.sessions.ICheckoutCreationOptions, response?: IResponseFn<checkouts.sessions.ICheckoutSession>): Promise<checkouts.sessions.ICheckoutSession>;
retrieve(data: string, response?: IResponseFn<checkouts.sessions.ICheckoutSession>): Promise<checkouts.sessions.ICheckoutSession>;
}
class Charges extends StripeResource {
/**
* To charge a credit card, you create a charge object. If your API key is in test mode, the supplied card won't actually be charged, though
+21 -1
View File
@@ -3,7 +3,7 @@ import { customers } from 'stripe';
const stripe = new Stripe("sk_test_BF573NobVn98OiIsPAv7A04K");
stripe.setApiVersion('2017-04-06');
stripe.setApiVersion('2019-05-16');
//#region Balance tests
// ##################################################################################
@@ -233,6 +233,26 @@ stripe.charges.markAsFraudulent('ch_15fvyXEe31JkLCeQOo0SwFk9').then((refunds) =>
//#endregion
//#region Checkout tests
// ##################################################################################
stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
payment_method_types: ['card'],
line_items: [{
name: 'Test',
description: 'Test',
amount: 100,
currency: 'gpb',
quantity: 1
}],
}, (err, session) => {
// asynchronously called
});
//#endregion
//#region Customer tests
// ##################################################################################