为什么贝宝沙箱帐户金额没有更新?

时间:2019-04-09 14:35:45

标签: php laravel paypal

我的代码成功处理了向Paypal的付款,然后返回到成功页面,购买企业帐户的金额未更新。

我正在laravel中尝试使用paypal sdk,下面是我正在使用的脚本,但是在正面,它成功地进入了paypal页面,我使用买方帐户登录,然后付款,然后再返回paypal成功页面。但是在卖方帐户中,该金额没有显示,也没有从买方帐户中扣除。

public function createpayment(){
        $apiContext = new \PayPal\Rest\ApiContext(
            new \PayPal\Auth\OAuthTokenCredential(
                'Ac.................asd',     // ClientID
                'Ac.................sdf'      // ClientSecret
            )
        );
        $payer = new Payer();
        $payer->setPaymentMethod("paypal");
        $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));

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

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

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


        /* $baseUrl = getBaseUrl(); */
        $redirectUrls = new RedirectUrls();
        $redirectUrls->setReturnUrl(route('success'))
        ->setCancelUrl(route('cancel'));


        $payment = new Payment();
        $payment->setIntent("sale")
            ->setPayer($payer)
            ->setRedirectUrls($redirectUrls)
            ->setTransactions(array($transaction));
         /* $payment->create($apiContext);
        return  redirect($payment->getApprovalLink()); */

        try {
            $payment->create($apiContext);
        } catch (Exception $ex) {
            ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
            exit(1);

        }
        $approvalUrl = $payment->getApprovalLink();

        echo $payment, $approvalUrl;
    }

    public function success(){
        $apiContext = new \PayPal\Rest\ApiContext(
            new \PayPal\Auth\OAuthTokenCredential(
                'Ac.................asd',     // ClientID
                'Ac.................sdf'      // ClientSecret     // ClientSecret
            )
        );

        return request();
    }

我希望此代码将资金从买方转移到卖方帐户,然后返回带有响应的成功页面。有人可以请我介绍一下我想谢谢的事吗?

1 个答案:

答案 0 :(得分:0)

在成功页面上,您需要执行付款才能真正完成交易。

https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/ExecutePayment.php