session_start(); use PayPal\Api\Payer; use PayPal\Api\Item; use PayPal\Api\ItemList; use PayPal\Api\Details; use PayPal\Api\Amount; use PayPal\Api\Transaction; use PayPal\Api\RedirectUrls; use PayPal\Api\Payment; if(isset($_SESSION['cart_list'])&&sizeof($_SESSION['cart_list'])>0){ require 'def_con.php'; require 'paypal.php'; $payer = new Payer(); $payer->setPaymentMethod('paypal'); // print_r($_SESSION['cart_list']); $list = $_SESSION['cart_list']; $invoice = str_real_escape((strtoupper($_SESSION['username']))).'-ODR-QC-'.rand(1111,9999); $_SESSION['invoice'] = $invoice; $items=''; $inc=1; $shipping=0; $tax=0; $ovpx=$shipping; foreach($list as $key => $prod){ $prodn = $prod['prodname']; $count = $prod['count']; $price = $prod['precio']*$count; $ovpx+=$price; // echo $prodn.' => '.$price.'<br>'; $item = new Item(); $item->setName($prodn) ->setCurrency('GHS') ->setQuantity($count) ->setPrice($price); if($inc==sizeof($list)){$c='';}else{$c=',';} $inc++; $items.=$item.$c; } $itemList = new ItemList(); $itemList->setItems([$items]); // print_r($itemList->getItems()); $details = new Details(); $details->setShipping($shipping) ->setSubtotal($ovpx); $amount = new Amount(); $amount->setCurrency('GHS') ->setTotal($ovpx) ->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount) ->setItemList($itemList) ->setDescription('Pay for smth') ->setInvoiceNumber($invoice); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl(SITE_URL.'/pay.php?success=true') ->setCancelUrl(SITE_URL.'/pay.php?success=false'); $payment = new Payment(); $payment->setIntent('sale') ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions([$transaction]); // try { // $payment->create($paypal); // } catch (Exception $e) { // die($e); // } // echo $approvalUrl = $payment->getApprovalLink(); // $transaction->getInvoiceNumber(); }else{ echo 'cart empty'; } // echo $payer->getPaymentMethod();
This is my code, calling the payment class alone gives me 500 error both in sanbox and live, I'm at my wits ends. Please advice. THANK YOU
... View more