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

tallaljamshed's avatar

Implementing Flutter API

Hi, I'm trying to implement this "https://api.flutterwave.com/v3/payments/" api in laravel. what i want is to send some data to this api and get a url in response so I can send that url back to the ajax request on client side. client side opens that url in a new tab and pays whatever amount was set in controller now how can i implement that. This is my code so far.

$amount = some amount;
    $referenceno = some ref number;
    $currency = "NGN";
    $redirect_url = some url;
    $authorization = 'Bearer'." ".$this->fsk;
    $data = [
        'amount' => $amount,
        'email' => email,
        'metadata' => json_encode($array = [
            'contest_id'=>contest_id , 
            'contestent_id'=>contestant_id,
            'no_of_votes'=>no_of_votes
        ]),
        'reference' => $referenceno,
    ];

    $client = new \GuzzleHttp\Client();
    $url = "https://api.flutterwave.com/v3/payments/";

    $request = $client->post($url,  [
        'headers' => [
            'Content-Type' => 'application/json',
            'Authorization' => $authorization,
        ],
        'form_params' => [
                'public_key'=>$this->fpk,
                "tx_ref"=>$referenceno,
                "amount"=>$amount,
                "currency"=>$currency,
                "redirect_url"=>$redirect_url,
                'customer'=>[
                    'email' => email,
                    'phone_number'=>some number,
                    'name'=>'voter',
                ],
                "meta"=>$data,
                'customizations' =>[
                    'title' => title,
                    'description'  => 'Pay to vote',
                ]
        ]
    ]);

    $response = $request->send();
    dd($response);

this returns me the error

Server error: `POST https://api.flutterwave.com/v3/payments/` resulted in a `500 Internal Server Error` response:↵{"error_id":"ERRNO738287451T1607106126413","message":"Application error. Please contact support","code":"app_error"}↵"

which is not very helpful so if someone can guide me. also i dont want to send payment method so customer can just chose one from payment page.

0 likes
1 reply
tallaljamshed's avatar
tallaljamshed
OP
Best Answer
Level 1

alright i got it working only change form_params to json and no public_key required only tx_ref , amount and redirect_url.

Please or to participate in this conversation.