0

我正在构建贝宝订阅系统,我正在使用网络挂钩来通知系统订阅创建、活动等。

但是,要求用户必须返回成功 url 并执行站点$agreement->execute($token, $apiContext));才能使其工作。

假设由于某种原因用户永远不会返回返回 url,那么您将永远不会执行付款,用户将永远不会得到他们的订阅。

我环顾了贝宝文档,找不到任何解决方案。

这是我的代码:

订阅.php:

$agreement = new Agreement();
$agreement->setName('Basic Plan')
->setDescription('Some info')
->setStartDate($date);

$plan = new Plan();
$plan->setId('PLAN_ID');

$agreement->setPlan($plan);

// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);

// Add Shipping Address
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')
    ->setCity('Saratoga')
    ->setState('CA')
    ->setPostalCode('95070')
    ->setCountryCode('US');
$agreement->setShippingAddress($shippingAddress);

// ### Create Agreement
try {
    $agreement = $agreement->create($apiContext);
    $agreement->getApprovalLink()
    // method
    $approvalUrl = $agreement->getApprovalLink();
    redirect($approvalUrl);
} catch (Exception $ex) {
    print_r($ex->getData());
}

索引.php

if (isset($_GET['status']) && $_GET['status'] == 'success') {
    $token = $_GET['token'];
    $agreement = new \PayPal\Api\Agreement();
    try {
        // ## Execute Agreement
        // Execute the agreement by passing in the token
        echo "<pre>";
        print_r($agreement->execute($token, $apiContext));
    } catch (Exception $ex) {

        exit(1);
    }
} else {
    echo "User Cancelled the Approval";
}
4

0 回答 0