Интернет-магазин AdyenC#

Место общения программистов C#
Ответить
Anonymous
 Интернет-магазин Adyen

Сообщение Anonymous »

Я выполнил большую часть инструкций здесь и могу обработать тестовую транзакцию по карте https://docs.adyen.com/online-pays/web-drop-in. Я извлек пример репозитория здесь https://github.com/adyen-examples/adyen ... nline-pays.
Проблема, с которой я столкнулся в результате перенаправления, К returnUrl не добавлен sessionId или redirectResult согласно документации. Это то, что я установил в запросе платежа.
Итак, в моем контроллере сеансы устанавливают sessionRequest.returnUrl = $"https://localhost:44303/Home/Redirect ?orderRef={orderRef}":

Код: Выделить всё

        [HttpPost("api/sessions")]
public ActionResult Sessions()
{
//var hi = new Adyen.
var sessionsRequest = new CreateCheckoutSessionRequest();
sessionsRequest.merchantAccount = _merchant_account; // required
sessionsRequest.channel = (CreateCheckoutSessionRequest.ChannelEnum?) PaymentRequest.ChannelEnum.Web;

var amount = new Amount("EUR", 1000); // value is 10€ in minor units
sessionsRequest.amount = amount;
var orderRef = System.Guid.NewGuid();
sessionsRequest.reference = orderRef.ToString(); // required

// required for 3ds2 redirect flow
sessionsRequest.returnUrl = $"https://localhost:44303/Home/Redirect?orderRef={orderRef}";

try
{
var res = _checkout.Sessions(sessionsRequest);
_logger.LogInformation($"Response for Payment API::\n{res}\n");
var json = res.ToJson();
return json;// res.ToJson();
}
catch (Adyen.HttpClient.HttpClientException e)
{
_logger.LogError($"Request for Payments failed::\n{e.ResponseBody}\n");
throw e;
}
}
В adyenImplementation.js я добавил console.info для отображения объекта сеанса, и, глядя на консоль, returnUrl ничего не добавляет.

Код: Выделить всё

const clientKey = document.getElementById("clientKey").innerHTML;

// Used to finalize a checkout call in case of redirect
const urlParams = new URLSearchParams(window.location.search);
const sessionId = urlParams.get('sessionId'); // Unique identifier for the payment session
const redirectResult = urlParams.get('redirectResult');

// Typical checkout experience
async function startCheckout() {
// Used in the demo to know which type of checkout was chosen
const type = document.getElementById("type").innerHTML;

try {
const checkoutSessionResponse = await callServer("/api/sessions");
const checkout = await createAdyenCheckout(checkoutSessionResponse);
checkout.create(type).mount(document.getElementById("payment"));

} catch (error) {
console.error(error);
alert("Error occurred. Look at console for details");
}
}

// Some payment methods use redirects. This is where we finalize the operation
async function finalizeCheckout() {
try {
const checkout = await createAdyenCheckout({id: sessionId});
checkout.submitDetails({details: {redirectResult}});
} catch (error) {
console.error(error);
alert("Error occurred. Look at console for details");
}
}

async function createAdyenCheckout(session){
return new AdyenCheckout(
{
clientKey,
locale: "en_US",
environment: "test",
session: session,
showPayButton: true,
paymentMethodsConfiguration: {
ideal: {
showImage: true,
},
card: {
hasHolderName: true,
holderNameRequired: true,
name: "Credit or debit card",
amount: {
value: 1000,
currency: "EUR",
},
},
paypal: {
amount: {
value: 1000,
currency: "USD",
},
environment: "test", // Change this to "live" when you're ready to accept live PayPal payments
countryCode: "US", // Only needed for test.  This will be automatically retrieved when you are in production.
}
},
onPaymentCompleted: (result, component) => {
console.info("onPaymentCompleted");
console.info("Session::", session);
console.info(result, component);
handleServerResponse(result, component);
},
onError: (error, component) => {
console.error("onError");
console.error(error.name, error.message, error.stack, component);
handleServerResponse(error, component);
},
}
);
}

// Calls your server endpoints
async function callServer(url, data) {
const res = await fetch(url, {
method: "POST",
body: data ? JSON.stringify(data) : "",
headers: {
"Content-Type": "application/json",
},
});

return await res.json();
}

function handleServerResponse(res, _component) {
switch (res.resultCode) {
case "Authorised":
window.location.href = "/Home/result/success";
break;
case "Pending":
case "Received":
window.location.href = "/Home/result/pending";
break;
case "Refused":
window.location.href = "/Home/result/failed";
break;
default:
window.location.href = "/Home/result/error";
break;
}
}

if (!sessionId) { startCheckout() } else { finalizeCheckout(); }
Изображение

Пожалуйста, какой-нибудь совет? Заранее спасибо!


Подробнее здесь: https://stackoverflow.com/questions/728 ... eb-drop-in
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»