Skip to content

Commit

Permalink
Merge pull request #132 from amrarick26/paypal
Browse files Browse the repository at this point in the history
New ICreditCardSaver method to initialize a create saved card request that returns a token
  • Loading branch information
erincdustin authored Oct 8, 2024
2 parents 89536cd + 8f53f46 commit cd16ad7
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 8 deletions.
12 changes: 8 additions & 4 deletions OrderCloud.Catalyst/Integrations/Interfaces/ICreditCardSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ namespace OrderCloud.Catalyst
/// </summary>
public interface ICreditCardSaver
{
/// <summary>
/// List Saved Credit Cards
/// </summary>
Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerID, OCIntegrationConfig configOverride = null);
/// <summary>
/// Creates a token used to create a saved card after full card details have been tokenized by the payment provider
/// </summary>
Task<string> InitializeCreateSavedCardRequestAsync(OCIntegrationConfig overrideConfig = null);
/// <summary>
/// List Saved Credit Cards
/// </summary>
Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerID, OCIntegrationConfig configOverride = null);
/// <summary>
/// Get a single saved credit card
/// </summary>
Expand Down
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.4.0</Version>
<Version>2.5.0</Version>
<PackageId>ordercloud-dotnet-catalyst</PackageId>
<Title>OrderCloud SDK Extensions for Azure App Services</Title>
<Authors>OrderCloud Team</Authors>
Expand Down
7 changes: 6 additions & 1 deletion OrderCloud.Integrations.Payment.BlueSnap/BlueSnapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public async Task<CCTransactionResult> VoidAuthorizationAsync(FollowUpCCTransact
return BlueSnapTransactionMapper.ToCardTransactionResult(result);
}

public async Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerID, OCIntegrationConfig overrideConfig = null)
public Task<string> InitializeCreateSavedCardRequestAsync(OCIntegrationConfig overrideConfig = null)
{
throw new NotImplementedException();
}

public async Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerID, OCIntegrationConfig overrideConfig = null)
{
var config = ValidateConfig<BlueSnapConfig>(overrideConfig ?? _defaultConfig);
var shopper = await BlueSnapClient.GetVaultedShopper(customerID, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ public async Task<CCTransactionResult> VoidAuthorizationAsync(FollowUpCCTransact
var cardConnectVoidAuthorizationResponse = await CardConnectClient.VoidPreviousAuthorization(transaction.ToCardConnectFundReversalRequest(config), config);
return cardConnectVoidAuthorizationResponse.ToIntegrationsCCFundReversalResponse();
}
public async Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerId, OCIntegrationConfig overrideConfig = null)

public Task<string> InitializeCreateSavedCardRequestAsync(OCIntegrationConfig overrideConfig = null)
{
throw new NotImplementedException();
}

public async Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerId, OCIntegrationConfig overrideConfig = null)
{
var config = ValidateConfig<CardConnectConfig>(overrideConfig ?? _defaultConfig);
var cardConnectSavedCards = await CardConnectClient.GetProfileAsync(customerId, config.MerchantId, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@ public class PayPalPaymentToken
public PayPalCustomer customer { get; set; }
public PaymentSource payment_source { get; set; }
public List<RelatedLink> links { get; set; }
public string status { get; set; }
}
}
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.1</Version>
<Version>2.5.0</Version>
<PackageId>OrderCloud.Integrations.Payment.PayPal</PackageId>
<Title>OrderCloud Payment Integration with PayPal</Title>
<Authors>OrderCloud Team</Authors>
Expand Down
16 changes: 16 additions & 0 deletions OrderCloud.Integrations.Payment.PayPal/PayPalClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ public static async Task<PayPalOrderReturn> RefundPaymentAsync(PayPalConfig conf
}).ReceiveJson<PayPalOrderReturn>();
}

public static async Task<string> CreateVaultSetupToken(PayPalConfig config)
{
var response = await BuildClient(config)
.AppendPathSegments("v3", "vault", "setup-tokens")
.PostJsonAsync(new
{
payment_source = new PaymentSource()
{
card = new Card()
}
});

var tokenResponse = await response.GetJsonAsync<PayPalPaymentToken>();
return tokenResponse.id;
}

// https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_create
public static async Task<PayPalPaymentToken> CreatePaymentTokenAsync(PayPalConfig config, PCISafeCardDetails card, PaymentSystemCustomer customer)
{
Expand Down
6 changes: 6 additions & 0 deletions OrderCloud.Integrations.Payment.PayPal/PayPalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public PayPalService(OCIntegrationConfig defaultConfig) : base(defaultConfig)
{
}

public async Task<string> InitializeCreateSavedCardRequestAsync(OCIntegrationConfig overrideConfig = null)
{
var config = ValidateConfig<PayPalConfig>(overrideConfig ?? _defaultConfig);
return await PayPalClient.CreateVaultSetupToken(config);
}

public async Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerID, OCIntegrationConfig overrideConfig = null)
{
var config = ValidateConfig<PayPalConfig>(overrideConfig ?? _defaultConfig);
Expand Down
5 changes: 5 additions & 0 deletions OrderCloud.Integrations.Payment.Stripe/StripeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public async Task<CardCreatedResponse> CreateSavedCardAsync(PaymentSystemCustome
return paymentMethodMapper.MapPaymentMethodCreateResponse(customer.ID, paymentMethod);
}

public Task<string> InitializeCreateSavedCardRequestAsync(OCIntegrationConfig overrideConfig = null)
{
throw new NotImplementedException();
}

public async Task<List<PCISafeCardDetails>> ListSavedCardsAsync(string customerID,
OCIntegrationConfig configOverride = null)
{
Expand Down

0 comments on commit cd16ad7

Please sign in to comment.