diff --git a/Craftgate/Adapter/BkmExpressPaymentAdapter.cs b/Craftgate/Adapter/BkmExpressPaymentAdapter.cs new file mode 100644 index 0000000..85a7530 --- /dev/null +++ b/Craftgate/Adapter/BkmExpressPaymentAdapter.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using Craftgate.Net; +using Craftgate.Request; +using Craftgate.Request.Common; +using Craftgate.Response; + +namespace Craftgate.Adapter +{ + public class BkmExpressPaymentAdapter : BaseAdapter + { + public BkmExpressPaymentAdapter(RequestOptions requestOptions) : base(requestOptions) + { + } + + public InitBkmExpressResponse Init(InitBkmExpressRequest initBkmExpressRequest) + { + var path = "/payment/v1/bkm-express/init"; + return RestClient.Post(RequestOptions.BaseUrl + path, + CreateHeaders(initBkmExpressRequest, path, RequestOptions), initBkmExpressRequest); + } + + public PaymentResponse Complete( + CompleteBkmExpressRequest completeBkmExpressPayment) + { + var path = "/payment/v1/bkm-express/complete"; + return RestClient.Post(RequestOptions.BaseUrl + path, + CreateHeaders(completeBkmExpressPayment, path, RequestOptions), + completeBkmExpressPayment); + } + + public PaymentResponse RetrievePayment( + string ticketId) + { + var path = "/payment/v1/bkm-express/payments/" + ticketId; + return RestClient.Get(RequestOptions.BaseUrl + path, + CreateHeaders(path, RequestOptions)); + } + + } + +} \ No newline at end of file diff --git a/Craftgate/CraftgateClient.cs b/Craftgate/CraftgateClient.cs index c39638e..e0744d3 100644 --- a/Craftgate/CraftgateClient.cs +++ b/Craftgate/CraftgateClient.cs @@ -21,6 +21,7 @@ public class CraftgateClient private readonly BankAccountTrackingAdapter _bankAccountTrackingAdapter; private readonly MerchantAdapter _merchantAdapter; private readonly JuzdanPaymentAdapter _juzdanPaymentAdapter; + private readonly BkmExpressPaymentAdapter _bkmExpressPaymentAdapter; public CraftgateClient(string apiKey, string secretKey) : this(apiKey, secretKey, BaseUrl, null) @@ -57,6 +58,7 @@ public CraftgateClient(string apiKey, string secretKey, string baseUrl, string l _bankAccountTrackingAdapter = new BankAccountTrackingAdapter(requestOptions); _merchantAdapter = new MerchantAdapter(requestOptions); _juzdanPaymentAdapter = new JuzdanPaymentAdapter(requestOptions); + _bkmExpressPaymentAdapter = new BkmExpressPaymentAdapter(requestOptions); } public PaymentAdapter Payment() @@ -133,5 +135,10 @@ public JuzdanPaymentAdapter Juzdan() { return _juzdanPaymentAdapter; } + + public BkmExpressPaymentAdapter BkmExpress() + { + return _bkmExpressPaymentAdapter; + } } } \ No newline at end of file diff --git a/Craftgate/Model/PaymentAuthenticationType.cs b/Craftgate/Model/PaymentAuthenticationType.cs index 7b5be4b..0eeaa51 100644 --- a/Craftgate/Model/PaymentAuthenticationType.cs +++ b/Craftgate/Model/PaymentAuthenticationType.cs @@ -8,6 +8,7 @@ namespace Craftgate.Model public enum PaymentAuthenticationType { [EnumMember(Value = "THREE_DS")] THREE_DS, - [EnumMember(Value = "NON_THREE_DS")] NON_THREE_DS + [EnumMember(Value = "NON_THREE_DS")] NON_THREE_DS, + [EnumMember(Value = "BKM_EXPRESS")] BKM_EXPRESS } } \ No newline at end of file diff --git a/Craftgate/Request/CompleteBkmExpressRequest.cs b/Craftgate/Request/CompleteBkmExpressRequest.cs new file mode 100644 index 0000000..490a43b --- /dev/null +++ b/Craftgate/Request/CompleteBkmExpressRequest.cs @@ -0,0 +1,10 @@ +namespace Craftgate.Request +{ + public class CompleteBkmExpressRequest + { + public bool? Status { get; set; } + public string Message { get; set; } + public string TicketId { get; set; } + + } +} \ No newline at end of file diff --git a/Craftgate/Request/InitBkmExpressRequest.cs b/Craftgate/Request/InitBkmExpressRequest.cs new file mode 100644 index 0000000..6794701 --- /dev/null +++ b/Craftgate/Request/InitBkmExpressRequest.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Craftgate.Model; +using Craftgate.Request.Dto; + +namespace Craftgate.Request +{ + public class InitBkmExpressRequest + { + public decimal? Price { get; set; } + public decimal? PaidPrice { get; set; } + public Currency? Currency { get; set; } + public PaymentGroup? PaymentGroup { get; set; } + public string ConversationId { get; set; } + public PaymentPhase PaymentPhase { get; set; } = PaymentPhase.AUTH; + public long? BuyerMemberId { get; set; } + public string BankOrderId { get; set; } + public IList Items { get; set; } + public IList EnabledInstallments { get; set; } + } +} \ No newline at end of file diff --git a/Craftgate/Response/InitBkmExpressResponse.cs b/Craftgate/Response/InitBkmExpressResponse.cs new file mode 100644 index 0000000..a9b19b5 --- /dev/null +++ b/Craftgate/Response/InitBkmExpressResponse.cs @@ -0,0 +1,9 @@ +namespace Craftgate.Response +{ + public class InitBkmExpressResponse + { + public string id { get; set; } + public string path { get; set; } + public string token { get; set; } + } +} \ No newline at end of file diff --git a/Samples/BkmExpressSample.cs b/Samples/BkmExpressSample.cs new file mode 100644 index 0000000..b7c21e2 --- /dev/null +++ b/Samples/BkmExpressSample.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using Craftgate; +using Craftgate.Model; +using Craftgate.Request; +using Craftgate.Request.Dto; +using NUnit.Framework; + +namespace Samples +{ + public class BkmExpressSample + { + private readonly CraftgateClient _craftgateClient = + new CraftgateClient("api-key", "secret-key", "https://sandbox-api.craftgate.io"); + + + [Test] + public void Init_Bkm_Express_Payment() + { + var request = new InitBkmExpressRequest + { + Price = new decimal(100.0), + PaidPrice = new decimal(100.0), + ConversationId = "456d1297-908e-4bd6-a13b-4be31a6e47d5", + Currency = Currency.TRY, + PaymentGroup = PaymentGroup.LISTING_OR_SUBSCRIPTION, + Items = new List + { + new PaymentItem + { + Name = "Item 1", + ExternalId = Guid.NewGuid().ToString(), + Price = new decimal(30.0) + }, + new PaymentItem + { + Name = "Item 2", + ExternalId = Guid.NewGuid().ToString(), + Price = new decimal(50.0) + }, + new PaymentItem + { + Name = "Item 3", + ExternalId = Guid.NewGuid().ToString(), + Price = new decimal(20.0) + } + } + }; + + var response = _craftgateClient.BkmExpress().Init(request); + Assert.NotNull(response); + } + + [Test] + public void Complete_Bkm_Express_Payment() + { + var request = new CompleteBkmExpressRequest() + { + Status = true, + Message = "İşlem Başarılı", + TicketId = "b9bd7b93-662f-4460-9ef3-8fc735853cf1", + + }; + + + var response = _craftgateClient.BkmExpress().Complete(request); + Assert.NotNull(response.HostReference); + Assert.NotNull(response); + } + + [Test] + public void Retrieve_Payment() + { + var ticketId = "b9bd7b93-662f-4460-9ef3-8fc735853cf1"; + + var response = _craftgateClient.BkmExpress().RetrievePayment(ticketId); + Assert.NotNull(response); + } + } +} \ No newline at end of file