Skip to content

Commit

Permalink
Add direct masterpass integration
Browse files Browse the repository at this point in the history
  • Loading branch information
onurpolattimur committed Sep 13, 2023
1 parent e6fdded commit c03424e
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 40 deletions.
102 changes: 102 additions & 0 deletions Craftgate/Adapter/MasterpassPaymentAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Threading.Tasks;
using Craftgate.Net;
using Craftgate.Request;
using Craftgate.Request.Common;
using Craftgate.Response;

namespace Craftgate.Adapter
{
public class MasterpassPaymentAdapter : BaseAdapter
{
public MasterpassPaymentAdapter(RequestOptions requestOptions) : base(requestOptions)
{
}

public CheckMasterpassUserResponse CheckMasterpassUser(CheckMasterpassUserRequest checkMasterpassUserRequest)
{
var path = "/payment/v1/masterpass-payments/check-user";
return RestClient.Post<CheckMasterpassUserResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(checkMasterpassUserRequest, path, RequestOptions), checkMasterpassUserRequest);
}

public Task<CheckMasterpassUserResponse> CheckMasterpassUserAsync(
CheckMasterpassUserRequest checkMasterpassUserRequest)
{
var path = "/payment/v1/masterpass-payments/check-user";
return AsyncRestClient.Post<CheckMasterpassUserResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(checkMasterpassUserRequest, path, RequestOptions), checkMasterpassUserRequest);
}

public MasterpassPaymentTokenGenerateResponse GenerateMasterpassPaymentToken(
MasterpassPaymentTokenGenerateRequest masterpassPaymentTokenGenerateRequest)
{
var path = "/payment/v2/masterpass-payments/generate-token";
return RestClient.Post<MasterpassPaymentTokenGenerateResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentTokenGenerateRequest, path, RequestOptions),
masterpassPaymentTokenGenerateRequest);
}

public Task<MasterpassPaymentTokenGenerateResponse> GenerateMasterpassPaymentTokenAsync(
MasterpassPaymentTokenGenerateRequest masterpassPaymentTokenGenerateRequest)
{
var path = "/payment/v2/masterpass-payments/generate-token";
return AsyncRestClient.Post<MasterpassPaymentTokenGenerateResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentTokenGenerateRequest, path, RequestOptions),
masterpassPaymentTokenGenerateRequest);
}

public PaymentResponse CompleteMasterpassPayment(
MasterpassPaymentCompleteRequest masterpassPaymentCompleteRequest)
{
var path = "/payment/v2/masterpass-payments/complete";
return RestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentCompleteRequest, path, RequestOptions),
masterpassPaymentCompleteRequest);
}

public Task<PaymentResponse> CompleteMasterpassPaymentAsync(
MasterpassPaymentCompleteRequest masterpassPaymentCompleteRequest)
{
var path = "/payment/v2/masterpass-payments/complete";
return AsyncRestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentCompleteRequest, path, RequestOptions),
masterpassPaymentCompleteRequest);
}

public MasterpassPaymentThreeDSInitResponse Init3DSMasterpassPayment(
MasterpassPaymentThreeDSInitRequest masterpassPaymentThreeDSInitRequest)
{
var path = "/payment/v2/masterpass-payments/3ds-init";
return RestClient.Post<MasterpassPaymentThreeDSInitResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentThreeDSInitRequest, path, RequestOptions),
masterpassPaymentThreeDSInitRequest);
}

public Task<MasterpassPaymentThreeDSInitResponse> Init3DSMasterpassPaymentAsync(
MasterpassPaymentThreeDSInitRequest masterpassPaymentThreeDSInitRequest)
{
var path = "/payment/v2/masterpass-payments/3ds-init";
return AsyncRestClient.Post<MasterpassPaymentThreeDSInitResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentThreeDSInitRequest, path, RequestOptions),
masterpassPaymentThreeDSInitRequest);
}

public PaymentResponse Complete3DSMasterpassPayment(
MasterpassPaymentThreeDSCompleteRequest masterpassPaymentThreeDSCompleteRequest)
{
var path = "/payment/v2/masterpass-payments/3ds-complete";
return RestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentThreeDSCompleteRequest, path, RequestOptions),
masterpassPaymentThreeDSCompleteRequest);
}

public Task<PaymentResponse> Complete3DSMasterpassPaymentAsync(
MasterpassPaymentThreeDSCompleteRequest masterpassPaymentThreeDSCompleteRequest)
{
var path = "/payment/v2/masterpass-payments/3ds-complete";
return AsyncRestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(masterpassPaymentThreeDSCompleteRequest, path, RequestOptions),
masterpassPaymentThreeDSCompleteRequest);
}
}
}
26 changes: 6 additions & 20 deletions Craftgate/Adapter/PaymentAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public Task<PaymentResponse> CreateApmPaymentAsync(CreateApmPaymentRequest creat
CreateHeaders(createApmPaymentRequest, path, RequestOptions),
createApmPaymentRequest);
}

public InitPosApmPaymentResponse InitPosApmPayment(InitPosApmPaymentRequest initPosApmPaymentRequest)
{
var path = "/payment/v1/pos-apm-payments/init";
Expand All @@ -308,15 +308,17 @@ public Task<InitPosApmPaymentResponse> InitPosApmPaymentAsync(InitPosApmPaymentR
initPosApmPaymentRequest);
}

public CompletePosApmPaymentResponse CompletePosApmPayment(CompletePosApmPaymentRequest completePosApmPaymentRequest)
public CompletePosApmPaymentResponse CompletePosApmPayment(
CompletePosApmPaymentRequest completePosApmPaymentRequest)
{
var path = "/payment/v1/pos-apm-payments/complete";
return RestClient.Post<CompletePosApmPaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(completePosApmPaymentRequest, path, RequestOptions),
completePosApmPaymentRequest);
}

public Task<CompletePosApmPaymentResponse> CompletePosApmPaymentAsync(CompletePosApmPaymentRequest completePosApmPaymentRequest)
public Task<CompletePosApmPaymentResponse> CompletePosApmPaymentAsync(
CompletePosApmPaymentRequest completePosApmPaymentRequest)
{
var path = "/payment/v1/pos-apm-payments/complete";
return AsyncRestClient.Post<CompletePosApmPaymentResponse>(RequestOptions.BaseUrl + path,
Expand Down Expand Up @@ -498,22 +500,6 @@ public Task<PaymentTransactionApprovalListResponse> DisapprovePaymentTransaction
disapprovePaymentTransactionsRequest);
}

public CheckMasterpassUserResponse CheckMasterpassUser(CheckMasterpassUserRequest checkMasterpassUserRequest)
{
var path = "/payment/v1/masterpass-payments/check-user";
return RestClient.Post<CheckMasterpassUserResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(checkMasterpassUserRequest, path, RequestOptions), checkMasterpassUserRequest);
}

public Task<CheckMasterpassUserResponse> CheckMasterpassUserAsync(
CheckMasterpassUserRequest checkMasterpassUserRequest)
{
var path = "/payment/v1/masterpass-payments/check-user";
return AsyncRestClient.Post<CheckMasterpassUserResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(checkMasterpassUserRequest, path, RequestOptions), checkMasterpassUserRequest);
}


public PaymentTransactionResponse UpdatePaymentTransaction(
UpdatePaymentTransactionRequest updatePaymentTransactionRequest)
{
Expand All @@ -529,7 +515,7 @@ public Task<PaymentTransactionResponse> UpdatePaymentTransactionAsync(
return AsyncRestClient.Put<PaymentTransactionResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(updatePaymentTransactionRequest, path, RequestOptions), updatePaymentTransactionRequest);
}

public bool Is3DSecureCallbackVerified(string threeDSecureCallbackKey, Dictionary<string, string> parameters)
{
string hash = parameters["hash"];
Expand Down
15 changes: 11 additions & 4 deletions Craftgate/CraftgateClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CraftgateClient
private readonly SettlementReportingAdapter _settlementReportingAdapter;
private readonly WalletAdapter _walletAdapter;
private readonly HookAdapter _hookAdapter;
private readonly MasterpassPaymentAdapter _masterpassPaymentAdapter;

public CraftgateClient(string apiKey, string secretKey)
: this(apiKey, secretKey, BaseUrl, null)
Expand All @@ -27,7 +28,7 @@ public CraftgateClient(string apiKey, string secretKey, string baseUrl)
: this(apiKey, secretKey, baseUrl, null)
{
}

public CraftgateClient(string apiKey, string secretKey, string baseUrl, string language)
{
var requestOptions = new RequestOptions
Expand All @@ -49,6 +50,7 @@ public CraftgateClient(string apiKey, string secretKey, string baseUrl, string l
_fileReportingAdapter = new FileReportingAdapter(requestOptions);
_fraudAdapter = new FraudAdapter(requestOptions);
_hookAdapter = new HookAdapter(requestOptions);
_masterpassPaymentAdapter = new MasterpassPaymentAdapter(requestOptions);
}

public PaymentAdapter Payment()
Expand Down Expand Up @@ -94,16 +96,21 @@ public PayByLinkApiAdapter PayByLink()
public FileReportingAdapter FileReporting()
{
return _fileReportingAdapter;
}
}

public FraudAdapter Fraud()
{
return _fraudAdapter;
}

public HookAdapter Hook()
{
return _hookAdapter;
}

public MasterpassPaymentAdapter Masterpass()
{
return _masterpassPaymentAdapter;
}
}
}
24 changes: 24 additions & 0 deletions Craftgate/Request/Dto/MasterpassCreatePayment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using Craftgate.Model;

namespace Craftgate.Request.Dto
{
public class MasterpassCreatePayment
{
public decimal? Price { get; set; }
public decimal? PaidPrice { get; set; }
public string PosAlias { get; set; }
public int? Installment { get; set; }
public Currency? Currency { get; set; }
public PaymentGroup? PaymentGroup { get; set; }
public string PaymentChannel { get; set; }
public string ConversationId { get; set; }
public string ExternalId { get; set; }
public PaymentPhase PaymentPhase { get; set; } = PaymentPhase.AUTH;
public long? BuyerMemberId { get; set; }
public string BankOrderId { get; set; }
public string ClientIp { get; set; }
public IList<PaymentItem> Items { get; set; }
public Dictionary<string, object> AdditionalParams { get; set; }
}
}
8 changes: 8 additions & 0 deletions Craftgate/Request/MasterpassPaymentCompleteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Craftgate.Request
{
public class MasterpassPaymentCompleteRequest
{
public string ReferenceId { get; set; }
public string Token { get; set; }
}
}
7 changes: 7 additions & 0 deletions Craftgate/Request/MasterpassPaymentThreeDSCompleteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Craftgate.Request
{
public class MasterpassPaymentThreeDSCompleteRequest
{
public long? PaymentId;
}
}
8 changes: 8 additions & 0 deletions Craftgate/Request/MasterpassPaymentThreeDSInitRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Craftgate.Request
{
public class MasterpassPaymentThreeDSInitRequest
{
public string ReferenceId { get; set; }
public string CallbackUrl { get; set; }
}
}
13 changes: 13 additions & 0 deletions Craftgate/Request/MaterpassPaymentTokenGenerateRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Craftgate.Request.Dto;

namespace Craftgate.Request
{
public class MasterpassPaymentTokenGenerateRequest
{
public string Msisdn { get; set; }
public string UserId { get; set; }
public string BinNumber { get; set; }
public bool ForceThreeDS { get; set; }
public MasterpassCreatePayment CreatePayment { get; set; }
}
}
7 changes: 7 additions & 0 deletions Craftgate/Response/MasterpassPaymentThreeDSInitResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Craftgate.Response
{
public class MasterpassPaymentThreeDSInitResponse
{
public string ReturnUrl { get; set; }
}
}
9 changes: 9 additions & 0 deletions Craftgate/Response/MasterpassPaymentTokenGenerateResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Craftgate.Response
{
public class MasterpassPaymentTokenGenerateResponse
{
public string Token { get; set; }
public string ReferenceId { get; set; }
public string OrderNo { get; set; }
}
}
Loading

0 comments on commit c03424e

Please sign in to comment.