diff --git a/OrderCloud.Catalyst/OrderCloud.Catalyst.csproj b/OrderCloud.Catalyst/OrderCloud.Catalyst.csproj index f46ed04..1830449 100644 --- a/OrderCloud.Catalyst/OrderCloud.Catalyst.csproj +++ b/OrderCloud.Catalyst/OrderCloud.Catalyst.csproj @@ -3,7 +3,7 @@ netstandard2.0 True - 2.6.0 + 2.6.1 ordercloud-dotnet-catalyst OrderCloud SDK Extensions for Azure App Services OrderCloud Team diff --git a/OrderCloud.Integrations.Payment.PayPal/Mappers/PayPalOrderPaymentMapper.cs b/OrderCloud.Integrations.Payment.PayPal/Mappers/PayPalOrderPaymentMapper.cs index fe6274d..27c3e9d 100644 --- a/OrderCloud.Integrations.Payment.PayPal/Mappers/PayPalOrderPaymentMapper.cs +++ b/OrderCloud.Integrations.Payment.PayPal/Mappers/PayPalOrderPaymentMapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using Newtonsoft.Json.Linq; using OrderCloud.Catalyst; using OrderCloud.Integrations.Payment.PayPal.Models; @@ -47,7 +48,7 @@ public List MapToPurchaseUnit(AuthorizeCCTransaction transaction, }, description = transaction?.OrderWorksheet?.Order?.Comments, reference_id = Guid.NewGuid().ToString(), - invoice_id = Guid.NewGuid().ToString(), + invoice_id = transaction?.OrderID, }; if (address != null) { @@ -61,23 +62,25 @@ public List MapToPurchaseUnit(AuthorizeCCTransaction transaction, } }); } - - var unit = new PurchaseUnit() - { - amount = new Amount() - { - currency_code = transaction.Currency, - value = transaction.Amount.ToString(CultureInfo.InvariantCulture) ?? null - } - }; - if (address != null) + else { - unit.shipping = new Shipping() + var unit = new PurchaseUnit() { - address = address + amount = new Amount() + { + currency_code = transaction.Currency, + value = transaction.Amount.ToString(CultureInfo.InvariantCulture) ?? null + } }; + if (address != null) + { + unit.shipping = new Shipping() + { + address = address + }; + } + purchaseUnits.Add(unit); } - purchaseUnits.Add(unit); return purchaseUnits; } @@ -105,13 +108,13 @@ public CCTransactionResult MapAuthorizedPaymentToCCTransactionResult(PayPalOrder var allPaymentsSucceeded = innerTransactions.All(t => t.Succeeded); var ccTransaction = new CCTransactionResult { - Succeeded = authorizedOrder.status.ToLowerInvariant() == "completed" && allPaymentsSucceeded, + Succeeded = authorizedOrder?.status.ToLowerInvariant() == "completed" && allPaymentsSucceeded, TransactionID = authorizationId, // Default to purchase_unit.TransactionID if only one merchant, else null - ResponseCode = authorizedOrder.processor_response.response_code, + ResponseCode = authorizedOrder?.processor_response?.response_code, AuthorizationCode = null, - AVSResponseCode = authorizedOrder.processor_response.avs_code, + AVSResponseCode = authorizedOrder?.processor_response?.avs_code, Message = null, - Amount = authorizedOrder.purchase_units.Sum(unit => ConvertStringAmountToDecimal(unit.amount.value)), + Amount = authorizedOrder?.purchase_units != null ? authorizedOrder.purchase_units.Sum(unit => ConvertStringAmountToDecimal(unit.amount.value)) : Convert.ToDecimal(0, CultureInfo.InvariantCulture), InnerTransactions = innerTransactions // Include all merchant transaction details as nested values }; return ccTransaction; @@ -141,12 +144,12 @@ public CCTransactionResult MapCapturedPaymentToCCTransactionResult(PayPalOrder c return new CCTransactionResult { TransactionID = captureId, // Default to purchase_unit.TransactionID if only one merchant, else null - ResponseCode = capturedOrder.processor_response.response_code, + ResponseCode = capturedOrder?.processor_response?.response_code, AuthorizationCode = null, - AVSResponseCode = capturedOrder.processor_response.avs_code, + AVSResponseCode = capturedOrder?.processor_response?.avs_code, Message = null, - Succeeded = capturedOrder.status.ToLowerInvariant() == "completed" && allPaymentsSucceeded, - Amount = capturedOrder.purchase_units.Sum(unit => ConvertStringAmountToDecimal(unit.amount.value)), + Succeeded = capturedOrder?.status.ToLowerInvariant() == "completed" && allPaymentsSucceeded, + Amount = capturedOrder?.purchase_units != null ? capturedOrder.purchase_units.Sum(unit => ConvertStringAmountToDecimal(unit.amount.value)) : Convert.ToDecimal(0, CultureInfo.InvariantCulture), InnerTransactions = innerTransactions // Include all merchant transaction details as nested values }; } diff --git a/OrderCloud.Integrations.Payment.PayPal/OrderCloud.Integrations.Payment.PayPal.csproj b/OrderCloud.Integrations.Payment.PayPal/OrderCloud.Integrations.Payment.PayPal.csproj index a60f7a3..88a031c 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.6.0 + 2.6.1 OrderCloud.Integrations.Payment.PayPal OrderCloud Payment Integration with PayPal OrderCloud Team