diff --git a/OrderCloud.Integrations.Payment.Stripe/Mappers/StripePaymentIntentMapper.cs b/OrderCloud.Integrations.Payment.Stripe/Mappers/StripePaymentIntentMapper.cs index f73e31f..b48ef15 100644 --- a/OrderCloud.Integrations.Payment.Stripe/Mappers/StripePaymentIntentMapper.cs +++ b/OrderCloud.Integrations.Payment.Stripe/Mappers/StripePaymentIntentMapper.cs @@ -48,6 +48,21 @@ public PaymentIntentCreateOptions MapPaymentIntentCreateAndConfirmOptions(Author }; } + public PaymentIntentCreateOptions MapPaymentIntentOnlyOptions(AuthorizeCCTransaction transaction) + { + var coefficient = IsZeroDecimalCurrency(transaction.Currency) ? 1 : 100; + return new PaymentIntentCreateOptions() + { + Amount = Convert.ToInt64((transaction.Amount * coefficient)), + Currency = transaction.Currency, + Customer = transaction.ProcessorCustomerID, + AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions + { + Enabled = true, // Creates PaymentIntent only- used to send Client Secret back to iframe + } + }; + } + public CCTransactionResult MapPaymentIntentCreateAndConfirmResponse(PaymentIntent createdPaymentIntent) => new CCTransactionResult() { @@ -59,6 +74,12 @@ public CCTransactionResult MapPaymentIntentCreateAndConfirmResponse(PaymentInten Amount = createdPaymentIntent.Amount }; + public CCTransactionResult MapPaymentIntentCreateResponse(PaymentIntent createdPaymentIntent) => + new CCTransactionResult() + { + TransactionID = createdPaymentIntent.ClientSecret // transaction.TransactionID represents Client Secret for the Stripe payment iframe in this case + }; + public PaymentIntentCaptureOptions MapPaymentIntentCaptureOptions(FollowUpCCTransaction transaction) { var options = new PaymentIntentCaptureOptions(); diff --git a/OrderCloud.Integrations.Payment.Stripe/OrderCloud.Integrations.Payment.Stripe.csproj b/OrderCloud.Integrations.Payment.Stripe/OrderCloud.Integrations.Payment.Stripe.csproj index 3309c2f..3abd9ab 100644 --- a/OrderCloud.Integrations.Payment.Stripe/OrderCloud.Integrations.Payment.Stripe.csproj +++ b/OrderCloud.Integrations.Payment.Stripe/OrderCloud.Integrations.Payment.Stripe.csproj @@ -3,7 +3,7 @@ netstandard2.0 True - 2.5.0 + 2.6.0 OrderCloud.Integrations.Payment.Stripe OrderCloud Tax Integration with Stripe OrderCloud Team diff --git a/OrderCloud.Integrations.Payment.Stripe/StripeClient.cs b/OrderCloud.Integrations.Payment.Stripe/StripeClient.cs index 1d442b9..7ea82c1 100644 --- a/OrderCloud.Integrations.Payment.Stripe/StripeClient.cs +++ b/OrderCloud.Integrations.Payment.Stripe/StripeClient.cs @@ -78,7 +78,7 @@ public static async Task CreateCustomerAsync(CustomerCreateOptions opt /// /// https://stripe.com/docs/api/payment_intents/create /// - public static async Task CreateAndConfirmPaymentIntentAsync(PaymentIntentCreateOptions options, StripeConfig config) + public static async Task CreatePaymentIntentAsync(PaymentIntentCreateOptions options, StripeConfig config) { StripeConfiguration.ApiKey = config.SecretKey; var service = new PaymentIntentService(); diff --git a/OrderCloud.Integrations.Payment.Stripe/StripeService.cs b/OrderCloud.Integrations.Payment.Stripe/StripeService.cs index bdc0fb3..d446a03 100644 --- a/OrderCloud.Integrations.Payment.Stripe/StripeService.cs +++ b/OrderCloud.Integrations.Payment.Stripe/StripeService.cs @@ -19,9 +19,13 @@ public async Task GetIFrameCredentialAsync(OCIntegrationConfig overrideC return token; } - public Task InitializePaymentRequestAsync(AuthorizeCCTransaction transaction, OCIntegrationConfig overrideConfig = null, bool isCapture = false) + public async Task InitializePaymentRequestAsync(AuthorizeCCTransaction transaction, OCIntegrationConfig overrideConfig = null, bool isCapture = false) { - throw new NotImplementedException(); + var config = ValidateConfig(overrideConfig ?? _defaultConfig); + var paymentIntentMapper = new StripePaymentIntentMapper(); + var paymentIntentCreateOptions = paymentIntentMapper.MapPaymentIntentOnlyOptions(transaction); + var createdPaymentIntent = await StripeClient.CreatePaymentIntentAsync(paymentIntentCreateOptions, config); + return paymentIntentMapper.MapPaymentIntentCreateResponse(createdPaymentIntent); } public Task CapturePaymentAsync(FollowUpCCTransaction transaction, OCIntegrationConfig overrideConfig = null) @@ -36,7 +40,7 @@ public async Task AuthorizeOnlyAsync(AuthorizeCCTransaction var config = ValidateConfig(configOverride ?? _defaultConfig); var paymentIntentMapper = new StripePaymentIntentMapper(); var paymentIntentCreateOptions = paymentIntentMapper.MapPaymentIntentCreateAndConfirmOptions(transaction); - var createdPaymentIntent = await StripeClient.CreateAndConfirmPaymentIntentAsync(paymentIntentCreateOptions, config); + var createdPaymentIntent = await StripeClient.CreatePaymentIntentAsync(paymentIntentCreateOptions, config); // confirms payment intent as well return paymentIntentMapper.MapPaymentIntentCreateAndConfirmResponse(createdPaymentIntent); } }