-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds dotnet client codes and code samples (#1)
* adds dotnet client codes and code samples * update main class name * optimize imports * changes formatting and renames/orders some variables of request and response classes + Pr reviews Co-authored-by: Onur Polattimur <[email protected]>
- Loading branch information
1 parent
02068a9
commit bd94c36
Showing
75 changed files
with
2,384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Craftgate Dotnet CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
name: Dotnet Build & Test | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup dotnet 1.1 | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '1.1.x' | ||
|
||
- name: Setup dotnet 2.0 | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '2.0.x' | ||
|
||
- name: Setup dotnet 3.1 | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '3.1.x' | ||
|
||
|
||
|
||
- run: dotnet build -c Release ./Craftgate | ||
- run: dotnet test Test -f netcoreapp1.1 | ||
- run: dotnet test Test -f netcoreapp2.0 | ||
- run: dotnet test Test -f netcoreapp3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Craftgate Dotnet Client Release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
pack: | ||
name: Release Library | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup dotnet 3.1 | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '3.1.x' | ||
source-url: https://api.nuget.org/v3/index.json | ||
env: | ||
NUGET_AUTH_TOKEN: ${{secrets.NUGET_SECRET_KEY}} | ||
|
||
- name: Pack Client Library | ||
run: dotnet pack -c Release -p:PackageVersion=${GITHUB_REF#refs/*/} ./Craftgate | ||
|
||
- name: Push Packed Client Library to Nuget | ||
run: dotnet nuget push ./Craftgate/bin/Release/*.nupkg -k ${{secrets.NUGET_SECRET_KEY}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bin/ | ||
obj/ | ||
/packages/ | ||
riderModule.iml | ||
/_ReSharper.Caches/ | ||
.idea/ | ||
.DS_Store | ||
.vscode | ||
craftgate-dotnet-client.sln.DotSettings.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Craftgate.Request.Common; | ||
|
||
namespace Craftgate.Adapter | ||
{ | ||
public abstract class BaseAdapter | ||
{ | ||
private const int RandomStringSize = 8; | ||
private const string ApiVersionHeaderValue = "v1"; | ||
private const string ApiKeyHeaderName = "x-api-key"; | ||
private const string RandomHeaderName = "x-rnd-key"; | ||
private const string AuthVersionHeaderName = "x-auth-version"; | ||
private const string SignatureHeaderName = "x-signature"; | ||
private const string RandomChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
protected readonly RequestOptions RequestOptions; | ||
|
||
protected BaseAdapter(RequestOptions requestOptions) | ||
{ | ||
RequestOptions = requestOptions; | ||
} | ||
|
||
protected Dictionary<string, string> CreateHeaders(object request, string path, | ||
RequestOptions requestOptions) | ||
{ | ||
return CreateHttpHeaders(request, path, requestOptions); | ||
} | ||
|
||
protected Dictionary<string, string> CreateHeaders(string path, RequestOptions requestOptions) | ||
{ | ||
return CreateHttpHeaders(null, path, requestOptions); | ||
} | ||
|
||
private static Dictionary<string, string> CreateHttpHeaders(object request, string path, | ||
RequestOptions options | ||
) | ||
{ | ||
var headers = new Dictionary<string, string>(); | ||
|
||
var randomString = RandomString(RandomStringSize); | ||
headers.Add(ApiKeyHeaderName, options.ApiKey); | ||
headers.Add(RandomHeaderName, randomString); | ||
headers.Add(AuthVersionHeaderName, ApiVersionHeaderValue); | ||
headers.Add(SignatureHeaderName, PrepareAuthorizationString(request, path, randomString, options)); | ||
return headers; | ||
} | ||
|
||
private static string PrepareAuthorizationString(object request, string path, string randomString, | ||
RequestOptions options) | ||
{ | ||
return HashGenerator.GenerateHash(options.BaseUrl, options.ApiKey, options.SecretKey, randomString, | ||
request, path); | ||
} | ||
|
||
private static string RandomString(int length) | ||
{ | ||
var stringChars = new char[length]; | ||
var random = new Random(); | ||
for (var i = 0; i < stringChars.Length; i++) | ||
stringChars[i] = RandomChars[random.Next(RandomChars.Length)]; | ||
return new string(stringChars); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Craftgate.Net; | ||
using Craftgate.Request; | ||
using Craftgate.Request.Common; | ||
using Craftgate.Response; | ||
|
||
namespace Craftgate.Adapter | ||
{ | ||
public class InstallmentAdapter : BaseAdapter | ||
{ | ||
public InstallmentAdapter(RequestOptions requestOptions) : base(requestOptions) | ||
{ | ||
} | ||
|
||
public InstallmentListResponse SearchInstallments(SearchInstallmentsRequest searchInstallmentsRequest) | ||
{ | ||
var queryParam = RequestQueryParamsBuilder.BuildQueryParam(searchInstallmentsRequest); | ||
var path = "/installment/v1/installments" + queryParam; | ||
return RestClient.Get<InstallmentListResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public BinNumberResponse RetrieveBinNumber(string binNumber) | ||
{ | ||
var path = "/installment/v1/bins/" + binNumber; | ||
return RestClient.Get<BinNumberResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Craftgate.Net; | ||
using Craftgate.Request; | ||
using Craftgate.Request.Common; | ||
using Craftgate.Response; | ||
|
||
namespace Craftgate.Adapter | ||
{ | ||
public class OnboardingAdapter : BaseAdapter | ||
{ | ||
public OnboardingAdapter(RequestOptions requestOptions) : base(requestOptions) | ||
{ | ||
} | ||
|
||
public MemberResponse CreateMember(CreateMemberRequest createMemberRequest) | ||
{ | ||
var path = "/onboarding/v1/members"; | ||
return RestClient.Post<MemberResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(createMemberRequest, path, RequestOptions), | ||
createMemberRequest); | ||
} | ||
|
||
public MemberResponse UpdateMember(long id, UpdateMemberRequest updateMemberRequest) | ||
{ | ||
var path = "/onboarding/v1/members/" + id; | ||
return RestClient.Put<MemberResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(updateMemberRequest, path, RequestOptions), | ||
updateMemberRequest); | ||
} | ||
|
||
public MemberResponse RetrieveMember(long id) | ||
{ | ||
var path = "/onboarding/v1/members/" + id; | ||
return RestClient.Get<MemberResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public MemberListResponse SearchMembers(SearchMemberRequest searchMemberRequest) | ||
{ | ||
var queryParam = RequestQueryParamsBuilder.BuildQueryParam(searchMemberRequest); | ||
var path = "/onboarding/v1/members" + queryParam; | ||
return RestClient.Get<MemberListResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using Craftgate.Net; | ||
using Craftgate.Request; | ||
using Craftgate.Request.Common; | ||
using Craftgate.Response; | ||
using Craftgate.Response.Dto; | ||
|
||
namespace Craftgate.Adapter | ||
{ | ||
public class PaymentAdapter : BaseAdapter | ||
{ | ||
public PaymentAdapter(RequestOptions requestOptions) : base(requestOptions) | ||
{ | ||
} | ||
|
||
public PaymentResponse CreatePayment(CreatePaymentRequest createPaymentRequest) | ||
{ | ||
var path = "/payment/v1/card-payments"; | ||
return RestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(createPaymentRequest, path, RequestOptions), | ||
createPaymentRequest); | ||
} | ||
|
||
public PaymentResponse RetrievePayment(long id) | ||
{ | ||
var path = "/payment/v1/card-payments/" + id; | ||
return RestClient.Get<PaymentResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public PaymentTransactionApprovalListResponse ApprovePaymentTransactions( | ||
ApprovePaymentTransactionsRequest approvePaymentTransactionsRequest) | ||
{ | ||
var path = "/payment/v1/payment-transactions/approve"; | ||
return RestClient.Post<PaymentTransactionApprovalListResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(approvePaymentTransactionsRequest, path, RequestOptions), | ||
approvePaymentTransactionsRequest); | ||
} | ||
|
||
public PaymentTransactionApprovalListResponse DisapprovePaymentTransactions( | ||
DisapprovePaymentTransactionsRequest disapprovePaymentTransactionsRequest) | ||
{ | ||
var path = "/payment/v1/payment-transactions/disapprove"; | ||
return RestClient.Post<PaymentTransactionApprovalListResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(disapprovePaymentTransactionsRequest, path, RequestOptions), | ||
disapprovePaymentTransactionsRequest); | ||
} | ||
|
||
public InitThreeDSPaymentResponse Init3DSPayment(InitThreeDSPaymentRequest initThreeDSPaymentRequest) | ||
{ | ||
var path = "/payment/v1/card-payments/3ds-init"; | ||
return RestClient.Post<InitThreeDSPaymentResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(initThreeDSPaymentRequest, path, RequestOptions), | ||
initThreeDSPaymentRequest); | ||
} | ||
|
||
public PaymentResponse Complete3DSPayment(CompleteThreeDSPaymentRequest completeThreeDsPaymentRequest) | ||
{ | ||
var path = "/payment/v1/card-payments/3ds-complete"; | ||
return RestClient.Post<PaymentResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(completeThreeDsPaymentRequest, path, RequestOptions), | ||
completeThreeDsPaymentRequest); | ||
} | ||
|
||
public PaymentTransactionRefundResponse RefundPaymentTransaction( | ||
RefundPaymentTransactionRequest refundPaymentTransactionRequest) | ||
{ | ||
var path = "/payment/v1/refund-transactions"; | ||
return RestClient.Post<PaymentTransactionRefundResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(refundPaymentTransactionRequest, path, RequestOptions), | ||
refundPaymentTransactionRequest); | ||
} | ||
|
||
public PaymentTransactionRefundResponse RetrievePaymentTransactionRefund(long id) | ||
{ | ||
var path = "/payment/v1/refund-transactions/" + id; | ||
return RestClient.Get<PaymentTransactionRefundResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public PaymentTransactionRefundListResponse SearchPaymentTransactionRefunds( | ||
SearchPaymentTransactionRefundsRequest searchPaymentTransactionRefundsRequest) | ||
{ | ||
var query = RequestQueryParamsBuilder.BuildQueryParam(searchPaymentTransactionRefundsRequest); | ||
var path = "/payment/v1/refund-transactions" + query; | ||
|
||
return RestClient.Get<PaymentTransactionRefundListResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public PaymentRefundResponse RefundPayment(RefundPaymentRequest refundPaymentRequest) | ||
{ | ||
var path = "/payment/v1/refunds"; | ||
return RestClient.Post<PaymentRefundResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(refundPaymentRequest, path, RequestOptions), | ||
refundPaymentRequest); | ||
} | ||
|
||
public PaymentRefundResponse RetrievePaymentRefund(long id) | ||
{ | ||
var path = "/payment/v1/refunds/" + id; | ||
return RestClient.Get<PaymentRefundResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public StoredCardResponse StoreCard(StoreCardRequest storeCardRequest) | ||
{ | ||
var path = "/payment/v1/cards"; | ||
return RestClient.Post<StoredCardResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(storeCardRequest, path, RequestOptions), storeCardRequest); | ||
} | ||
|
||
public StoredCardListResponse SearchStoredCards(SearchStoredCardsRequest searchStoredCardsRequest) | ||
{ | ||
var query = RequestQueryParamsBuilder.BuildQueryParam(searchStoredCardsRequest); | ||
var path = "/payment/v1/cards" + query; | ||
|
||
return RestClient.Get<StoredCardListResponse>(RequestOptions.BaseUrl + path, | ||
CreateHeaders(path, RequestOptions)); | ||
} | ||
|
||
public void DeleteStoredCard(DeleteStoredCardRequest deleteStoredCardRequest) | ||
{ | ||
var query = RequestQueryParamsBuilder.BuildQueryParam(deleteStoredCardRequest); | ||
var path = "/payment/v1/cards" + query; | ||
|
||
RestClient.Delete<object>(RequestOptions.BaseUrl + path, CreateHeaders(path, RequestOptions)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks> | ||
<RootNamespace>Craftgate</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.