Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Only used for connect actions, not platform actions.
- RequestOptions requestOptions = new RequestOptions { StripeAccount = "acct_xxx" };
- // Platform customer
- var customerCreateParams = new CustomerCreateOptions()
- {
- Email = "test@example.com"
- };
- var customerService = new CustomerService();
- Customer customer = customerService.Create(customerCreateParams);
- Console.WriteLine("Platform Customer " + customer.Id);
- // Platform payment method
- var paymentMethodOptions = new PaymentMethodCreateOptions()
- {
- Type = "card",
- Card = new PaymentMethodCardCreateOptions()
- {
- Number = "4242424242424242",
- ExpMonth = 8,
- ExpYear = 2020,
- Cvc = "314"
- }
- };
- var paymentMethodService = new PaymentMethodService();
- PaymentMethod platformPaymentMethod = paymentMethodService.Create(paymentMethodOptions);
- Console.WriteLine("Platform PaymentMethod " + platformPaymentMethod.Id);
- // Attach at platform level
- (new PaymentMethodService()).Attach(platformPaymentMethod.Id, new PaymentMethodAttachOptions() { CustomerId = customer.Id });
- Console.WriteLine("Platform PaymentMethod Attached");
- // "Share" the payment method down to the connected account
- var connectPaymentMethodOptions = new PaymentMethodCreateOptions()
- {
- CustomerId = customer.Id,
- PaymentMethodId = platformPaymentMethod.Id
- };
- PaymentMethod connectedAccountPaymentMethod = paymentMethodService.Create(connectPaymentMethodOptions, requestOptions);
- Console.WriteLine("Connect PaymentMethod: " + connectedAccountPaymentMethod.Id);
- // Create the payment intent on the connected account with the connected account's payment method and customer
- var applicationFee = 100;
- var orderNumber = "123";
- var amount = 9999;
- var orderReference = "order-reference";
- var paymentIntentService = new PaymentIntentService();
- var paymentIntentCreateOptions = new PaymentIntentCreateOptions
- {
- Amount = amount,
- Currency = "gbp",
- CustomerId = connectedAccountPaymentMethod.CustomerId, // Note this is the customer from the shared payment method!
- PaymentMethodId = connectedAccountPaymentMethod.Id,
- ApplicationFeeAmount = applicationFee,
- CaptureMethod = "automatic",
- OffSession = "true",
- Confirm = true,
- PaymentMethodTypes = new System.Collections.Generic.List<string> { "card"},
- Metadata = new System.Collections.Generic.Dictionary<string, string>
- {
- { "OrderReference", orderReference },
- { "OrderNumber", orderNumber.ToString() },
- { "StripeConnectAccountId", "acc_99999" }
- },
- };
- var paymentIntent = paymentIntentService.Create(paymentIntentCreateOptions, requestOptions);
- Console.WriteLine("PaymentIntent " + paymentIntent.Id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement