2
TL; DR:私は自分の店舗の購読を実装しようとしていますが、 "paypalobjects.com/api/checkout.js"は "sandbox.paypal.com/webapps/hermes/error"にリダイレクトします。 "通常の支払いは意図どおりに機能します。私はExpress Checkout高度なサーバー統合を使用しています。Express Checkoutによる定期支払い
paypal.Button.render({
env: 'sandbox', // Optional: specify 'sandbox' environment
payment: function(resolve, reject) {
const token = localStorage.getItem('_token').split(' ')[1];
if(!subscribe){
var CREATE_PAYMENT_URL = `/store/${store}/paypal/create-payment/${orderId}?token=${token}`;
}else{
var CREATE_PAYMENT_URL = `/store/${store}/subscribe/paypal/create-payment/${orderId}?token=${token}`;
}
paypal.request.post(CREATE_PAYMENT_URL)
.then(function(data) { resolve(data.id); })
.catch(function(err) { console.log(err); });
},
onAuthorize: function(data) {
const token = localStorage.getItem('_token').split(' ')[1];
if(!subscribe){
var EXECUTE_PAYMENT_URL = `/store/${store}/paypal/execute-payment?token=${token}`;
}else{
var EXECUTE_PAYMENT_URL = `/store/${store}/subscribe/paypal/execute-payment?token=${token}`;
}
paypal.request.post(EXECUTE_PAYMENT_URL,
{ paymentID: data.paymentID, payerID: data.payerID })
.then(function(data) {
})
.catch(function(err) { console.log("error " + err);});
},
onCancel: function(data){
cancel();
this.destroy();
},
onError: function (err) {
console.log("ERROR OCCURRED!");
console.log(err);
}
}, '#paypal-button');
本当に関係ありませんが、私のバックエンドは(テストデータで)次のようになります:
マイPaypal.Button
public function createPaypalOrder(Request $request, $store, $orderId){
$order = Order::with(['user', 'whitelabel'])->where('id', $orderId)->first();
$amout = array(
'value' => (string) $order->price/100,
'currency' => 'NOK',
);
$shippingandtax = array(
'value' => '0',
'currency' => 'NOK',
);
$charge_models = array([
'type'=> 'SHIPPING',
'amount'=> $shippingandtax,
],
[
'type'=> 'TAX',
'amount'=> $shippingandtax,
]);
$payment_definitions_creation = array();
array_push($payment_definitions_creation,[
'name' => 'Regular Payment Definition',
'type' => 'REGULAR',
'frequency' => 'MONTH',
'frequency_interval'=> '2',
'amount' => $amout,
'cycles' => '12',
'charge_models' => $charge_models
]);
$format = Config::get('constants.FRONTEND_URL')[env('APP_ENV')];
$redirectBase = sprintf($format, $order->whitelabel->subdomain, 'orders/?order=' . $order->id);
$merchant_preferences_temp = array(
'value' => '0',
'currency' => 'NOK'
);
$merchant_preferences = array(
"setup_fee" => $merchant_preferences_temp,
'return_url' => "http://www.vg.no",
'cancel_url' => "http://www.yahoo.no",
'auto_bill_amount' => 'YES',
'initial_fail_amount_action' => 'CONTINUE',
'max_fail_attempts' => '0'
);
$payment_definitions = array();
array_push($payment_definitions, $payment_definitions_creation);
$name = 'Monthly subscription to ' . (string)$order->whitelabel->title;
$body = array(
'name' => $name,
'description' => 'Subscribtion.',
'type' => 'fixed',
'payment_definitions' => $payment_definitions_creation,
"merchant_preferences"=> $merchant_preferences,
);
$token = $this->getPaypalToken($order);
$client = new \GuzzleHttp\Client();
$response = $client->post('https://api.sandbox.paypal.com/v1/payments/billing-plans', [
'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token],
'json' => $body,
]);
$paypalOrderCreation = json_decode($response->getBody());
// add stuff to db
$order->setTransactionId($paypalOrderCreation->id);
return json_encode($paypalOrderCreation);
}
私のバックエンドはのidを持つペイパルからの有効な応答を返しますオーダーと状態は「作成済み」です。 (そして、他の多くのデータ...)
{"id":"P-0SE01606VF925501Y2UAKG3Y","state":"CREATED","name":"Monthly subscription to Paypal","description":"Subscribtion.","type":"FIXED","payment_definitions":[{"id":"PD-35U317461H38251442UAKG4A","name":"Regular Payment Definition","type":"REGULAR","frequency":"Month","amount":{"currency":"NOK","value":"500"},"cycles":"12","charge_models":[{"id":"CHM-7T021625H451740052UAKG4A","type":"SHIPPING","amount":{"currency":"NOK","value":"0"}},{"id":"CHM-313690493W320615U2UAKG4A","type":"TAX","amount":{"currency":"NOK","value":"0"}}],"frequency_interval":"2"}],"merchant_preferences":{"setup_fee":{"currency":"NOK","value":"0"},"max_fail_attempts":"0","return_url":"http:\/\/www.vg.no","cancel_url":"http:\/\/www.yahoo.no","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2017-01-25T09:41:45.967Z","update_time":"2017-01-25T09:41:45.967Z","links":[{"href":"https:\/\/api.sandbox.paypal.com\/v1\/payments\/billing-plans\/P-0SE01606VF925501Y2UAKG3Y","rel":"self","method":"GET"}]}
今私の問題は私のpaypal.buttonを受信したときに、この応答は、それが情報を処理し、「sandbox.paypal.com/webapps/hermes/error」に私をリダイレクトするということですこれはやや難しいです。
ありがとうございました:
私たちは内部的な問題を抱えており、できるだけ早く解決するよう努めています。 - ペイパル – LordMarty