[types/stripe] Add PaymentIntentData (#38025)

* Support for Connect in PaymentIntent Checkout

Support for examples documented here: https://stripe.com/docs/payments/checkout/connect

* Add PaymentIntentData to ICheckoutCreationOptions

* Add tests for with destination and on_behalf_on

* Cleanup after merge
This commit is contained in:
Claus Stilborg
2019-09-06 10:22:02 -07:00
committed by Andrew Casey
parent d40fd0c490
commit 2ec7a2b814
2 changed files with 142 additions and 1 deletions
+95 -1
View File
@@ -30,6 +30,7 @@
// Pavel Ivanov <https://github.com/schfkt>
// Chris Zieba <https://github.com/ChrisZieba>
// Jeffery Grajkowski <https://github.com/pushplay>
// Claus Stilborg <https://github.com/stilborg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -2155,7 +2156,7 @@ declare namespace Stripe {
/**
* Details for creation of payment intent
*/
payment_intent_data?: paymentIntents.IPaymentIntentCaptureOptions;
payment_intent_data?: paymentIntents.IPaymentIntentCaptureOptions | paymentIntents.IPaymentIntentData;
/**
* Use instead of @param line_items when using a subscription
@@ -5303,6 +5304,99 @@ declare namespace Stripe {
client_secret: string;
}
interface IPaymentIntentDataTransferDataOptions {
/**
* A positive integer representing how much to charge in the smallest currency unit.
*/
amount?: number;
/**
* The account (if any) the payment will be attributed to for tax reporting, and where funds from the payment will be transferred to upon payment success.
*/
destination?: string;
}
interface IPaymentIntentDataShipping {
/**
* Shipping address.
*/
address: IAddress;
/**
* Recipient name. This can be unset by updating the value to null and then saving.
*/
name: string | null;
/**
* The delivery service that shipped a physical product, such as Fedex, UPS, USPS, etc. This can be unset by updating the value to null and then saving.
*/
carrier?: string | null;
/**
* Recipient phone (including extension). This can be unset by updating the value to null and then saving.
*/
phone?: string | null;
/**
* The tracking number for a physical product, obtained from the delivery service. If multiple tracking numbers were generated for this purchase, please separate them with commas. This can be unset by updating the value to null and then saving.
*/
tracking_number?: string | null;
}
type PaymentIntentDataCaptureMethodOptions = 'automatic' | 'manual';
type PaymentIntendDataFutureUsageOptions = 'on_session' | 'off_session';
interface IPaymentIntentData {
/**
* The amount of the application fee (if any) that will be applied to the payment and transferred to the application owner’s Stripe account. To use an application fee, the request must be made on behalf of another account, using the `Stripe-Account` header or an OAuth key.
*/
application_fee_amount?: number;
/**
* Capture method of this PaymentIntent, one of automatic or manual.
*/
capture_method?: PaymentIntentDataCaptureMethodOptions;
/**
* An arbitrary string attached to the object. Often useful for displaying to users. This can be unset by updating the value to null and then saving.
*/
description?: string | null;
/**
* Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
*/
metadata?: IOptionsMetadata;
/**
* The account (if any) for which the funds of the PaymentIntent are intended. Used with connected accounts.
*/
on_behalf_of?: string;
/**
* Email address that the receipt for the resulting payment will be sent to.
*/
receipt_email?: string;
/**
* Indicates that you intend to make future payments with this PaymentIntent’s payment method.
* If present, the payment method used with this PaymentIntent can be attached to a Customer, even after the transaction completes.
* Use on_session if you intend to only reuse the payment method when your customer is present in your checkout flow. Use off_session if your customer may or may not be in your checkout flow. See Saving card details after a payment to learn more.
* Stripe uses setup_future_usage to dynamically optimize your payment flow and comply with regional legislation and network rules. For example, if your customer is impacted by SCA, using off_session will ensure that they are authenticated while processing this PaymentIntent. You will then be able to collect off-session payments for this customer.
*/
setup_future_usage?: PaymentIntendDataFutureUsageOptions;
/**
* Shipping information for this payment.
*/
shipping?: IPaymentIntentDataShipping;
/**
* The data with which to automatically create a Transfer when the payment is finalized. Used with connected accounts.
*/
transfer_data?: IPaymentIntentDataTransferDataOptions;
}
interface IPaymentIntentCaptureOptions {
/**
* The amount to capture (in cents) from the PaymentIntent, which must be less than or equal to the original amount. Any additional amount will be automatically refunded. Defaults to the full `amount_capturable` if not provided.
+47
View File
@@ -318,6 +318,53 @@ stripe.checkout.sessions.retrieve('ch_test_123', { expand: ['payment_intent'] })
//#endregion
//#region Checkout with connect tests
// ##################################################################################
// With destination
stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
name: "Cucumber from Roger's Farm",
amount: 200,
currency: 'sek',
quantity: 10,
}],
payment_intent_data: {
application_fee_amount: 200,
transfer_data: {
destination: 'acct_17wV8KBoqMA9o2xk',
},
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
}, (err, session) => {
// asynchronously called
});
// With on_behalf_of
stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
name: "Cucumber from Roger's Farm",
amount: 200,
currency: 'sek',
quantity: 10,
}],
payment_intent_data: {
application_fee_amount: 200,
on_behalf_of: 'acct_17wV8KBoqMA9o2xk',
transfer_data: {
destination: 'acct_17wV8KBoqMA9o2xk',
},
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
}, (err, session) => {
// asynchronously called
});
//#endregion
//#region CreditNotes tests
// ##################################################################################
stripe.creditNotes.create({