Я скопировал подпрограмму php из моего тестового файла, где она отлично работала при прямой ссылке на нее. Теперь я объединил его с сохранением в базе данных и выполнением пост-звонка из index.php
Та часть, в которой я должен принять PayPal. Ничего не делает, я довольно туп, где искать.
Я могу скопировать URL и вставить его в браузер без проблем.
Я уверен, что проблема заключается в том, что я называю это через AJAX
$.ajax({
url: 'php/processorder.php',
data: {my_json_data: json}, // tableObject},
type: 'POST',
async: false,
dataType: 'json',
cache:false
});
<?PHP
//this is the layout of the json object
//Title:First Name:Surname:Group Name this will need amending as the json object builds
//checkout.php to be incorparated into this file
//namespaces here
//everything below here is from checkout.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;
//requirements here
require("dbsettings.php");
require ("/../app/start.php");
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//gets a new number
$sql = "SELECT max(`applicationNumber`) + 1 as newNum FROM applicationheader;";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)) {
$NewOrder = $row["newNum"];
}
$_Reference= $_POST["my_json_data"] ;
// Loop through Array
$someArray = json_decode($_Reference, true);
$I = 1 ;
$lineNo =1 ;
foreach ($someArray as $key => $value) {
//fist pass store header info as well
if ($I == 1) {
$sql = "INSERT into applicationheader (applicationnumber,GroupName,applicationDate)
Values (" . $NewOrder . ",'" . $value["Group Name"] . "',curdate())";
mysqli_query($conn,$sql);
}
//store detail
//$mval holds the value of price
$mVal = 5;
if ($value["Age Bracket"] === 'A'){
$mVal = 10;
}
$sql = "INSERT into applicationdetail (
applicationnumber,lineNo,title,firstname,surname,address1,address2,city,county,postcode,paid,`size`,price,gender,agebracket,MobileNo)
values(" . $NewOrder . " , " . $lineNo . "," . "'" . $value["Title"] . "','" . $value["First name"] . "','" . $value["Surname"] . "','" . $value["Address1"] . "','" . $value["Address2"] . "','" . $value["City"] . "','" . $value["County"] . "','" . $value["Postcode"] . "','" . "N" . "','". $value["Size"] . "'," . $mVal . ",'" . $value["Gender"] . "','" . $value["Age Bracket"] . "','" . $value["Mobile"] . "')";
mysqli_query($conn,$sql);
$I ++;//control adding to the heder
$lineNo ++;//control line no
}
//close the database connection
mysqli_close($conn);
$pTotal = 20.00;
$shipping = 1.00;
$Total = $pTotal + $shipping ;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName("tieThisToSomething")
->setCurrency('GBP')
->setQuantity(1)
->setPrice($pTotal);
$itemList = new ItemList();
$itemList->setItems(array($item)); //I have removed square brackets from here []
$details = new Details();
$details->setShipping($shipping)
->setSubtotal($pTotal);
$amount = new Amount();
$amount->setCurrency('GBP')
->setTotal($Total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('Pay for all your santa fun')
->setInvoiceNumber(uniqid());//perhaps tie this to order number?
$redirectUrls = new RedirectUrls();
$redirectUrls->setCancelUrl(SITE_URL . '/php/pay.php?success=false')
->setReturnUrl(SITE_URL . '/php/php.php?success=true');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction)); //should [] be needed here?
//try {
// $payment->create($paypal);
//} catch (Exception $e) {
// die($e);
//}
try {
$payment->create($paypal);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
// echo $ex->getCode(); // Prints the Error Code
// echo $ex->getData(); // Prints the detailed error message
die($ex);
} catch (Exception $ex) {
die($ex);
}
$approvalUrl = $payment->getApprovalLink();
//echo $approvalUrl;
header("Location: {$approvalUrl}");
?>
Задача ещё не решена.
Других решений пока нет …