Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mspace's avatar

Paystack set first and last name parameters

I am using paystack standard and I use this function to initialize payments. It only sends the the email and amount and it does not recognize the other fields. How can I resolve this?


    public function initialize(Request $request)
    {

        $curl = curl_init();

    
        // $email = $request->email;
        //$email = 'aaaa' . time() . '@gmail.com';
        $amount = $request->amount;  //the amount in kobo. This value is actually NGN 300
        $first_name = $request->first_name;  //the amount in kobo. This value is actually NGN 300
        $last_name = $request->last_name;  //the amount in kobo. This value is actually NGN 300
        //$emaillll = '1234';

       
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://api.paystack.co/transaction/initialize",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => json_encode([
                'amount' => $amount,
                'email' => $email,
                'phone' => 234868965986,
                'firstname' => $first_name,
                'lastname' => $last_name,



            ]),
            CURLOPT_HTTPHEADER => [
                "authorization: Bearer MY_SECRET_KEY", //replace this with your own test key
                "content-type: application/json",
                "cache-control: no-cache"
            ],
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        if ($err) {
            // there was an error contacting the Paystack API
            die('Curl returned error: ' . $err);
        }

        $tranx = json_decode($response, true);
     

        if ($tranx['status'] != true) {
            // there was an error from the API
            print_r('API returned error: ' . $tranx['message']);
        }
  


        // redirect to page so User can pay
        // uncomment this line to allow the user redirect to the payment page
        return redirect($tranx['data']['authorization_url']);
    }
}

0 likes
0 replies

Please or to participate in this conversation.