Skip to content

Commit

Permalink
Merge pull request #136 from erincdustin/paypal_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
crhistianramirez authored Dec 5, 2024
2 parents be839da + 45bb21d commit 3951de1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion OrderCloud.Catalyst/OrderCloud.Catalyst.csproj
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.6.0</Version>
<Version>2.6.1</Version>
<PackageId>ordercloud-dotnet-catalyst</PackageId>
<Title>OrderCloud SDK Extensions for Azure App Services</Title>
<Authors>OrderCloud Team</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -47,7 +48,7 @@ public List<PurchaseUnit> 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)
{
Expand All @@ -61,23 +62,25 @@ public List<PurchaseUnit> 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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
}
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.6.0</Version>
<Version>2.6.1</Version>
<PackageId>OrderCloud.Integrations.Payment.PayPal</PackageId>
<Title>OrderCloud Payment Integration with PayPal</Title>
<Authors>OrderCloud Team</Authors>
Expand Down

0 comments on commit 3951de1

Please sign in to comment.