Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,4 @@ $RECYCLE.BIN/
!.vscode/extensions.json

*.nupkg
.vscode/
44 changes: 44 additions & 0 deletions Examples/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Zotapay.Models.Payout;
using Zotapay.Callback;
using Zotapay;
using Zotapay.Models.Deposit;

class Example
{
Expand All @@ -15,6 +16,7 @@ static void Main(string[] args)
// MGClient client = CreateClientWithEnvVarExample();
MGClient client = CreateClientWithExplicitConfig();

DepositCCDirectExample(client);
DepositExample(client);
QueryOrderExample(client);
PayoutExample(client);
Expand All @@ -24,6 +26,7 @@ static void Main(string[] args)
public static MGClient CreateClientWithExplicitConfig()
{
// Credentials are hardcoded for showcase purposes - do not use hardcoded credentials on live environment
// TODO: revert
MGClient clientWithConfig = new MGClient(
merchantSecret: "merchant-secret-key",
endpointId: "400007",
Expand Down Expand Up @@ -53,6 +56,47 @@ public static MGClient CreateClientWithEnvVarExample()
return client;
}

public static void DepositCCDirectExample(MGClient client)
{
// Assemble deposit order data
MGDepositCardRequest DepositDirectCCOrderRequest = new MGDepositCardRequest
{
MerchantOrderID = "QvE8dZshpKhaOmHY1",
OrderAmount = "100.00",
CustomerEmail = "[email protected]",
OrderCurrency = "USD",
MerchantOrderDesc = "desc",
CustomerFirstName = "John",
CustomerLastName = "Doe",
CustomerAddress = "The Moon, hill 42",
CustomerCity = "Sofia",
CustomerCountryCode = "BG",
CustomerZipCode = "1303",
CustomerPhone = "123",
CustomerIP = "127.0.0.1",
RedirectUrl = "https://example-merchant.com/payment/return",
CheckoutUrl = "https://example-merchant.com/deposit",
CallbackUrl = "https://example-merchant.com/payment/callback",
};

// Initiate deposit order request
MGDepositCardResult resp = client.InitCardDeposit(DepositDirectCCOrderRequest).Result;

// Check the request status
if (!resp.IsSuccess)
{
// handle unsuccessful request
string reasonForFailure = resp.Message;
// ...
return;
}

// Once no errors are encountered,
// order should be checked via status check or resolved by callback from Zota
DepositCardResponseData data = resp.Data;
Console.WriteLine(data);
}

public static void ParseCallbackExample(MGClient client)
{
string exampleRawJson = "{\"type\":\"SALE\",\"status\":\"APPROVED\",\"errorMessage\":\"\",\"endpointID\":\"400009\",\"processorTransactionID\":\"279198e3-7277-4e28-a490-e02deec1a3cc\",\"orderID\":\"32453550\",\"merchantOrderID\":\"QvE8dZshpKhaOmHY1\",\"amount\":\"100.00\",\"currency\":\"USD\",\"customerEmail\":\"[email protected]\",\"customParam\":\"\",\"extraData\":{\"dcc\":false,\"paymentMethod\":\"ONLINE\"},\"originalRequest\":{\"merchantOrderID\":\"QvE8dZshpKhaOmHY1\",\"merchantOrderDesc\":\"desc\",\"orderAmount\":\"100.00\",\"orderCurrency\":\"USD\",\"customerEmail\":\"[email protected]\",\"customerFirstName\":\"John\",\"customerLastName\":\"Doe\",\"customerAddress\":\"The Moon, hill 42\",\"customerCountryCode\":\"BG\",\"customerCity\":\"Sofia\",\"customerZipCode\":\"1303\",\"customerPhone\":\"123\",\"customerIP\":\"127.0.0.1\",\"redirectUrl\":\"https://example-merchant.com/payment/return\",\"callbackUrl\":\"https://ens39ypv7jld8.x.pipedream.net\",\"checkoutUrl\":\"https://example-merchant.com/deposit\",\"signature\":\"0ca81b0354fd669b602b683ca11859635a1831d438ef276289ab653a310c8f76\",\"requestedAt\":\"0001-01-01T00:00:00Z\"},\"signature\":\"7df9a67035e2c2f145c51653bd25aa56658954dac114ce8f77ddc4f991ecab1a\"}";
Expand Down
38 changes: 37 additions & 1 deletion Zotapay/MGClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,43 @@ public async Task<MGDepositResult> InitDeposit(MGDepositRequest requestPayload)
/// <returns>Task<DepositCardResponseData> containing Zotapay API response</returns>
public async Task<MGDepositCardResult> InitCardDeposit(MGDepositCardRequest requestPayload)
{
var result = await Send(requestPayload);
// Direct card integration is broken into two requests: deposit and card
MGDepositRequest depositRequest = new MGDepositRequest
{
MerchantOrderID = requestPayload.MerchantOrderID,
OrderAmount = requestPayload.OrderAmount,
CustomerEmail = requestPayload.CustomerEmail,
OrderCurrency = requestPayload.OrderCurrency,
MerchantOrderDesc = requestPayload.MerchantOrderDesc,
CustomerFirstName = requestPayload.CustomerFirstName,
CustomerLastName = requestPayload.CustomerLastName,
CustomerAddress = requestPayload.CustomerAddress,
CustomerCity = requestPayload.CustomerCity,
CustomerCountryCode = requestPayload.CustomerCountryCode,
CustomerZipCode = requestPayload.CustomerZipCode,
CustomerPhone = requestPayload.CustomerPhone,
CustomerIP = requestPayload.CustomerIP,
RedirectUrl = requestPayload.RedirectUrl,
CheckoutUrl = requestPayload.CheckoutUrl,
CallbackUrl = requestPayload.CallbackUrl,
IsDirectCC = true
};

var result = await Send(depositRequest);
MGDepositCardResult cardResult = new MGDepositCardResult{
Code = result.Code,
IsSuccess = result.IsSuccess,
Message = result.Message
};
if (!cardResult.IsSuccess)
{
return cardResult;
}

CardDataRequest cardRequest = new CardDataRequest{

};

return (MGDepositCardResult)result;
}

Expand Down
80 changes: 80 additions & 0 deletions Zotapay/Models/Deposit/CardDataRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace Zotapay.Models.Deposit
{
using System.ComponentModel.DataAnnotations;
using System.Net.Http;
using System.Runtime.Serialization;
using Zotapay.Contracts;

/// <summary>
/// Card payment request with card data already collected
/// </summary>
internal class CardDataRequest : IMGRequest
{
/// <summary>
/// Expiration Year(e.g "2020" or just "20")
/// </summary>
[Required, StringLength(4, MinimumLength = 2)]
[DataMember(Name = "cardExpirationYear")]
internal string CardExpirationYear { get; set; }

/// <summary>
/// CVV / Security code
/// </summary>
[Required, StringLength(4, MinimumLength = 3)]
[DataMember(Name = "cardCvv")]
internal string CardCvv { get; set; }

/// <summary>
/// Expiration month(e.g "02")
/// </summary>
[Required, StringLength(2, MinimumLength = 1)]
[DataMember(Name = "cardExpirationMonth")]
internal string CardExpirationMonth { get; set; }

/// <summary>
/// Card holder name as appears on card
/// </summary>
[Required, StringLength(64, MinimumLength = 1)]
[DataMember(Name = "cardHolderName")]
internal string CardHolderName { get; set; }

/// <summary>
/// Card number (PAN)
/// </summary>
[Required, StringLength(16, MinimumLength = 12)]
[DataMember(Name = "cardNumber")]
internal string CardNumber { get; set; }

void IMGRequest.GenerateSignature(string endpointId, string secret)
{
throw new System.NotImplementedException();
}

HttpMethod IMGRequest.GetMethod()
{
return HttpMethod.Post;
}

internal string DirectUrl;

public string GetRequestUrl(string baseUrl, string endpoint)
{
if (DirectUrl != "")
{
return DirectUrl;
}

throw new System.MissingMemberException("DirectUrl is not set");
}

IMGResult IMGRequest.GetResultInstance()
{
return new MGDepositCardResult();
}

void IMGRequest.SetupPrivateMembers(string merchantId)
{
return;
}
}
}
5 changes: 0 additions & 5 deletions Zotapay/Models/Deposit/MGDepositCardRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,5 @@ public class MGDepositCardRequest : MGDepositRequest
[Required, StringLength(16, MinimumLength = 12)]
[DataMember(Name = "cardNumber")]
public string CardNumber { get; set; }

public override IMGResult GetResultInstance()
{
return new MGDepositCardResult();
}
}
}
11 changes: 11 additions & 0 deletions Zotapay/Models/Deposit/MGDepositRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public void GenerateSignature(string endpointId, string secret)
this.Signature = Hasher.ToSHA256(toSign);
}

/// <summary>
/// Indicates, wether request is using direct credit card API
/// </summary>
internal bool IsDirectCC;

/// <summary>
/// Gets the full request url
/// </summary>
Expand All @@ -199,6 +204,12 @@ public void GenerateSignature(string endpointId, string secret)
/// <returns>The full deposit request url</returns>
public string GetRequestUrl(string baseUrl, string endpoint)
{
if (this.IsDirectCC)
{
string urlDirectPath = string.Format(URL.PATH_DEPOSIT_DIRECT, endpoint);
return baseUrl + urlDirectPath;
}

string urlPath = string.Format(URL.PATH_DEPOSIT, endpoint);
return baseUrl + urlPath;
}
Expand Down
5 changes: 5 additions & 0 deletions Zotapay/Static/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public static class URL
/// </summary>
public const string PATH_DEPOSIT = BASE_URL + "/deposit/request/{0}/";

/// <summary>
/// Deposit path with an endpoint id for direct card requests
/// </summary>
public const string PATH_DEPOSIT_DIRECT = BASE_URL + "/deposit/request/direct/{0}/";

/// <summary>
/// Order status check path
/// </summary>
Expand Down
Loading