首页 > 解决方案 > 如何使用 PayPal-PHP-SDK 设置“product_id”?

问题描述

根据文档,我使用 curl 创建了一个计划,

curl -v -k -X POST https://api.sandbox.paypal.com/v1/billing/plans \
  -H "Accept: application/json" \
  -H "Authorization: Bearer Access-Token" \
  -H "PayPal-Request-Id: PLAN-18062019-001" \  // merchant generated ID, optional and needed for idempotent samples
  -H "Prefer: return=representation" \
  -H "Content-Type: application/json" \
  -d '{
      "product_id": "PROD-6XB24663H4094933M",
      "name": "Basic Plan",
      "description": "Basic plan",
      "billing_cycles": [
  ........................

在我的沙盒帐户中,该产品下的活动计划是创建 计划 现在,我使用 PayPal-PHP-SDK,我想在其中设置product_id,但没有找到方法。我的代码是

$plan = new Plan();
    $plan->setName('plan_10_12_2019')->setDescription('simple description')->setType('INFINITE');

    // Set billing plan definitions
    $paymentDefinition = new PaymentDefinition();
    $paymentDefinition->setName('Regular Payments')
        ->setType('REGULAR')
        ->setFrequency('DAY')
        ->setFrequencyInterval('1')
        // ->setCycles('UNLIMITED')
        ->setAmount(new Currency(array(
        'value' => 3,
        'currency' => 'USD'
    )));

    // Set charge models
    $chargeModel = new ChargeModel();
    $chargeModel->setType('SHIPPING')->setAmount(new Currency(array(
        'value' => 1,
        'currency' => 'USD'
    )));
    $paymentDefinition->setChargeModels(array(
        $chargeModel
    ));

    // Set merchant preferences
    $merchantPreferences = new MerchantPreferences();
    $merchantPreferences->setReturnUrl('http://example.com/how-to-manage-recurring-payments-using-paypal-subscriptions-in-php/index.php?status=success')
        ->setCancelUrl('http://example.com/engagetwo/how-to-manage-recurring-payments-using-paypal-subscriptions-in-php/index.php?status=cancel')
        ->setAutoBillAmount('yes')
        ->setInitialFailAmountAction('CONTINUE')
        ->setMaxFailAttempts('0')
        ->setSetupFee(new Currency(array(
        'value' => 1,
        'currency' => 'USD'
    )));
    $plan->setPaymentDefinitions(array(
        $paymentDefinition
    ));
    $plan->setMerchantPreferences($merchantPreferences);

    try {
        $createdPlan = $plan->create($apiContext);
        var_dump($createdPlan);
    } catch (PayPal\Exception\PayPalConnectionException $ex) {
        echo $ex->getCode();
        echo $ex->getData();
        die('here');
    } catch (Exception $ex) {
        die('there');
    }

你能告诉我如何设置product_id,以便我在该产品下创建一个活动计划吗???

标签: phppaypalpaypal-rest-sdk

解决方案


推荐阅读