Skip to content

Commit

Permalink
refactor: paynet logics are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
onurkanbakirci committed Dec 23, 2023
1 parent 850235e commit 5101e96
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 20 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,52 @@ var paynetPaymentIntegration = new PaynetPaymentIntegration(

// Get installments
var installments = await paynetPaymentIntegration.CheckInstallmentAsync(new CheckInstallmentRequestModel(bin: "bin", amount: 100));

// Non secure payment
var nonSecurePaymentResponse = await paynetPaymentIntegration.NonSecurePaymentAsync(new NonSecurePaymentRequestModel(
amount: "100",
referenceNo: "referenceNo",
domain: "domain",
cardHolder: "cardHolder",
pan: "pan",
month: "month",
year: "year",
cvc: "cvc",
instalment: 1));

// Secure payment
// 1. Get secure payment initial
var securePaymentInitialResponse = await paynetPaymentIntegration.SecurePaymentInitialAsync(new SecurePaymentInitialRequestModel(
amount: "100",
orderRefNo: "orderRefNo",
domain: "domain",
cardHolder: "cardHolder",
pan: "pan",
month: 1,
year: 2021,
cVC: "cVC",
returnUrl: "returnUrl",
instalment: 1));

// 2. Show 3ds html content to user
Console.WriteLine(securePaymentInitialResponse.HtmlContent);

// 3. After successfull 3d confirmation, secure payment charge
var securePaymentChargeRequest = new SecurePaymentChargeRequestModel(
sessionId: securePaymentInitialResponse.SessionId,
tokenId: securePaymentInitialResponse.TokenId);


// Cancel payment
var cancelResponse = await paynetPaymentIntegration.CancelAsync(new CancellationRequestModel(
xactId: "xactId",
succeedUrl: "succeedUrl"
));

// Refund payment
var refundResponse = await paynetPaymentIntegration.RefundAsync(new RefundRequestModel(
xactId: "xactId",
amount: "100",
succeedUrl: "succeedUrl"
));
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,52 @@
isInProduction: false);

// Get installments
var installments = await paynetPaymentIntegration.CheckInstallmentAsync(new CheckInstallmentRequestModel(bin: "bin", amount: 100));
var installments = await paynetPaymentIntegration.CheckInstallmentAsync(new CheckInstallmentRequestModel(bin: "bin", amount: 100));

// Non secure payment
var nonSecurePaymentResponse = await paynetPaymentIntegration.NonSecurePaymentAsync(new NonSecurePaymentRequestModel(
amount: "100",
referenceNo: "referenceNo",
domain: "domain",
cardHolder: "cardHolder",
pan: "pan",
month: "month",
year: "year",
cvc: "cvc",
instalment: 1));

// Secure payment
// 1. Get secure payment initial
var securePaymentInitialResponse = await paynetPaymentIntegration.SecurePaymentInitialAsync(new SecurePaymentInitialRequestModel(
amount: "100",
orderRefNo: "orderRefNo",
domain: "domain",
cardHolder: "cardHolder",
pan: "pan",
month: 1,
year: 2021,
cVC: "cVC",
returnUrl: "returnUrl",
instalment: 1));

// 2. Show 3ds html content to user
Console.WriteLine(securePaymentInitialResponse.HtmlContent);

// 3. After successfull 3d confirmation, secure payment charge
var securePaymentChargeRequest = new SecurePaymentChargeRequestModel(
sessionId: securePaymentInitialResponse.SessionId,
tokenId: securePaymentInitialResponse.TokenId);


// Cancel payment
var cancelResponse = await paynetPaymentIntegration.CancelAsync(new CancellationRequestModel(
xactId: "xactId",
succeedUrl: "succeedUrl"
));

// Refund payment
var refundResponse = await paynetPaymentIntegration.RefundAsync(new RefundRequestModel(
xactId: "xactId",
amount: "100",
succeedUrl: "succeedUrl"
));
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,59 @@
namespace Integration.PaymentGateways.Paynet.Infrastructure.PaymentIntegration;
public interface IPaynetPaymentIntegration : IPaymentIntegration
{
/// <summary>
/// 3D doğrulama olmadan ödeme servisimizi kullanarak tek çekim,
/// taksitli ve saklı kart ile ödeme işlemlerini gerçekleştirebilirsiniz.
/// Kredi kartından direkt ödeme tutarı çekilir, 3D doğrulama yapılmaz.
/// </summary>
/// <param name="nonSecurePaymentRequest"></param>
/// <returns><see cref="NonSecurePaymentResponseModel"/></returns>
public Task<NonSecurePaymentResponseModel> NonSecurePaymentAsync(NonSecurePaymentRequestModel nonSecurePaymentRequest);
public Task<SecurePaymentInitialResponseModel> SecurePaymentChargeAsync(SecurePaymentInitialRequestModel securePaymentInitialRequest);

/// <summary>
/// Ödeme işleminden farklı olarak return_url parametresi gönderilir.
/// Servisten dönen post_url ya da html_content parametrelerini kullanarak
/// bankaların 3D doğrulama sayfasını açabilirsiniz.
/// </summary>
/// <param name="securePaymentInitialRequest"></param>
/// <returns><see cref="SecurePaymentInitialResponseModel"/></returns>
public Task<SecurePaymentInitialResponseModel> SecurePaymentInitialAsync(SecurePaymentInitialRequestModel securePaymentInitialRequest);

/// <summary>
/// 3D doğrulama sonucunda kredi kartından ilgili tutarın çekim yapıldığı servis.
/// "3D ödeme başlatma" servisinde kullandığınız return_url'e post edilen session_id
/// ve token_id değerlerini bu service post edip ödeme akışını tamamlayabilirsiniz.
/// </summary>
/// <param name="securePaymentChargeRequest"></param>
/// <returns><see cref="SecurePaymentChargeResponseModel"/></returns>
public Task<SecurePaymentChargeResponseModel> SecurePaymentChargeAsync(SecurePaymentChargeRequestModel securePaymentChargeRequest);

/// <summary>
/// Başarılı kredi kartı işlemlerinin iptali, iadesi veya kısmi iadesi için kullanılır.
/// Burada önemli olan nokta işlemin yapıldığı tarihtir. Aynı gün yapılan işlemler tüm
/// tutar iptal edilir. Geçmiş tarihli işlemler tümü iade olabilir ya da kısmı iade yapabilirsiniz.
/// Aynı gün yapılan işlemlerde kısmi iade yapılamaz.
/// </summary>
/// <param name="refundRequest"></param>
/// <returns><see cref="RefundResponseModel"/></returns>
public Task<RefundResponseModel> RefundAsync(RefundRequestModel refundRequest);

/// <summary>
/// Başarılı kredi kartı işlemlerinin iptali, iadesi veya kısmi iadesi için kullanılır.
/// Burada önemli olan nokta işlemin yapıldığı tarihtir. Aynı gün yapılan işlemler tüm
/// tutar iptal edilir. Geçmiş tarihli işlemler tümü iade olabilir ya da kısmı iade yapabilirsiniz.
/// Aynı gün yapılan işlemlerde kısmi iade yapılamaz.
/// </summary>
/// <param name="cancellationRequest"></param>
/// <returns><see cref="CancellationResponseModel"/></returns>
public Task<CancellationResponseModel> CancelAsync(CancellationRequestModel cancellationRequest);

/// <summary>
/// 3D doğrulama olmadan ödeme servisimizi kullanarak tek çekim,
/// taksitli ve saklı kart ile ödeme işlemlerini gerçekleştirebilirsiniz.
/// Kredi kartından direkt ödeme tutarı çekilir, 3D doğrulama yapılmaz.
/// </summary>
/// <param name="nonSecurePaymentRequest"></param>
/// <returns><see cref="CheckInstallmentResponseModel"/></returns>
public Task<CheckInstallmentResponseModel> CheckInstallmentAsync(CheckInstallmentRequestModel checkInstallmentRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
namespace Integration.PaymentGateways.Paynet.Infrastructure.PaymentIntegration.Models.Request;
public class CancellationRequestModel : IRequestModel
{
public CancellationRequestModel(string xactId, string? succeedUrl = null)
{
XactId = xactId;
SucceedUrl = succeedUrl;
}

public string XactId { get; set; }

public string? SucceedUrl { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ public class CheckInstallmentRequestModel : IRequestModel
public bool? AddcomissionToAmount { get; set; }
public bool? MergeOption { get; set; }

public CheckInstallmentRequestModel(string? bin = null, decimal? amount = null)
public CheckInstallmentRequestModel(int? posType = null, string? ratioCode = null, string? bin = null, decimal? amount = null, string? agentId = null, string? cardType = null, bool? addcomissionToAmount = null, bool? mergeOption = null)
{
PosType = posType;
RatioCode = ratioCode;
Bin = bin;
Amount = amount is not null ? amount * 100 : null;
Amount = amount;
AgentId = agentId;
CardType = cardType;
AddcomissionToAmount = addcomissionToAmount;
MergeOption = mergeOption;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@

using Integration.Hub;
using Integration.Hub;

namespace Integration.PaymentGateways.Paynet.Infrastructure.PaymentIntegration.Models.Request;
public class NonSecurePaymentRequestModel : IRequestModel
{
public NonSecurePaymentRequestModel(string amount, string referenceNo, string domain, string cardHolder, string pan, string month, string year, string cvc, int? instalment = null)
{
Amount = amount;
ReferenceNo = referenceNo;
Domain = domain;
CardHolder = cardHolder;
Pan = pan;
Month = month;
Year = year;
CVC = cvc;
Instalment = instalment;
}

/// <summary>
/// Kredi kartından çekilecek tutar. Ondalık ayıraç olarak virgül (,) kullanılmaktadır.(Zorunlu)
/// </summary>
Expand All @@ -14,11 +26,6 @@ public class NonSecurePaymentRequestModel : IRequestModel
/// </summary>
public string ReferenceNo { get; set; }

/// <summary>
/// Ana firma bayi referans kodu (Zorunlu değil)
/// </summary>
public string AgentReferenceNo { get; set; }

/// <summary>
/// İşlemin yapıldığı uygulamanın domain bilgisi. ( örn: www.acme.com ) (Zorunlu)
/// </summary>
Expand Down Expand Up @@ -50,6 +57,11 @@ public class NonSecurePaymentRequestModel : IRequestModel
/// </summary>
public string CVC { get; set; }

/// <summary>
/// Ana firma bayi referans kodu (Zorunlu değil)
/// </summary>
public string AgentReferenceNo { get; set; }

public string CardHash { get; set; }

public string CardHolderName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ namespace Integration.PaymentGateways.Paynet.Infrastructure.PaymentIntegration.M

public class RefundRequestModel : IRequestModel
{
public RefundRequestModel(string xactId, string amount, string? succeedUrl = null)
{
XactId = xactId;
Amount = amount;
SucceedUrl = succeedUrl;
}

public string XactId { get; set; }

public string Amount { get; set; }

public string SucceedUrl { get; set; }
public string? SucceedUrl { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
namespace Integration.PaymentGateways.Paynet.Infrastructure.PaymentIntegration.Models.Request;
public class SecurePaymentChargeRequestModel : IRequestModel
{
public SecurePaymentChargeRequestModel(string sessionId, string tokenId, int? transactionType = null)
{
SessionId = sessionId;
TokenId = tokenId;
TransactionType = transactionType;
}

public string SessionId { get; set; }

public string TokenId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
namespace Integration.PaymentGateways.Paynet.Infrastructure.PaymentIntegration.Models.Request;
public class SecurePaymentInitialRequestModel : IRequestModel
{
public SecurePaymentInitialRequestModel(string amount, string orderRefNo, string domain, string cardHolder, string pan, int month, int year, string cVC, string returnUrl, int? instalment = null)

Check warning on line 6 in src/PaymentGateways/Integration.PaymentGateways.Paynet/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs

View workflow job for this annotation

GitHub Actions / Build Lib

Non-nullable property 'AgentReferenceNo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in src/PaymentGateways/Integration.PaymentGateways.Paynet/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs

View workflow job for this annotation

GitHub Actions / Build Lib

Non-nullable property 'CardHash' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in src/PaymentGateways/Integration.PaymentGateways.Paynet/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs

View workflow job for this annotation

GitHub Actions / Build Lib

Non-nullable property 'CardHolderPhone' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
Amount = amount;
OrderRefNo = orderRefNo;
Domain = domain;
CardHolder = cardHolder;
Pan = pan;
Month = month;
Year = year;
CVC = cVC;
ReturnUrl = returnUrl;
Instalment = instalment;
}

public string AgentReferenceNo { get; set; }

public string Amount { get; set; }

public string OrderRefNo { get; set; }

public string AgentReferenceNo { get; set; }

public string Domain { get; set; }

public string CardHolder { get; set; }
Expand All @@ -21,6 +35,10 @@ public class SecurePaymentInitialRequestModel : IRequestModel

public string CVC { get; set; }

public string ReturnUrl { get; set; }

public int? Instalment { get; set; }

public string CardHash { get; set; }

public string CardHolderPhone { get; set; }
Expand All @@ -29,8 +47,6 @@ public class SecurePaymentInitialRequestModel : IRequestModel

public string Description { get; set; }

public int? Instalment { get; set; }

public string AgentId { get; set; }

public string CompanyAmount { get; set; }
Expand Down Expand Up @@ -69,8 +85,5 @@ public class SecurePaymentInitialRequestModel : IRequestModel

public string Iban { get; set; }

public string ReturnUrl { get; set; }

public bool ApprovedCard { get; set; }

}
Loading

0 comments on commit 5101e96

Please sign in to comment.