Skip to content

Commit

Permalink
adds bnpl payment endoints (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanAkkus authored Nov 1, 2023
1 parent b60d4ec commit a4213e3
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 30 deletions.
44 changes: 43 additions & 1 deletion Craftgate/Adapter/PaymentAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,49 @@ public Task<PaymentTransactionResponse> UpdatePaymentTransactionAsync(
return AsyncRestClient.Put<PaymentTransactionResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(updatePaymentTransactionRequest, path, RequestOptions), updatePaymentTransactionRequest);
}


public BnplPaymentOfferResponse RetrieveBnplOffers(BnplPaymentOfferRequest request)
{
var path = "/payment/v1/bnpl-payments/offers";
return RestClient.Post<BnplPaymentOfferResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(request, path, RequestOptions), request);
}

public Task<BnplPaymentOfferResponse> RetrieveBnplOffersAsync(BnplPaymentOfferRequest request)
{
var path = "/payment/v1/bnpl-payments/offers";
return AsyncRestClient.Post<BnplPaymentOfferResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(request, path, RequestOptions), request);
}

public InitBnplPaymentResponse InitBnplPayment(InitBnplPaymentRequest request)
{
var path = "/payment/v1/bnpl-payments/init";
return RestClient.Post<InitBnplPaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(request, path, RequestOptions), request);
}

public Task<InitBnplPaymentResponse> InitBnplPaymentAsync(InitBnplPaymentRequest request)
{
var path = "/payment/v1/bnpl-payments/init";
return AsyncRestClient.Post<InitBnplPaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(request, path, RequestOptions), request);
}

public void ApproveBnplPayment(long PaymentId)
{
var path = "/payment/v1/bnpl-payments/" + PaymentId + "/approve";
RestClient.Post<object>(RequestOptions.BaseUrl + path,
CreateHeaders(null, path, RequestOptions), null);
}

public Task ApproveBnplPaymentAsync(long PaymentId)
{
var path = "/payment/v1/bnpl-payments/" + PaymentId + "/approve";
return AsyncRestClient.Post<object>(RequestOptions.BaseUrl + path,
CreateHeaders(null, path, RequestOptions), null);
}

public bool Is3DSecureCallbackVerified(string threeDSecureCallbackKey, Dictionary<string, string> parameters)
{
string hash = parameters["hash"];
Expand Down
1 change: 1 addition & 0 deletions Craftgate/Model/ApmType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ApmType
[EnumMember(Value = "STRIPE")] STRIPE,
[EnumMember(Value = "KASPI")] KASPI,
[EnumMember(Value = "TOMPAY")] TOMPAY,
[EnumMember(Value = "MASLAK")] MASLAK,
[EnumMember(Value = "FUND_TRANSFER")] FUND_TRANSFER,
[EnumMember(Value = "CASH_ON_DELIVERY")] CASH_ON_DELIVERY
}
Expand Down
51 changes: 51 additions & 0 deletions Craftgate/Model/BnplCartItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Runtime.Serialization;

namespace Craftgate.Model
{
public enum BnplCartItemType
{
[EnumMember(Value = "MOBILE_PHONE_OVER_5000_TRY")]
MOBILE_PHONE_OVER_5000_TRY,

[EnumMember(Value = "MOBILE_PHONE_BELOW_5000_TRY")]
MOBILE_PHONE_BELOW_5000_TRY,
[EnumMember(Value = "TABLET")] TABLET,
[EnumMember(Value = "COMPUTER")] COMPUTER,

[EnumMember(Value = "CONSTRUCTION_MARKET")]
CONSTRUCTION_MARKET,
[EnumMember(Value = "GOLD")] GOLD,

[EnumMember(Value = "DIGITAL_PRODUCTS")]
DIGITAL_PRODUCTS,
[EnumMember(Value = "SUPERMARKET")] SUPERMARKET,
[EnumMember(Value = "WHITE_GOODS")] WHITE_GOODS,

[EnumMember(Value = "WEARABLE_TECHNOLOGY")]
WEARABLE_TECHNOLOGY,

[EnumMember(Value = "SMALL_HOME_APPLIANCES")]
SMALL_HOME_APPLIANCES,
[EnumMember(Value = "TV")] TV,
[EnumMember(Value = "GAMES_CONSOLES")] GAMES_CONSOLES,

[EnumMember(Value = "AIR_CONDITIONER_AND_HEATER")]
AIR_CONDITIONER_AND_HEATER,
[EnumMember(Value = "ELECTRONICS")] ELECTRONICS,
[EnumMember(Value = "ACCESSORIES")] ACCESSORIES,

[EnumMember(Value = "MOM_AND_BABY_AND_KIDS")]
MOM_AND_BABY_AND_KIDS,
[EnumMember(Value = "SHOES")] SHOES,
[EnumMember(Value = "CLOTHING")] CLOTHING,

[EnumMember(Value = "COSMETICS_AND_PERSONAL_CARE")]
COSMETICS_AND_PERSONAL_CARE,
[EnumMember(Value = "FURNITURE")] FURNITURE,
[EnumMember(Value = "HOME_LIVING")] HOME_LIVING,

[EnumMember(Value = "AUTOMOBILE_MOTORCYCLE")]
AUTOMOBILE_MOTORCYCLE,
[EnumMember(Value = "OTHER")] OTHER
}
}
15 changes: 15 additions & 0 deletions Craftgate/Request/BnplPaymentOfferRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using Craftgate.Model;
using Craftgate.Request.Dto;

namespace Craftgate.Request
{
public class BnplPaymentOfferRequest
{
public ApmType ApmType { get; set; }
public long? MerchantApmId { get; set; }
public decimal Price { get; set; }
public Currency Currency { get; set; }
public IList<BnplPaymentCartItem> Items;
}
}
14 changes: 14 additions & 0 deletions Craftgate/Request/Dto/BnplPaymentCartItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Craftgate.Model;

namespace Craftgate.Request.Dto
{
public class BnplPaymentCartItem
{
public string Id { get; set; }
public string Name { get; set; }
public string BrandName { get; set; }
public BnplCartItemType Type { get; set; }
public decimal UnitPrice { get; set; }
public int Quantity { get; set; }
}
}
11 changes: 11 additions & 0 deletions Craftgate/Request/InitBnplPaymentRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Craftgate.Request.Dto;

namespace Craftgate.Request
{
public class InitBnplPaymentRequest : InitApmPaymentRequest
{
public string BankCode { get; set; }
public IList<BnplPaymentCartItem> CartItems;
}
}
14 changes: 14 additions & 0 deletions Craftgate/Response/ApmPaymentResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Craftgate.Model;
using Craftgate.Response.Common;
using Craftgate.Response.Dto;

namespace Craftgate.Response
{
public class ApmPaymentResponse : BasePaymentResponse
{
public ApmType ApmType { get; set; }
public string TransactionId { get; set; }
public string RedirectUrl { get; set; }
}
}
11 changes: 11 additions & 0 deletions Craftgate/Response/BnplPaymentOfferResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace Craftgate.Response.Dto
{
public class BnplPaymentOfferResponse
{
public string OfferId { get; set; }
public decimal Price { get; set; }
public IList<BnplBankOffer> BankOffers { get; set; }
}
}
15 changes: 15 additions & 0 deletions Craftgate/Response/Dto/BnplBankOffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace Craftgate.Response.Dto
{
public class BnplBankOffer
{
public string BankCode { get; set; }
public string BankName { get; set; }
public string BankIconUrl { get; set; }
public string BankTableBannerMessage { get; set; }
public string BankSmallBannerMessage { get; set; }
public bool? IsSupportNonCustomer { get; set; }
public IList<BnplBankOfferTerm> BankOfferTerms { get; set; }
}
}
13 changes: 13 additions & 0 deletions Craftgate/Response/Dto/BnplBankOfferTerm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace Craftgate.Response.Dto
{
public class BnplBankOfferTerm
{
public int? Term { get; set; }
public decimal Amount { get; set; }
public decimal TotalAmount { get; set; }
public decimal InterestRate { get; set; }
public decimal AnnualInterestRate { get; set; }
}
}
16 changes: 16 additions & 0 deletions Craftgate/Response/InitBnplPaymentResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Text;
using Craftgate.Model;
using Craftgate.Response.Dto;

namespace Craftgate.Response
{
public class InitBnplPaymentResponse
{
public long PaymentId { get; set; }
public PaymentStatus PaymentStatus { get; set; }
public ApmAdditionalAction AdditionalAction { get; set; }
public string RedirectUrl { get; set; }
public PaymentError PaymentError { get; set; }
}
}
Loading

0 comments on commit a4213e3

Please sign in to comment.