Skip to content

Commit

Permalink
Merge pull request #134 from erincdustin/paypal_updates
Browse files Browse the repository at this point in the history
Update to how single merchant CCTransactionResult is mapped
  • Loading branch information
amrarick26 authored Nov 27, 2024
2 parents a7d9321 + 0dc17ae commit 9db5fe7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 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.5.0</Version>
<Version>2.6.0</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 @@ -85,61 +85,69 @@ public List<PurchaseUnit> MapToPurchaseUnit(AuthorizeCCTransaction transaction,
public CCTransactionResult MapAuthorizedPaymentToCCTransactionResult(PayPalOrder authorizedOrder)
{
var innerTransactions = new List<CCTransactionResult>();
authorizedOrder.purchase_units.ForEach(u =>
authorizedOrder?.purchase_units?.ForEach(u =>
{
var capture = u.payments.authorizations.FirstOrDefault();
if (capture != null)
var auth = u.payments.authorizations.FirstOrDefault();
if (auth != null)
{
innerTransactions.Add(new CCTransactionResult()
{
TransactionID = capture.id,
TransactionID = auth.id, // Authorization ID needed to Capture payment or Void Authorization
Amount = ConvertStringAmountToDecimal(u.amount.value),
Succeeded = capture.status.ToLowerInvariant() == "completed",
MerchantID = u.payee.merchant_id
Succeeded = auth.status.ToLowerInvariant() == "completed",
MerchantID = u?.payee?.merchant_id
});
}
});
var authorizationId = innerTransactions.Count == 1
? innerTransactions?.FirstOrDefault()?.TransactionID
: null;
var allPaymentsSucceeded = innerTransactions.All(t => t.Succeeded);
var ccTransaction = new CCTransactionResult
{
Succeeded = authorizedOrder.status.ToLowerInvariant() == "completed",
TransactionID = authorizedOrder.id, // Authorization ID needed to Capture payment or Void Authorization
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,
AuthorizationCode = null,
AVSResponseCode = authorizedOrder.processor_response.avs_code,
Message = null,
Amount = authorizedOrder.purchase_units.Sum(unit => ConvertStringAmountToDecimal(unit.amount.value)),
InnerTransactions = innerTransactions
InnerTransactions = innerTransactions // Include all merchant transaction details as nested values
};
return ccTransaction;
}

public CCTransactionResult MapCapturedPaymentToCCTransactionResult(PayPalOrder capturedOrder)
{
var innerTransactions = new List<CCTransactionResult>();
capturedOrder.purchase_units.ForEach(u =>
capturedOrder?.purchase_units?.ForEach(u =>
{
var capture = u.payments.captures.FirstOrDefault();
if (capture != null)
{
innerTransactions.Add(new CCTransactionResult()
{
TransactionID = capture.id,
TransactionID = capture.id, // Capture ID needed to Refund payment
Amount = ConvertStringAmountToDecimal(u.amount.value),
Succeeded = capture.status.ToLowerInvariant() == "completed",
MerchantID = u.payee.merchant_id
MerchantID = u?.payee?.merchant_id
});
}
});
var captureId = innerTransactions.Count == 1
? innerTransactions?.FirstOrDefault()?.TransactionID
: null;
var allPaymentsSucceeded = innerTransactions.All(t => t.Succeeded);
return new CCTransactionResult
{
TransactionID = capturedOrder.id, // Capture ID needed to Refund payment
TransactionID = captureId, // Default to purchase_unit.TransactionID if only one merchant, else null
ResponseCode = capturedOrder.processor_response.response_code,
AuthorizationCode = null,
AVSResponseCode = capturedOrder.processor_response.avs_code,
Message = null,
Succeeded = capturedOrder.status.ToLowerInvariant() == "completed",
Succeeded = capturedOrder.status.ToLowerInvariant() == "completed" && allPaymentsSucceeded,
Amount = capturedOrder.purchase_units.Sum(unit => ConvertStringAmountToDecimal(unit.amount.value)),
InnerTransactions = innerTransactions
InnerTransactions = innerTransactions // Include all merchant transaction details as nested values
};
}

Expand Down

0 comments on commit 9db5fe7

Please sign in to comment.