paypal沙盒没有执行付款

时间:2017-11-07 10:21:00

标签: php paypal-sandbox

这几天,我使用的是php sdk。它以前工作,但现在他们没有执行我的订阅和收费。每当付款时我都会收到PAYMENT.SALE.PENDING事件。 请帮忙,这让我发疯了。

我收到付款状态"已批准"但我没有收到付款。销售。已付款' webhook,我不知道出了什么问题。

这是我的代码:

创建:

public function doPayPalCharge($returnUrl, $cancelUrl)
{
    $apiContext = $this->apiContext;
    $money      = $this->getAmount();
    $customData = $this->getMetadata();

    // Create new payer and method
    $payer = new Payer();
    $payer->setPaymentMethod("paypal");

    // Set redirect urls
    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl($returnUrl)
                 ->setCancelUrl($cancelUrl);

    // Set payment amount
    $amount = new Amount();
    $amount->setCurrency("USD")
           ->setTotal($money);

    // Set transaction object
    $transaction = new Transaction();
    $transaction->setAmount($amount)
        //can not use json_encode here, because can not decode data from web hook
                ->setCustom(base64_encode(serialize($customData->all)))
                ->setDescription("Payment description");

    // Create the full payment object
    $payment = new Payment();
    $payment->setIntent('sale')
            ->setPayer($payer)
            ->setRedirectUrls($redirectUrls)
            ->setTransactions([$transaction]);

    $request = clone $payment;

    // Create payment with valid API context
    try
    {
        $payment->create($apiContext);
        $token = $this->getPayPalTokenFromUrl($payment->getApprovalLink());

    } catch (PayPalConnectionException $e)
    {
        self::payPalLog($e, '[PayPalConnectionException]', (array)$request);
    } catch (\Exception $e)
    {
        self::payPalLog($e, '[Create Payment Failed]', (array)$request);
    }

    return isset($token) ? $token : '';
}

执行:

public function confirmPayPalCharge($payment_id, $payer_id)
{
    $apiContext = $this->apiContext;
    // Get payment object by passing paymentId
    $payment = Payment::get($payment_id, $apiContext);

    // Execute payment with payer id
    $execution = new PaymentExecution();
    $execution->setPayerId($payer_id);

    try
    {
        // Execute payment
        $payment = $payment->execute($execution, $apiContext);

    } catch (PayPalConnectionException $e)
    {
        self::payPalLog($e, '[PayPalConnectionException]');
    } catch (\Exception $e)
    {
        self::payPalLog($e);
    }

    return isset($payment) ? $payment : null;
}

0 个答案:

没有答案