مشكلة عدم إتمام عملية الدفع عبر الـ API الخاص بـ Paypal
صادفتني مُشكلة عند العمل على الـ API الخاص بـ Paypal وهي عدم إتمام عملية الدفع عبر الحساب التجريبي للمطورين sandbox وعدم إظهار المُشكلة بشكل تفصيلي ويكتفي الموقع فقط بإظهار التالي:
Sorry, we can’t complete your purchase at this time Please return to the merchant and choose another way to pay.
هذه الرسالة لا توضح سبب المُشكلة بالتحديد لمعالجتها، هل لدى أحد أي معلومة حول الأمر؟
يرجى الدخول لحسابك أو تسجيل حساب لتستطيع إضافة تعليق
حساب جديد
دخول
التعليقات
المُشكلة غير مُتعلقة بالكود على الأغلب، فالاتصال يتم وعند عملية الدفع عبر منصة بايبال تظهر المشكلة وهذا هو الكود المستخدم:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cookie;
use App\Http\Requests;
use App\Tables\Price;
use App\Tables\Tour;
use App\Tables\Order;
use App\Tables\Category;
use App\Tables\Cart;
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\PaymentExecution;
use PayPal\Api\ExecutePayment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
class CheckoutController extends Controller
{
private $apiContext;
private $paypal_ClientId;
private $paypal_ClientSecret;
public function __construct()
{
$this->middleware('login');
$this->paypal_ClientId = config('paypal_payment.Account.ClientId');
$this->paypal_ClientSecret = config('paypal_payment.Account.ClientSecret');
$this->apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$this->paypal_ClientId,
$this->paypal_ClientSecret
)
);
}
public function index(Request $request)
{
$data['title'] = 'Checkout';
$amount = 0;
foreach(Cart::where('user_id', auth()->user()->id)->get() as $row){
if(strtotime($row->order->date) < strtotime(date('Y-m-d 00:00:00', time()))){
$row->delete();
}
if(!isset($row->order->price)){
$row->delete();
}
$tour_date = '2000'.substr($row->order->date, 4);
if(!(strtotime($tour_date) >= strtotime($row->order->price->availability->from_date)
&& strtotime($tour_date) <= strtotime($row->order->price->availability->to_date))){
$row->delete();
}
$total_amount = ceil($row->order->adult/$row->order->price->room_range)*$row->order->price->room_range*$row->order->price->adult;
$total_amount += $row->order->child*$row->order->price->child;
$total_amount += $row->order->infant*$row->order->price->infant;
$total_amount += $row->order->extra_fee;
Order::where('id', $row->order_id)->update(['total_amount' => $total_amount]);
$amount += $total_amount;
}
$data['total_amount'] = $amount;
return view('checkout', $data);
}
public function create()
{
//
}
public function store(Request $request)
{
$items = [];
$checkout_amount = 0;
foreach(Cart::where('user_id', auth()->user()->id)->get() as $row){
if(strtotime($row->order->date) < strtotime(date('Y-m-d 00:00:00', time()))){
$row->delete();
continue;
}
if(!isset($row->order->price)){
$row->delete();
continue;
}
$tour_date = '2000'.substr($row->order->date, 4);
if(!(strtotime($tour_date) >= strtotime($row->order->price->availability->from_date)
&& strtotime($tour_date) <= strtotime($row->order->price->availability->to_date))){
$row->delete();
continue;
}
$total_amount = ceil($row->order->adult/$row->order->price->room_range)*$row->order->price->room_range*$row->order->price->adult;
$total_amount += $row->order->child*$row->order->price->child;
$total_amount += $row->order->infant*$row->order->price->infant;
$total_amount += $row->order->extra_fee;
Order::where('id', $row->order_id)->update(['total_amount' => $total_amount]);
$checkout_amount += $total_amount;
$tempItem = new Item();
$tempItem->setName($row->order->tour->name)
->setCurrency('USD')
->setQuantity(1)
->setSku($row->order->id)
->setPrice($total_amount);
$items[] = $tempItem;
}
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$itemList = new ItemList();
$itemList->setItems($items);
$details = new Details();
$details->setShipping(0)
->setTax(0)
->setSubtotal($checkout_amount);
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal($checkout_amount)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
$baseUrl = url('/').'/'.$request->segment(1).'/checkout';
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/success")
->setCancelUrl("$baseUrl/failed");
$payment = new Payment();
$payment->setIntent("order")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$payment->create($this->apiContext);
} catch (Exception $ex) {
return "Created Payment Using PayPal. Please visit the URL to Approve.";
}
$approvalUrl = $payment->getApprovalLink();
return redirect($payment->getApprovalLink());
}
public function success(Request $request)
{
return $request->PayerID;
$payment = Payment::get($request->paymentId, $this->apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($request->PayerID);
$transaction = new Transaction();
$amount = new Amount();
$details = new Details();
}
public function failed(Request $request)
{
//
}
public function show($id)
{
//
}
public function edit($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
}
وهذا تصوير للمشكلة من الموقع الذي أعمل عليه