我已经阅读了这里的大部分说明,并且能够处理测试卡事务https://docs.adyen.com/online-payments/web-drop-in。我在这里删除了repo示例,https://github.com/adyen-examples/adyen-dotnet-online-payments。
我在重定向结果中遇到的问题是,returnUrl没有将sessionId或作为文档附加到其中。不管我在付款请求中设置了什么。
因此,在我的控制器中,会话正在设置sessionsRequest.returnUrl = $"https://localhost:44303/Home/Redirect?orderRef={orderRef}"“
[HttpPost("api/sessions")]
public ActionResult<string> 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(); }

有什么建议吗?提前谢谢你!
发布于 2022-07-05 10:41:33
使用所需的sessions (即https://localhost:44303/...)设置(正确)会话请求(在执行returnUrl调用之前准备)。此时,还没有与Adyen平台的交互。
一旦提交,/sessions/调用将负责执行付款和与Adyen平台的交互。当支付流程需要第二步(即对于iDeal,购物者打开家庭银行应用程序)时,购物者被重定向到returnUrl,在returnUrl中附加redirectResult
https://localhost:44303/Home/Redirect?orderRef=123&redirectResult=eyJ0cmFuc1N0YX..在信用卡支付的情况下(没有额外的验证步骤),不涉及重定向(不使用returnUrl)。
https://stackoverflow.com/questions/72867130
复制相似问题