Skip to content

Commit

Permalink
Add BKM Express Integration (#184)
Browse files Browse the repository at this point in the history
* BKM Express Integration

* Add BKM Express Integration

* update
  • Loading branch information
deryacakmak authored Jul 3, 2024
1 parent 731916f commit 9e808ce
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Craftgate/Adapter/BkmExpressPaymentAdapter.cs
Original file line number Diff line number Diff line change
@@ -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<InitBkmExpressResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(initBkmExpressRequest, path, RequestOptions), initBkmExpressRequest);
}

public PaymentResponse Complete(
CompleteBkmExpressRequest completeBkmExpressPayment)
{
var path = "/payment/v1/bkm-express/complete";
return RestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(completeBkmExpressPayment, path, RequestOptions),
completeBkmExpressPayment);
}

public PaymentResponse RetrievePayment(
string ticketId)
{
var path = "/payment/v1/bkm-express/payments/" + ticketId;
return RestClient.Get<PaymentResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(path, RequestOptions));
}

}

}
7 changes: 7 additions & 0 deletions Craftgate/CraftgateClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -133,5 +135,10 @@ public JuzdanPaymentAdapter Juzdan()
{
return _juzdanPaymentAdapter;
}

public BkmExpressPaymentAdapter BkmExpress()
{
return _bkmExpressPaymentAdapter;
}
}
}
3 changes: 2 additions & 1 deletion Craftgate/Model/PaymentAuthenticationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
10 changes: 10 additions & 0 deletions Craftgate/Request/CompleteBkmExpressRequest.cs
Original file line number Diff line number Diff line change
@@ -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; }

}
}
20 changes: 20 additions & 0 deletions Craftgate/Request/InitBkmExpressRequest.cs
Original file line number Diff line number Diff line change
@@ -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<PaymentItem> Items { get; set; }
public IList<int> EnabledInstallments { get; set; }
}
}
9 changes: 9 additions & 0 deletions Craftgate/Response/InitBkmExpressResponse.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
80 changes: 80 additions & 0 deletions Samples/BkmExpressSample.cs
Original file line number Diff line number Diff line change
@@ -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<PaymentItem>
{
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);
}
}
}

0 comments on commit 9e808ce

Please sign in to comment.