0

Please i need help, i don't know what i am doing wrong. Accessing the API works through postman but not working in my laravel application.

//...........
Client error: `POST https://remitademo.net/remita/exapp/api/v1/send/api/echannelsvc/merchant/api/paymentinit` resulted in a `405 Method Not Allowed` response:

{"responseData":"{\"status\":null,\"responseCode\":\"405\",\"responseMsg\":\"Request method \u0027GET\u0027 not supporte (truncated...)
//.................

$client = new Client();
        $headers = [
            'Content-Type' => 'application/json',
            'Authorization' => "remitaConsumerKey={$merchantId},remitaConsumerToken={$hash}"
        ];

    $body = [
              "serviceTypeId"=>$serviceTypeId,
              "amount"=>$amount,
              "orderId"=>$orderId,
              "payerName"=> Auth::user()->surname.' '.Auth::user()->firstname,
              "payerEmail"=> Auth::user()->email,
              "payerPhone"=>Auth::user()->phone,
              "description"=>"Payment for Septmeber Fees"
            ];
    
    $request = new Request('POST', 'https://remitademo.net/remita/exapp/api/v1/send/api/echannelsvc/merchant/api/paymentinit', $headers, json_encode($body));
    
    $res = $client->sendAsync($request
);
3
  • Are you using GuzzleHttp ?Please ensure. Commented Nov 13, 2024 at 17:00
  • @Subha Yes, i'am - GuzzleHttp\Psr7\Request and GuzzleHttp\Client Commented Nov 13, 2024 at 19:02
  • I have posted my answer, please check and let me know your feedback. Commented Nov 14, 2024 at 7:46

1 Answer 1

0

The issue lies in your sendAsync($request) part .As per the official-docs of the Remita API the response of the API should be collected as (since it is an asynchronous request).

$res = $client->sendAsync($request)->wait();
echo $res->getBody();

Alternatively you can also use this approach as per Guzzle Documentation.

// Send an asynchronous request.
$res= $client->sendAsync($request)->then(function ($response) {
    echo 'I completed! ' . $response->getBody();
});
$res->wait();

N:B :- Also note that the apiHash is SHA-512 encryption of concatenating merchantId + serviceTypeId + orderId + totalAmount + apiKey.

Try this and let me know.

EDIT :-

Try this and let me know.

$response = $client->request('POST', 'https://remitademo.net/remita/exapp/api/v1/send/api/echannelsvc/merchant/api/paymentinit', [
    'headers' => $headers,
    'json' => $body
]);
Sign up to request clarification or add additional context in comments.

2 Comments

Does not work. If i dd($request) the body is not passed, it seems that is the problem
@Abenslive , I have edited my answer,please check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.