Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.5.0</Version>
<Version>2.6.0</Version>
<PackageId>OrderCloud.Integrations.Payment.Stripe</PackageId>
<Title>OrderCloud Tax Integration with Stripe</Title>
<Authors>OrderCloud Team</Authors>
Expand Down
2 changes: 1 addition & 1 deletion OrderCloud.Integrations.Payment.Stripe/StripeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static async Task<Customer> CreateCustomerAsync(CustomerCreateOptions opt
/// <summary>
/// https://stripe.com/docs/api/payment_intents/create
/// </summary>
public static async Task<PaymentIntent> CreateAndConfirmPaymentIntentAsync(PaymentIntentCreateOptions options, StripeConfig config)
public static async Task<PaymentIntent> CreatePaymentIntentAsync(PaymentIntentCreateOptions options, StripeConfig config)
{
StripeConfiguration.ApiKey = config.SecretKey;
var service = new PaymentIntentService();
Expand Down
10 changes: 7 additions & 3 deletions OrderCloud.Integrations.Payment.Stripe/StripeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ public async Task<string> GetIFrameCredentialAsync(OCIntegrationConfig overrideC
return token;
}

public Task<CCTransactionResult> InitializePaymentRequestAsync(AuthorizeCCTransaction transaction, OCIntegrationConfig overrideConfig = null, bool isCapture = false)
public async Task<CCTransactionResult> InitializePaymentRequestAsync(AuthorizeCCTransaction transaction, OCIntegrationConfig overrideConfig = null, bool isCapture = false)
{
throw new NotImplementedException();
var config = ValidateConfig<StripeConfig>(overrideConfig ?? _defaultConfig);
var paymentIntentMapper = new StripePaymentIntentMapper();
var paymentIntentCreateOptions = paymentIntentMapper.MapPaymentIntentOnlyOptions(transaction);
var createdPaymentIntent = await StripeClient.CreatePaymentIntentAsync(paymentIntentCreateOptions, config);
return paymentIntentMapper.MapPaymentIntentCreateResponse(createdPaymentIntent);
}

public Task<CCTransactionResult> CapturePaymentAsync(FollowUpCCTransaction transaction, OCIntegrationConfig overrideConfig = null)
Expand All @@ -36,7 +40,7 @@ public async Task<CCTransactionResult> AuthorizeOnlyAsync(AuthorizeCCTransaction
var config = ValidateConfig<StripeConfig>(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);
}
}
Expand Down
Loading