私もこの問題に直面しました。私のケースでは、実際には偽のデータをpaypalに送っていました。最初のステップで
は、例外をキャッチし、actualyにErrorMessage
// For testing purpose use the general exception (failed to catch with paypal for me)
catch (Exception $ex) {
if (\Config::get('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
exit;
} else {
die('Some error occur, sorry for inconvenient');
}
}
結果のメッセージはあなたが間違って得たものを解決するのに十分な情報を与える必要がありますを取得しよう。
以下私はpaypal REST APIを使用して私のために働いている自分のコードを貼り付けます。あなたは(ペイパルのハンドルキャンセルを)キャンセル/
/支払い/成功(支払いを検証&がペイパルからのリダイレクトに成功した)
/支払(支払の作成)を作成/支払い/
また、ペイパル設定を追加し、コントローラで初期化する必要があります。 paypal設定ファイルがない場合は、クライアントIDとシークレットを直接関数に設定することができます。設定は、私はすべてを持って期待しルート
// create a payment
public function create(Request $request)
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$price = '10.00'; // 10 € for example
if($price == 0) { // ensure a price above 0
return Redirect::to('/');
}
// Set Item
$item_1 = new Item();
$item_1->setName('My Item')
->setCurrency('EUR')
->setQuantity(1)
->setPrice($price);
// add item to list
$item_list = new ItemList();
$item_list->setItems(array($item_1));
$amount = new Amount();
$amount->setCurrency('EUR')
->setTotal($price); // price of all items together
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Fitondo Fitnessplan');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(URL::to('/payment/status'))
->setCancelUrl(URL::to('/payments/cancel'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
if (config('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
exit;
} else {
die('Error.');
}
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
/* here you could already add a database entry that a person started buying stuff (not finished of course) */
if(isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
}
die('Error.');
}
成功ルート
public function get(Request $request)
{
// Get the payment ID before session clear
$payment_id = $request->paymentId;
if (empty($request->PayerID) || empty($request->token)) {
die('error');
}
$payment = Payment::get($payment_id, $this->_api_context);
// PaymentExecution object includes information necessary
// to execute a PayPal account payment.
// The payer_id is added to the request query parameters
// when the user is redirected from paypal back to your site
$execution = new PaymentExecution();
$execution->setPayerId($request->PayerID);
//Execute the payment
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') { // payment made
/* here you should update your db that the payment was succesful */
return Redirect::to('/this-is-what-you-bought')
->with(['success' => 'Payment success']);
}
return Redirect::to('/')
->with(['error' => 'Payment failed']);
}
を作成コントローラー
$paypal_conf = config('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
のこの
'settings' => array(
/**
* Available option 'sandbox' or 'live'
*/
'mode' => 'sandbox',
/**
* Specify the max request time in seconds
*/
'http.ConnectionTimeOut' => 30,
/**
* Whether want to log to a file
*/
'log.LogEnabled' => true,
/**
* Specify the file that want to write on
*/
'log.FileName' => storage_path() . '/logs/paypal.log',
/**
* Available option 'FINE', 'INFO', 'WARN' or 'ERROR'
*
* Logging is most verbose in the 'FINE' level and decreases as you
* proceed towards ERROR
*/
'log.LogLevel' => 'FINE'
)
コンストラクタのようにする必要があります - 私が持っていました私をきれいにするそれを単純化するために少しコードを書いてください。
'Session :: put( 'paypal_payment_id'、$ payment-> getId());'の前に 'dd($ payment-> getId());'を実行し、その応答を確認してください。 – Abbasi
もう一つは、すべてのデータをpaypalに提供することです。そうでなければ、同じ例外がスローされます。 – Abbasi
こんにちはムハンマドは返事をありがとう。私はPayPalHttpConnection.phpの176: https://api.sandbox.paypal.com/v1/payments/paymentにアクセスすると、HTTP応答コード400が表示されます。 。私はpaypalにすべてのデータを提供しているかどうかを確認する方法を確認することができます。 –