我正在使用Laravel 5.5上的Paypal会员付款 我正在使用以下链接将Paypal集成到Laravel中
https://devdojo.com/tutorials/using-paypal-in-your-laravel-app
我要在这里添加功能
public function paypalRedirect($planID){
$response = array();
$this->plan_id = $planID;
// Create new agreement
$agreement = new Agreement();
$agreement->setName('Vechflow Monthly Subscription Agreement')
->setDescription('Basic Subscription')
->setStartDate(\Carbon\Carbon::now()->addMinutes(5)->toIso8601String());
// Set plan id
$plan = new Plan();
$plan->setId($this->plan_id);
$agreement->setPlan($plan);
// Add payer type
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
try {
// Create agreement
$agreement = $agreement->create($this->apiContext);
// Extract approval URL to redirect user
$approvalUrl = $agreement->getApprovalLink();
$response['status_code'] = 200;
$response['url'] = $approvalUrl;
return $response;
} catch (PayPal\Exception\PayPalConnectionException $ex) {
$response['status_code'] = 500;
$response['error'] = $ex;
return $response;
} catch (Exception $ex) {
$response['status_code'] = 500;
$response['error'] = $ex;
return $response;
}
}
直到这里它运行良好并正确返回协议,但是在此之后,当我们执行协议时,它会引发一个异常,该异常在调试后显示以下错误
{"name":"TEMPLATE_ID_INVALID","details":[{"field":"template id is invalid","issue":"Incorrect Plan Id."}],"message":"","information_link":"https://developer.paypal.com/docs/api/payments.billing-agreements#errors","debug_id":"4afbcfb5dd18a"}