douzhiji2020 2015-09-05 15:51
浏览 34

php标题重定向不

I have copied a php routine from my test file where it worked great when referencing it directly. Now I have merged it to the saving to a database and making a post call from index.php

The part where it should take me to paypal. Doesn't do anything, I am pretty stumped in where to look.

I can copy the url and paste it into a browser no problem.

I am sure the problem lies in the fact I am calling this through 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}");


?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题