diff --git a/OrderCloud.Integrations.Payment.PayPal/Models/PayPalOrder.cs b/OrderCloud.Integrations.Payment.PayPal/Models/PayPalOrder.cs index 8d611e7..c732855 100644 --- a/OrderCloud.Integrations.Payment.PayPal/Models/PayPalOrder.cs +++ b/OrderCloud.Integrations.Payment.PayPal/Models/PayPalOrder.cs @@ -85,6 +85,8 @@ public class Card public string last_digits { get; set; } public string expiry { get; set; } public string brand { get; set; } + public string vault_id { get; set; } + public string single_use_token { get; set; } } public class PaymentToken diff --git a/OrderCloud.Integrations.Payment.PayPal/OrderCloud.Integrations.Payment.PayPal.csproj b/OrderCloud.Integrations.Payment.PayPal/OrderCloud.Integrations.Payment.PayPal.csproj index aa30cba..a7a4e34 100644 --- a/OrderCloud.Integrations.Payment.PayPal/OrderCloud.Integrations.Payment.PayPal.csproj +++ b/OrderCloud.Integrations.Payment.PayPal/OrderCloud.Integrations.Payment.PayPal.csproj @@ -3,7 +3,7 @@ netstandard2.0 True - 2.4.0 + 2.4.1 OrderCloud.Integrations.Payment.PayPal OrderCloud Payment Integration with PayPal OrderCloud Team diff --git a/OrderCloud.Integrations.Payment.PayPal/PayPalClient.cs b/OrderCloud.Integrations.Payment.PayPal/PayPalClient.cs index ef73ee7..967c460 100644 --- a/OrderCloud.Integrations.Payment.PayPal/PayPalClient.cs +++ b/OrderCloud.Integrations.Payment.PayPal/PayPalClient.cs @@ -17,24 +17,16 @@ public static async Task CreateAuthorizedOrderAsync(PayPalConfig co var paymentSource = new PaymentSource(); if (transaction.CardDetails != null) { + paymentSource.card = new Card(); if (transaction.CardDetails.SavedCardID != null) { - paymentSource.token = new PaymentToken() - { - id = transaction.CardDetails.SavedCardID, - type = "BILLING_AGREEMENT" - }; - } else { - paymentSource.card = new Card - { - name = transaction.CardDetails.CardHolderName, - last_digits = transaction.CardDetails.NumberLast4Digits, - expiry = $"{transaction.CardDetails.ExpirationMonth}/{transaction.CardDetails.ExpirationYear}", - brand = transaction.CardDetails.CardType - }; + paymentSource.card.vault_id = transaction.CardDetails.SavedCardID; + } else if (transaction.CardDetails.Token != null) + { + paymentSource.card.single_use_token = transaction.CardDetails.Token; } - } + return await BuildClient(config) .AppendPathSegments("v2", "checkout", "orders") .WithHeader("PayPal-Request-Id", transaction.RequestID) @@ -45,7 +37,7 @@ public static async Task CreateAuthorizedOrderAsync(PayPalConfig co { purchaseUnit }, - payment_source = paymentSource + payment_source = paymentSource.card != null ? paymentSource : null }) .ReceiveJson(); } diff --git a/OrderCloud.Integrations.Payment.PayPal/PayPalService.cs b/OrderCloud.Integrations.Payment.PayPal/PayPalService.cs index be0c4e8..699f356 100644 --- a/OrderCloud.Integrations.Payment.PayPal/PayPalService.cs +++ b/OrderCloud.Integrations.Payment.PayPal/PayPalService.cs @@ -24,7 +24,7 @@ public async Task InitializePaymentRequestAsync(AuthorizeCC var order = await PayPalClient.CreateAuthorizedOrderAsync(config, purchaseUnit, transaction); return new CCTransactionResult { - Succeeded = order.status.ToLowerInvariant() == "created", + Succeeded = new List{ "created", "completed" }.Contains(order.status.ToLowerInvariant()), Amount = transaction.Amount, TransactionID = order.id };