Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 贝宝SDK可以';不要创建新的付款_Php_Paypal_Doctrine Orm_Paypal Sandbox - Fatal编程技术网

Php 贝宝SDK可以';不要创建新的付款

Php 贝宝SDK可以';不要创建新的付款,php,paypal,doctrine-orm,paypal-sandbox,Php,Paypal,Doctrine Orm,Paypal Sandbox,在Sandbox.paypal.com上,我在我的Xxamp上使用了下面的代码,它工作正常。 我的代码: 但当我在我的真实网站(配置Https)上使用它时,它将无法工作。 它不会运行$payment->create($apiContext)。 我必须为贝宝打开任何端口吗?由于安全原因,我的网站受到限制。 有人能帮我吗? 谢谢 $apiContext = new ApiContext(new OAuthTokenCredential(xxxxxxxxxxxx', 'xxxxxxxxxxxxx'))

在Sandbox.paypal.com上,我在我的Xxamp上使用了下面的代码,它工作正常。 我的代码:

但当我在我的真实网站(配置Https)上使用它时,它将无法工作。 它不会运行
$payment->create($apiContext)
。 我必须为贝宝打开任何端口吗?由于安全原因,我的网站受到限制。 有人能帮我吗? 谢谢

$apiContext = new ApiContext(new OAuthTokenCredential(xxxxxxxxxxxx', 'xxxxxxxxxxxxx'));
// Create new payer and method
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$payer_info = new PayerInfo();
$payer_info->setEmail('harujiburke@gmail.com');
$payer->setPayerInfo($payer_info);

$details = new Details();
$details->setShipping(1.2)
    ->setTax(1.3)
    ->setSubtotal(17.50);

$amount = new Amount();
$amount->setCurrency("USD")
    ->setTotal(20)
    ->setDetails($details);


//list Items
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
    ->setCurrency('USD')
    ->setQuantity(1)
    ->setSku("123123") // Similar to `item_number` in Classic API
    ->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setSku("321321") // Similar to `item_number` in Classic API
->setPrice(2);

$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://check.com/process.php")
    ->setCancelUrl("http://check.com/cancel.php");

$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));

$request = clone $payment;

try {   
    $payment->create($apiContext);
} catch (Exception $ex) {

    exit(1);
}
foreach($payment->getLinks() as $link){
    if($link->getRel() == 'approval_url'){
        $redirect_url = $link->getHref();   
        break;
    }
}
$_SESSION['paypal_payment_id'] = $payment->getId();

// Do the redirection
if(isset($redirect_url)) {
    header('location: '. $redirect_url);
    exit();
}

return $payment;