laravel-paystack icon indicating copy to clipboard operation
laravel-paystack copied to clipboard

return Paystack::getAuthorizationUrl($data)->redirectNow();

Open felixkaleke opened this issue 1 year ago • 5 comments

This is not redirecting as its supposed to redirect , what might be the issue?, I have my secret and public key in my files correctly

felixkaleke avatar Apr 03 '23 13:04 felixkaleke

same here. I have everything set up and the function isn't redirecting my website to the paystack website. Can someone help, if this problem has already been solved?

Chuby11 avatar Apr 30 '23 03:04 Chuby11

This is not redirecting as its supposed to redirect , what might be the issue?, I have my secret and public key in my files correctly

Still working here. Next time always remember to share your code

goodmuyis avatar May 12 '23 20:05 goodmuyis

Hello, Am having problem redirecting to paystack payment gateway. Am having this error -> cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for /transaction/initialize

Here is the code below.

public function paystackPayment(Request $request) { try { $order = $this->placeOrder('paystack'); $order->paystack_reference_number = $request->reference; $order->save(); return Paystack::getAuthorizationUrl()->redirectNow(); dd(); } catch (\Exception $e) { $this->showToastrMessage('error', 'The paystack token has expired. Please refresh the page and try again.'); return redirect()->back(); } }

private function placeOrder($payment_method) { $carts = CartManagement::whereUserId(@Auth::user()->id)->get(); $order = new Order(); $order->user_id = Auth::user()->id; $order->order_number = rand(100000, 999999); $order->sub_total = $carts->sum('price'); $order->discount = $carts->sum('discount'); $order->platform_charge = get_platform_charge($carts->sum('price')); $order->current_currency = get_currency_code(); $order->grand_total = $order->sub_total + $order->platform_charge; $order->payment_method = $payment_method;

    $payment_currency = '';
    $conversion_rate = '';

    if ($payment_method == 'paypal') {
        $payment_currency = get_option('paypal_currency');
        $conversion_rate = get_option('paypal_conversion_rate') ? get_option('paypal_conversion_rate') : 0;
    } elseif ($payment_method == 'stripe') {
        $payment_currency = get_option('stripe_currency');
        $conversion_rate = get_option('stripe_conversion_rate') ? get_option('stripe_conversion_rate') : 0;
    } elseif ($payment_method == 'bank') {
        $payment_currency = get_option('bank_currency');
        $conversion_rate = get_option('bank_conversion_rate') ? get_option('bank_conversion_rate') : 0;
    } elseif ($payment_method == 'mollie') {
        $payment_currency = get_option('mollie_currency');
        $conversion_rate = get_option('mollie_conversion_rate') ? get_option('mollie_conversion_rate') : 0;
    } elseif ($payment_method == 'instamojo') {
        $payment_currency = get_option('im_currency');
        $conversion_rate = get_option('im_conversion_rate') ? get_option('im_conversion_rate') : 0;
    } elseif ($payment_method == 'paystack') {
        $payment_currency = get_option('paystack_currency');
        $conversion_rate = get_option('paystack_conversion_rate') ? get_option('paystack_conversion_rate') : 0;
    }

    $order->payment_currency = $payment_currency;
    $order->conversion_rate = $conversion_rate;
    if ($conversion_rate) {
        $order->grand_total_with_conversation_rate = ($order->sub_total + $order->platform_charge) * $conversion_rate;
    }

    $order->save();

    foreach ($carts as $cart) {
        if ($cart->course_id) {
            $order_item = new Order_item();
            $order_item->order_id = $order->id;
            $order_item->user_id = Auth::id();
            $order_item->course_id = $cart->course_id;
            $order_item->owner_user_id = $cart->course ? $cart->course->user_id : null;
            $order_item->unit_price = $cart->price;
            if (get_option('sell_commission')) {
                $order_item->admin_commission = admin_sell_commission($cart->price);
                $order_item->owner_balance = $cart->price - admin_sell_commission($cart->price);
                $order_item->sell_commission = get_option('sell_commission');
            } else {
                $order_item->owner_balance = $cart->price;
            }

            $order_item->save();
        } elseif ($cart->bundle_id) {
            /*
             If bundle course add. we only calculate all things in order_items 1 time.
                and all bundle courses save in order_items table.
             If any course of bundle already purchased with paid. Those course won't be added again.
             */
            $order_item = new Order_item();
            $order_item->order_id = $order->id;
            $order_item->user_id = Auth::user()->id;
            $order_item->bundle_id = $cart->bundle_id;
            $order_item->owner_user_id = $cart->bundle ? $cart->bundle->user_id : null;
            $order_item->unit_price = $cart->price;
            if (get_option('sell_commission')) {
                $order_item->admin_commission = admin_sell_commission($cart->price);
                $order_item->owner_balance = $cart->price - admin_sell_commission($cart->price);
                $order_item->sell_commission = get_option('sell_commission');
            } else {
                $order_item->owner_balance = $cart->price;
            }
            $order_item->type = 3; //bundle course
            $order_item->save();

            /*
             * All bundle course added but not calculate balance, commission etc
             */
            foreach ($cart->bundle_course_ids ?? [] as $bundle_course_id) {
                /*
                need to add bundle course in order list
                Old paid course check with bundle course
                */

                $paidOrderIds = Order::where('user_id', auth()->id())->where('payment_status', 'paid')->pluck('id')->toArray();
                $freeOrderIds = Order::where('user_id', auth()->id())->where('payment_status', 'free')->pluck('id')->toArray();
                $orderIds = array_merge($paidOrderIds, $freeOrderIds);
                $orderCourseIds = Order_item::whereIn('order_id', $orderIds)->pluck('course_id')->toArray();

                if (in_array($bundle_course_id, $orderCourseIds) == false){
                    $order_item = new Order_item();
                    $order_item->order_id = $order->id;
                    $order_item->user_id = Auth::user()->id;
                    $order_item->bundle_id = $cart->bundle_id;
                    $order_item->course_id = $bundle_course_id;
                    $order_item->owner_user_id = $cart->bundle->user_id;
                    $order_item->type = 3; //bundle course
                    $order_item->save();
                }
            }

        } elseif ($cart->consultation_slot_id) {
            $order_item = new Order_item();
            $order_item->order_id = $order->id;
            $order_item->user_id = Auth::id();
            $order_item->owner_user_id = is_array($cart['consultation_details']) ? $cart['consultation_details'][0]->instructor_user_id : null;
            $order_item->consultation_slot_id = $cart->consultation_slot_id;
            $order_item->consultation_date = $cart->consultation_date;
            $order_item->unit_price = $cart->price;
            if (get_option('sell_commission')) {
                $order_item->admin_commission = admin_sell_commission($cart->price);
                $order_item->owner_balance = $cart->price - admin_sell_commission($cart->price);
                $order_item->sell_commission = get_option('sell_commission');
            } else {
                $order_item->owner_balance = $cart->price;
            }
            $order_item->type = 4;
            $order_item->save();

            //Start:: Need to add Booking History
            $booking = new BookingHistory();
            $booking->order_id = $order->id;
            $booking->order_item_id = $order_item->id;
            $booking->instructor_user_id = is_array($cart['consultation_details']) ? $cart['consultation_details'][0]->instructor_user_id : null;
            $booking->student_user_id = Auth::id();
            $booking->consultation_slot_id = $cart->consultation_slot_id;
            $booking->date = is_array($cart['consultation_details']) ? $cart['consultation_details'][0]->date : null;
            $booking->day = is_array($cart['consultation_details']) ? $cart['consultation_details'][0]->day : null;
            $booking->time = is_array($cart['consultation_details']) ? $cart['consultation_details'][0]->time : null;
            $booking->duration = is_array($cart['consultation_details']) ? $cart['consultation_details'][0]->duration : null;
            $booking->type = $cart->consultation_available_type;
            $booking->status = 0; //Pending
            $booking->save();

            //End:: Add Booking History
        }

    }
    CartManagement::whereUserId(@Auth::user()->id)->delete();
    return $order;
}

}

habeeblht17 avatar May 31 '23 09:05 habeeblht17

@habeeblht17 what is your Laravel version

Paystack::getAuthorizationUrl()->redirectNow(); The line above expects payment data in two ways 1=> Through the submitted form data, if this is your case use it like this return Paystack::getAuthorizationUrl()->redirectNow();

2=> Pass the data from your controller instead of a form, is this is the case then you need to build your array day and pass the array to the getAuthorizationUrl() method. example below

$data = array(
        "amount" => 700 * 100,
        "reference" => '4g4g5485g8545jg8gj',
        "email" => '[email protected]',
        "currency" => "NGN",
        "orderID" => 23456,
    );

return Paystack::getAuthorizationUrl($data)->redirectNow();

You missed the guide on the info page

goodmuyis avatar Jun 04 '23 09:06 goodmuyis

Thanks for getting back to me. Am using version 9. Have solve the problem. The issue came from the csrf token from the form, where I suppose to use the csrf token syntax that is compatible with version 9, am using the one for version 5. I will close the case on github.

Once again thank you.

On Sun, Jun 4, 2023, 10:46 AM goodmuyis @.***> wrote:

@habeeblht17 https://github.com/habeeblht17 what is your Laravel version

You can pass payment Paystack::getAuthorizationUrl()->redirectNow(); The line above expects payment data in two ways 1=> Through the submitted form data, if this is your case use it like this return Paystack::getAuthorizationUrl()->redirectNow();

2=> Pass the data from your controller instead of a form, is this is the case then you need to build your array day and pass the array to the getAuthorizationUrl() method. example below

$data = array( "amount" => 700 * 100, "reference" => '4g4g5485g8545jg8gj', "email" => @.***', "currency" => "NGN", "orderID" => 23456, );

return Paystack::getAuthorizationUrl($data)->redirectNow();

You missed the guide on the info page

— Reply to this email directly, view it on GitHub https://github.com/unicodeveloper/laravel-paystack/issues/172#issuecomment-1575492870, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYZX6DGK32WMG3AVTFOGT73XJRKPFANCNFSM6AAAAAAWRLS24M . You are receiving this because you were mentioned.Message ID: @.***>

habeeblht17 avatar Jun 04 '23 10:06 habeeblht17