I am trying to build a simple payment processor using PayPal to sell pay-per-view tickets for an boxing company I work with. When I ran the PHP code below in a browser, I saw the HTTP Error 505 - This page isn't working.
I removed segments of the coded piece by piece and ran it again until I found that one line in particular was causing the issue.
The line that says $itemList->setItems([$item]);
is causing the issue and I have no idea why. Any help would be amazing.
<?php
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;
require $_SERVER['DOCUMENT_ROOT'] . '/process/ppv_start.php';
$product = 'FILL_WITH_BKB';
$price = 5;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($product)
->setCurrency('GBP')
->setQuantity(1)
->setPrice($price);
$itemList = new ItemList();
$itemList->setItems([$item]);
$amount = new Amount();
$amount->setCurrency('GBP')
->setTotal($price);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('PPV Purchase')
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(SITE_URL . 'process/ppv_pay.php?success=true')
->setCancelUrl(SITE_URL . 'process/ppv_pay.php?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->redirectUrls($redirectUrls)
->setTransactions([$transaction]);
?>