dongxianghui3709 2018-11-20 15:09
浏览 11

PayPal Plus API和PHP:付款不可能

I created a REST Api for PayPal Plus. Somehow payments are not being processed. After my order I successfully get directed to the paypal page where I can see an overview of my order. However, when I click "Paying" I DO NOT get forwarded to the paypal confirmation page, but get redirected to the return URL of my shop.

My PHP code:

$money = '0.01';
$mode = 'live';
$cientID = '123456';
$clientSecret = '123456';

$apiContext = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        $cientID,     
        $clientSecret      
    )
);
$apiContext->setConfig(
    array(
        'mode' => $mode
    )
);

$item1 = new \PayPal\Api\Item();
$item1->setName('My order')
    ->setCurrency('EUR')
    ->setQuantity(1)
    ->setPrice($money);

$itemList = new \PayPal\Api\ItemList();
$itemList->setItems(array($item1));

$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');

$amount = new \PayPal\Api\Amount();
$amount->setCurrency('EUR');
$amount->setTotal($money);

$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemList);
$transaction->setInvoiceNumber(uniqid());
$transaction->setDescription('My order');

    $host = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'];

$redirectUrl = new \PayPal\Api\RedirectUrls();
$redirectUrl->setReturnUrl($host . '/page.php');
$redirectUrl->setCancelUrl($host . '/page.php');

$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrl);
$payment->setTransactions(array($transaction));

$payment = $payment->create($apiContext);

$approvalUrl = $payment->getApprovalLink();

My JS:

var ppp = PAYPAL.apps.PPP({
   "approvalUrl": "<?=$approvalUrl?>",
   "placeholder": "ppplus",
   "mode": "live",
   "country": "DE"
});

Can anyone see a problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭