[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 ничего не добавляет.
Я выполнил большую часть инструкций здесь и могу обработать тестовую транзакцию по карте https://docs.adyen.com/online-pays/web-drop-in. Я извлек пример репозитория здесь https://github.com/adyen-examples/adyen-dotnet-online-pays. Проблема, с которой я столкнулся в результате перенаправления, К [b]returnUrl[/b] не добавлен [b]sessionId[/b] или [b]redirectResult[/b] согласно документации. Это то, что я установил в запросе платежа. Итак, в моем контроллере сеансы устанавливают sessionRequest.returnUrl = $"https://localhost:44303/Home/Redirect ?orderRef={orderRef}": [code] [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; } } [/code] В adyenImplementation.js я добавил console.info для отображения объекта сеанса, и, глядя на консоль, [b]returnUrl[/b] ничего не добавляет. [code]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;
} 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; } }