Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 KB | None | 0 0
  1.             // Only used for connect actions, not platform actions.
  2.             RequestOptions requestOptions = new RequestOptions { StripeAccount = "acct_xxx" };
  3.  
  4.             // Platform customer
  5.             var customerCreateParams = new CustomerCreateOptions()
  6.             {
  7.                 Email = "test@example.com"
  8.             };
  9.             var customerService = new CustomerService();
  10.             Customer customer = customerService.Create(customerCreateParams);
  11.             Console.WriteLine("Platform Customer " + customer.Id);
  12.  
  13.             // Platform payment method
  14.             var paymentMethodOptions = new PaymentMethodCreateOptions()
  15.             {
  16.               Type = "card",
  17.               Card = new PaymentMethodCardCreateOptions()
  18.               {
  19.                   Token = "tok_visa"
  20.               }
  21.             };
  22.             var paymentMethodService = new PaymentMethodService();
  23.             PaymentMethod platformPaymentMethod = paymentMethodService.Create(paymentMethodOptions);
  24.             Console.WriteLine("Platform PaymentMethod " + platformPaymentMethod.Id);
  25.  
  26.             // Attach at platform level
  27.             (new PaymentMethodService()).Attach(platformPaymentMethod.Id, new PaymentMethodAttachOptions() { CustomerId = customer.Id });
  28.             Console.WriteLine("Platform PaymentMethod Attached");
  29.  
  30.             // "Share" the payment method down to the connected account
  31.             var connectPaymentMethodOptions = new PaymentMethodCreateOptions()
  32.             {
  33.               CustomerId = customer.Id,
  34.               PaymentMethodId = platformPaymentMethod.Id
  35.             };
  36.             PaymentMethod connectedAccountPaymentMethod = paymentMethodService.Create(connectPaymentMethodOptions, requestOptions);
  37.             Console.WriteLine("Connect PaymentMethod: " + connectedAccountPaymentMethod.Id);
  38.  
  39.             // Create the payment intent on the connected account with the connected account's payment method and customer
  40.             var applicationFee = 100;
  41.             var orderNumber = "123";
  42.             var amount = 9999;
  43.             var orderReference = "order-referece";
  44.  
  45.             var paymentIntentService = new PaymentIntentService();
  46.             Console.WriteLine(connectedAccountPaymentMethod.CustomerId);
  47.             // Note: No customer required in the paymentIntentCreateOptions because we're explicitly passing the payment method.
  48.             var paymentIntentCreateOptions = new PaymentIntentCreateOptions
  49.             {
  50.               Amount = amount,
  51.               Currency = "gbp",
  52.               PaymentMethodId = connectedAccountPaymentMethod.Id,
  53.               ApplicationFeeAmount = applicationFee,
  54.               CaptureMethod = "automatic",
  55.               OffSession = "true",
  56.               Confirm = true,
  57.               PaymentMethodTypes = new System.Collections.Generic.List<string> { "card"},
  58.               Metadata = new System.Collections.Generic.Dictionary<string, string>
  59.               {
  60.                 { "OrderReference", orderReference },
  61.                 { "OrderNumber", orderNumber.ToString() },
  62.                 { "StripeConnectAccountId", "acc_99999" }
  63.               },
  64.             };
  65.             var paymentIntent = paymentIntentService.Create(paymentIntentCreateOptions, requestOptions);
  66.             Console.WriteLine("PaymentIntent " + paymentIntent.Id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement