Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.36 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.                   Number = "4242424242424242",
  20.                   ExpMonth = 8,
  21.                   ExpYear = 2020,
  22.                   Cvc = "314"
  23.               }
  24.             };
  25.             var paymentMethodService = new PaymentMethodService();
  26.             PaymentMethod platformPaymentMethod = paymentMethodService.Create(paymentMethodOptions);
  27.             Console.WriteLine("Platform PaymentMethod " + platformPaymentMethod.Id);
  28.  
  29.             // Attach at platform level
  30.             (new PaymentMethodService()).Attach(platformPaymentMethod.Id, new PaymentMethodAttachOptions() { CustomerId = customer.Id });
  31.             Console.WriteLine("Platform PaymentMethod Attached");
  32.  
  33.             // "Share" the payment method down to the connected account
  34.             var connectPaymentMethodOptions = new PaymentMethodCreateOptions()
  35.             {
  36.               CustomerId = customer.Id,
  37.               PaymentMethodId = platformPaymentMethod.Id
  38.             };
  39.             PaymentMethod connectedAccountPaymentMethod = paymentMethodService.Create(connectPaymentMethodOptions, requestOptions);
  40.             Console.WriteLine("Connect PaymentMethod: " + connectedAccountPaymentMethod.Id);
  41.  
  42.             // Create the payment intent on the connected account with the connected account's payment method and customer
  43.             var applicationFee = 100;
  44.             var orderNumber = "123";
  45.             var amount = 9999;
  46.             var orderReference = "order-reference";
  47.  
  48.             var paymentIntentService = new PaymentIntentService();
  49.             var paymentIntentCreateOptions = new PaymentIntentCreateOptions
  50.             {
  51.               Amount = amount,
  52.               Currency = "gbp",
  53.               CustomerId = connectedAccountPaymentMethod.CustomerId, // Note this is the customer from the shared payment method!
  54.               PaymentMethodId = connectedAccountPaymentMethod.Id,
  55.               ApplicationFeeAmount = applicationFee,
  56.               CaptureMethod = "automatic",
  57.               OffSession = "true",
  58.               Confirm = true,
  59.               PaymentMethodTypes = new System.Collections.Generic.List<string> { "card"},
  60.               Metadata = new System.Collections.Generic.Dictionary<string, string>
  61.               {
  62.                 { "OrderReference", orderReference },
  63.                 { "OrderNumber", orderNumber.ToString() },
  64.                 { "StripeConnectAccountId", "acc_99999" }
  65.               },
  66.             };
  67.             var paymentIntent = paymentIntentService.Create(paymentIntentCreateOptions, requestOptions);
  68.             Console.WriteLine("PaymentIntent " + paymentIntent.Id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement