私のエラーの回答を探していましたが、まだ運がよかったので、私を助けてくれる人に願っています。Laravel 5.2 Paypal SDK REST API SDKレスポンスコード403
私は2つの異なるAPIコンテキストを持つ2つのPayPal SDK REST API SDK、2つのPaypalアカウントを持つウェブサイトを持っています。ユーザーが支払いを確認すると、私のwebisteにリダイレクトされませんが、このエラーが発生しました。
PayPalConnectionException in PayPalHttpConnection.php line 183:
Got Http response code 403 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAY-21W53712D7067391CLA35ZEA/execute.
は、だからここ
// for local
Route::post('payment', array(
'as' => 'payment',
'uses' => '[email protected]',
));
// this is after make the payment, PayPal redirect back to your site
Route::get('payment/status', array(
'as' => 'payment.status',
'uses' => '[email protected]',
));
//for international
Route::post('international', array(
'as' => 'payment',
'uses' => '[email protected]',
));
Route::get('international/status', array(
'as' => 'payment.status',
'uses' => '[email protected]',
));
マイIndexController.php私route.phpある
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\ExecutePayment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
class IndexController extends Controller
{
private $_api_context;
public function __construct()
{
// setup PayPal api context
$this->_api_context = new ApiContext(
new OAuthTokenCredential(
'....',
'....'
)
);
$this->_api_context->setConfig(['mode' => 'sandbox']);
}
// local paypal
public function postPayment()
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$price = Input::get('value');
if($price == 'starter'){
$price = 465;
$item_1 = new Item();
$item_1->setName('STARTER PLAN') // item name
->setCurrency('USD')
->setQuantity(1)
->setPrice($price); // unit price
}
elseif($price == 'silver'){
$price = 700;
$item_1 = new Item();
$item_1->setName('SILVER PLAN') // item name
->setCurrency('USD')
->setQuantity(1)
->setPrice($price); // unit price
}
else{
$price = 1300;
$item_1 = new Item();
$item_1->setName('GOLD PLAN') // item name
->setCurrency('USD')
->setQuantity(1)
->setPrice($price); // unit price
}
// add item to list
$item_list = new ItemList();
// $item_list->setItems(array($item_1, $item_2, $item_3));
$item_list->setItems(array($item_1));
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal($price);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(\URL::route('payment.status'))
->setCancelUrl(\URL::route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $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');
}
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
\Session::put('paypal_payment_id', $payment->getId());
\Session::put('value_price', $price);
if(isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
}
return redirect('paypal');
}
public function getPaymentStatus()
{
// Get the payment ID before session clear
$payment_id = \Session::get('paypal_payment_id');
// clear the session payment ID
\Session::forget('paypal_payment_id');
if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
return redirect('failed');
}
$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(Input::get('PayerID'));
//Execute the payment
$result = $payment->execute($execution, $this->_api_context);
//echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later
if ($result->getState() == 'approved') { // payment made
return redirect('success');
}else{
return redirect('failed');
}
}
}
マイIntIndexController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\ExecutePayment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
class IntIndexController extends Controller
{
private $_api_context;
public function __construct()
{
// setup PayPal api context
$this->_api_context = new ApiContext(
new OAuthTokenCredential(
'...',
'...'
)
);
$this->_api_context->setConfig(['mode' => 'sandbox']);
}
// local paypal
public function postPayment()
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$price = Input::get('value');
if($price == 'starter'){
$price = 465;
$item_1 = new Item();
$item_1->setName('STARTER PLAN') // item name
->setCurrency('USD')
->setQuantity(1)
->setPrice($price); // unit price
}
elseif($price == 'silver'){
$price = 700;
$item_1 = new Item();
$item_1->setName('SILVER PLAN') // item name
->setCurrency('USD')
->setQuantity(1)
->setPrice($price); // unit price
}
else{
$price = 1300;
$item_1 = new Item();
$item_1->setName('GOLD PLAN') // item name
->setCurrency('USD')
->setQuantity(1)
->setPrice($price); // unit price
}
// add item to list
$item_list = new ItemList();
// $item_list->setItems(array($item_1, $item_2, $item_3));
$item_list->setItems(array($item_1));
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal($price);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(\URL::route('payment.status'))
->setCancelUrl(\URL::route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $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');
}
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
\Session::put('paypal_payment_id', $payment->getId());
\Session::put('value_price', $price);
if(isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
}
return redirect('paypal');
}
public function getPaymentStatus()
{
// Get the payment ID before session clear
$payment_id = \Session::get('paypal_payment_id');
// clear the session payment ID
\Session::forget('paypal_payment_id');
if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
return redirect('failed');
}
$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(Input::get('PayerID'));
//Execute the payment
$result = $payment->execute($execution, $this->_api_context);
//echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later
if ($result->getState() == 'approved') { // payment made
return redirect('success');
}else{
return redirect('failed');
}
}
}
マイpaypal.phpビュー
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4" style="margin-top: 20px;">
{!! Form::open(array('url'=>'payment','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('value', 'starter') }}
<div class="row" style="background-color: #423E3D; margin-left: 0px; margin-right: 0px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="color : #000000;">
<h2 style="color: #FFFFFF; text-align:center;">STARTER PLAN</h2>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="color : #000000;">
<h2 style="color: #FFFFFF; text-align:center; margin-top:0px;">USD 465</h2>
</div>
<center>
<div class="col-md-12">
<div style="margin-top:15px;" class="form-group">
{!! Form::submit('Buy Now',
array('class'=>'btn btn-primary')) !!}
</div>
</div>
</center>
</div>
{!! Form::close() !!}
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4" style="margin-top: 20px;">
{!! Form::open(array('url'=>'payment','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('value', 'silver') }}
<div class="row" style="background-color: #423E3D; margin-left: 0px; margin-right: 0px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="color : #000000;">
<h2 style="color: #FFFFFF; text-align:center;">SILVER PLAN</h2>
</div>
<center>
<div style="margin-top:15px;" class="col-md-12">
<div class="form-group">
{!! Form::submit('Buy Now',
array('class'=>'btn btn-primary')) !!}
</div>
</div>
</center>
</div>
{!! Form::close() !!}
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4" style="margin-top: 20px;">
{!! Form::open(array('url'=>'payment','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('value', 'gold') }}
<div class="row" style="background-color: #423E3D; margin-left: 0px; margin-right: 0px;">
<center>
<div style="margin-top:15px;" class="col-md-12">
<div class="form-group">
{!! Form::submit('Buy Now',
array('class'=>'btn btn-primary')) !!}
</div>
</div>
</center>
</div>
{!! Form::close() !!}
</div>
その後、私のintpaypal.phpビュー
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4" style="margin-top: 20px;">
{!! Form::open(array('url'=>'international','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('value', 'starter') }}
<div class="row" style="background-color: #423E3D; margin-left: 0px; margin-right: 0px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="color : #000000;">
<h2 style="color: #FFFFFF; text-align:center;">STARTER PLAN</h2>
</div>
<center>
<div class="col-md-12">
<div style="margin-top:15px;" class="form-group">
{!! Form::submit('Buy Now',
array('class'=>'btn btn-primary')) !!}
</div>
</div>
</center>
</div>
{!! Form::close() !!}
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4" style="margin-top: 20px;">
{!! Form::open(array('url'=>'international','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('value', 'silver') }}
<div class="row" style="background-color: #423E3D; margin-left: 0px; margin-right: 0px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="color : #000000;">
<h2 style="color: #FFFFFF; text-align:center;">SILVER PLAN</h2>
</div>
<center>
<div class="col-md-12">
<div style="margin-top:15px;" class="form-group">
{!! Form::submit('Buy Now',
array('class'=>'btn btn-primary')) !!}
</div>
</div>
</center>
</div>
{!! Form::close() !!}
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4" style="margin-top: 20px;">
{!! Form::open(array('url'=>'international','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('value', 'gold') }}
<div class="row" style="background-color: #423E3D; margin-left: 0px; margin-right: 0px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="color : #000000;">
<h2 style="color: #FFFFFF; text-align:center;">GOLD PLAN</h2>
</div>
<center>
<div class="col-md-12">
<div style="margin-top:15px;" class="form-group">
{!! Form::submit('Buy Now',
array('class'=>'btn btn-primary')) !!}
</div>
</div>
</center>
</div>
{!! Form::close() !!}
</div>
私はここでの唯一の問題はroute.phpであるが、私はそれを修正する方法を知らない、私の犯人は
Route::get('international/status', array(
'as' => 'payment.status',
'uses' => '[email protected]',
));
だと思います
私はそれを削除しようとすると、ローカルアカウントが動作しますが、国際的なアカウントが動作していないときに私はこれを戻すローカルアカウントが動作していないが、国際的な作業です。
解決方法を知っている人はいますか?手伝って頂けますか。