Skip to content

Commit

Permalink
fix initializing payment in paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
amrarick26 committed Oct 8, 2024
1 parent 79575e9 commit a5bf008
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 2 additions & 0 deletions OrderCloud.Integrations.Payment.PayPal/Models/PayPalOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.4.0</Version>
<Version>2.4.1</Version>
<PackageId>OrderCloud.Integrations.Payment.PayPal</PackageId>
<Title>OrderCloud Payment Integration with PayPal</Title>
<Authors>OrderCloud Team</Authors>
Expand Down
22 changes: 7 additions & 15 deletions OrderCloud.Integrations.Payment.PayPal/PayPalClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,16 @@ public static async Task<PayPalOrder> 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)
Expand All @@ -45,7 +37,7 @@ public static async Task<PayPalOrder> CreateAuthorizedOrderAsync(PayPalConfig co
{
purchaseUnit
},
payment_source = paymentSource
payment_source = paymentSource.card != null ? paymentSource : null
})
.ReceiveJson<PayPalOrder>();
}
Expand Down
2 changes: 1 addition & 1 deletion OrderCloud.Integrations.Payment.PayPal/PayPalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<CCTransactionResult> InitializePaymentRequestAsync(AuthorizeCC
var order = await PayPalClient.CreateAuthorizedOrderAsync(config, purchaseUnit, transaction);
return new CCTransactionResult
{
Succeeded = order.status.ToLowerInvariant() == "created",
Succeeded = new List<string>{ "created", "completed" }.Contains(order.status.ToLowerInvariant()),
Amount = transaction.Amount,
TransactionID = order.id
};
Expand Down

0 comments on commit a5bf008

Please sign in to comment.