简体   繁体   中英

Paypal Billing Agreement Invalid Plan Id PHP

I have been trying to execute a subscription plan. I have hit a roadblock in the form of the billing agreement. I keep getting the following error when trying to create the agreement.

{"name":"VALIDATION_ERROR","details":[{"field":"plan","issue":"Invalid Fields passed in plan. Pass only a valid plan-id."}],"message":"Invalid request. See details.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR"}

I am unsure where the issue lies, trying to force the agreement's set plan to output the id itself also causes a JSON error and does nothing productive. If you need more info feel free to ask.

$createdPlan = $startPlan->create($paypal);

$patch = new Patch();
$value = new PayPalModel('{
    "state":"ACTIVE"
}');
$patch->setOp('replace')
    ->setPath('/')
    ->setValue($value);
$patchRequest = new PatchRequest();
$patchRequest->addPatch($patch);
$createdPlan->update($patchRequest, $paypal);
$plan = Plan::get($createdPlan->getId(), $paypal);


$agreement = new Agreement();
$agreement->setName($product . ' Agreement')
    ->setDescription('Recurring Payment')
    ->setStartDate(date(c, time()+4));

$agreement->setPlan($plan);

$payer = new Payer();
$payer->setPaymentMethod('paypal');

$agreement->setPayer($payer);
$agreement->create($paypal);

I was able to fix this by creating a new plan object and only setting the id to the actual plan like so.

$jsonplan = new Plan();
$jsonplan->setId($createdPlan->getId());
$agreement->setPlan($jsonplan);

$createdPlan是您需要在$agreement类中传递的计划变量

$agreement->setPlan($createdPlan);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM