paypal SDK无法创建新的付款

时间:2017-03-21 09:15:54

标签: php paypal doctrine-orm paypal-sandbox

使用Sandbox.paypal.com,我在我的Xxamp上使用了以下代码并且它可以工作。 我的代码:

$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;

但是当我在我的真实网站(配置好的Https)上使用它时,它不会起作用。 它不会运行$payment->create($apiContext)。 我必须打开Paypal的任何端口吗?由于安全问题,我的网站受到限制。 有人能帮助我吗? 感谢。

0 个答案:

没有答案