Finalnie zrezygnowałem z ajaxa (częściowo) i zrobiłem to w klasycznym, nudnym, niewidzialnym formie:
<form action="https://ssl.dotpay.pl/test_payment/" method="post" id="dotpay_redirection_form">
<input name="api_version" value="dev" type="hidden" />
<input name="lang" value="pl" type="hidden" />
<input name="id" value="123456" type="hidden" />
<input name="amount" value="" id="PaymentAmountHidden" type="hidden" />
<input name="currency" value="PLN" type="hidden" />
<input name="description" value="" id="description" type="hidden" />
<input name="chk" value="" id="chk" type="hidden" />
<button class="centralize paymentSubmitButton" type="submit" form="dotpay_redirection_form" value="Submit">OPŁAĆ DOSTĘP</button>
</form>
Do tego należy oczywiście dodać obliczony kod z sprawdzający o enigmatycznej nazwie "chk". W tym celu zrobiłem sobie funkcję javaScriptową:
function SetChk() {
$.ajax({
method: "GET",
url: "/Payments/GetChkForDotPay",
data:
{
amount:$("#PaymentAmount").val(),
description: $("#description").val()
}
})
.done(function (content) {
$("#chk").val(content);
})
.fail(function () {
$("#chk").val("");
});
}
Sama zaś funkcja obliczająca chk znajduje się, naturalnie, w PaymentsController i wygląda tak:
public String GetChkForDotPay(string amount, string description)
{
string PIN = "ABCDE123455",
api_version = "dev",
lang = "pl",
id = "123456",
currency = "PLN",
concatOfParameters;
concatOfParameters = PIN + api_version + lang + id + amount + currency + description;
return EncodeToSha256(concatOfParameters);
}
private string EncodeToSha256(string concatOfStrings)
{
SHA256Managed sha256 = new SHA256Managed();
string resultString = null;
byte[] byteConcat = Encoding.UTF8.GetBytes(concatOfStrings);
int byteNumber = Encoding.UTF8.GetByteCount(concatOfStrings);
byte[] result = sha256.ComputeHash(byteConcat, 0, byteNumber);
foreach (byte a in result)
{
resultString += a.ToString("x2");
}
return resultString;
}
Do tego wszystkiego potrzebujemy bibliotek:
using System.Security.Cryptography;
using System.Text;
Kod PIN możemy pobrać z naszego panelu w DotPay Ustawienia -> Powiadomienia -> Konfiguracja urlc. Należy również odfajkować blokowanie zewnętrznych URLC.
Edit:
PS. Szukam pracy w Trójmieście jako junior .NET developer :p