Reputation: 11
I am a newbie. I have a saas project where I have used srmklive paypal package and it has the following code to create a new order. But when I click on the button, it shows an Undefined Array key "links" error. How to fix it so that on clicking the button, it redirects to the paypal payment page.
<--------
public function onBoard(Request $request): JsonResponse
{
$plan = Plan::with('currency')->findOrFail($request->planId);
if ($plan->currency->currency_code != null && ! in_array(strtoupper($plan->currency->currency_code),
getPayPalSupportedCurrencies())) {
return $this->sendError(__('messages.placeholder.this_currency_is_not_supported'));
}
$data = $this->subscriptionRepository->manageSubscription($request->all());
if (! isset($data['plan'])) { // 0 amount plan or try to switch the plan if it is in trial mode
// returning from here if the plan is free.
if (isset($data['status']) && $data['status'] == true) {
return $this->sendSuccess($data['subscriptionPlan']->name.' '.__('messages.subscription_pricing_plans.has_been_subscribed'));
} else {
if (isset($data['status']) && $data['status'] == false) {
return $this->sendError(__('messages.placeholder.cannot_switch_to_zero'));
}
}
}
$subscriptionsPricingPlan = $data['plan'];
$subscription = $data['subscription'];
$mode = getSelectedPaymentGateway('paypal_mode');
$clientId = getSelectedPaymentGateway('paypal_client_id');
$clientSecret = getSelectedPaymentGateway('paypal_secret');
config([
'paypal.mode' => $mode,
'paypal.sandbox.client_id' => $clientId,
'paypal.sandbox.client_secret' => $clientSecret,
'paypal.live.client_id' => $clientId,
'paypal.live.client_secret' => $clientSecret,
]);
$provider = new PayPalClient();
$provider->getAccessToken();
$data = [
'intent' => 'CAPTURE',
'purchase_units' => [
[
'reference_id' => $subscription->id,
'amount' => [
'value' => $data['amountToPay'],
'currency_code' => $subscription->plan->currency->currency_code,
],
],
],
'application_context' => [
'cancel_url' => route('paypal.failed'),
'return_url' => route('paypal.success'),
],
];
$order = $provider->createOrder($data);
return response()->json(['link' => $order['links'][1]['href'], 'status' => 200]);
}
------->
I am a newbie and tried changing it to paypal-link but not working.
Upvotes: 1
Views: 108