我已经用Magento 2.2建立了一个测试商店。我为商店使用一个测试贝宝帐户,为客户使用一个。我已经在配置面板中设置了Paypal,并设法通过网上商店购买了产品。
现在,我想使用带有REST请求的webhook来做到这一点。我可以在购物车中添加东西,并使用离线付款方式,没问题。这是我的结帐代码
const header_valid = {'content-type': 'application/json',
'Authorization': "Bearer " + token };
const url_valid = site+"carts/mine/payment-information";
const postbody_valid = JSON.stringify({
"paymentMethod" : {
"method" : payment // payment ="paypal_express" in this case
},
"billing_address" : {
"email" : "",
"region" : adress.region.region,
"region_id" : adress.region.region_id,
"country_id" : adress.country_id,
"street" : adress.street,
"postcode" : adress.postcode,
"city" : adress.city,
"telephone" : adress.telephone,
"firstname" : adress.firstname,
"lastname" : adress.lastname
},
"shipping_address": {
"email" : "",
"region" : adress.region.region,
"region_id" : adress.region.region_id,
"country_id" : adress.country_id,
"street" : adress.street,
"postcode" : adress.postcode,
"city" : adress.city,
"telephone" : adress.telephone,
"firstname" : adress.firstname,
"lastname" : adress.lastname
}
});
request.post({
headers : header_valid,
url : url_valid,
body : postbody_valid
},function(error_valid,response_valid,body_valid){
if(error_valid)
console.log(intent + "\n Erreur : " + error_valid);
else{
console.log(intent + "\n"+ JSON.stringify(body_valid));
if(JSON.parse(body_valid).message)
send_message(res,"Problème",id,Parametre);
else send_message(res,"La commande a été validée",id,Parametre);
}
});
但是,当我使用REST请求访问商店并尝试结帐我的购物车时,我收到消息“Problème”,这是body_valid.message:
"{\"message\":\"PayPal gateway has rejected request. Invalid token (#10410: Invalid token).\"}"
感谢您的帮助