php - 如何使用 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,以便我在该产品下创建一个活动计划吗???
解决方案
推荐阅读
- python - 解压特定目录中的特定文件并解决任何错误情况?
- python - 如何获取除最后 n 个可迭代值之外的所有值
- python - 出现错误:JSONDecodeError:预期值:第 2 行第 1 列(字符 1)
- mysql - 如何获取过敏原数量最多的成分的成分名称?
- android - 删除不需要的十进制“.0”
- mysql - Mule3 在一次查询中将数据插入到 2 个表中
- php - 数据表 Laravel 中不是唯一的表别名
- c# - 使用 DeepEquals 忽略列表类型的属性
- javascript - 允许跨域访问窗口对象到父 iframe (w/o postMessage)
- javascript - JavaScript FloodFIll 慢