skip to Main Content

I have a laravel api that I’m trying to run a custom artisan command to process a transaction. The api is suppose to check for pending transactions in our merchant database and post them in our transaction database.
I get the following error:

[GuzzleHttpExceptionClientException]
  Client error: `POST http://paycentral.mymarket.com/transactions/bulk` resulted in a `405 Method Not Allowed` response:
  {"error":{"message":"405 Method Not Allowed","status_code":405,"debug":{"line":446,"file":"/var/www/vhosts/maindomai (truncated...)

The API I’m using is located at api.mymarket.com. Searching for errors like this has me believing it’s a CORS-related issue. I’m using laravel-cors and added Header set Access-Control-Allow-Origin “*” to the .htaccess in both the public folder for api.mymarket.com and paycentral.mymarket.com. The error is still persisting though. Is there any other possible workaround? We are currently using plesk for our hosting services.

UPDATE: I tried doing a preflight request in the pay subdomain
Origin: api.mymarket.com
Access-Control-Request-Method: POST
Access-Control-Request-Headers: MM

It returned a 500 Internal Error which is progress I guess.

UPDATE Here is the routes.php for paycentral. The cors-library is registered in the app.php.

paycentral routes.php

<?php

$api = app('DingoApiRoutingRouter');

// all routes are protected by the Authenticate middleware which makes sure     the client
// is authenticated as *somebody* - each resource is further protected by  the authorization
// policies in the AppApiV1Policies files to limit the method calls by which client
// type is attempting to access the resource - these must be mapped in the     AuthServiceProvider
$api->group([
    'version' => 'v1',
    'namespace' => 'AppApiV1Controllers',
    'middleware' => 'auth' // use the Authenticate middleware
], function($api) {

/*
     * partial CRUD resource routes
     */

    $api->get('transactions/{id}', 'TransactionController@show');
    $api->post('transactions', 'TransactionController@store');
    $api->put('transactions/{id}', 'TransactionController@update');
    $api->post('transactions/bulk', 'TransactionController@store_bulk');
    $api->post('transactions/get_updates',  'TransactionController@get_updates');

2

Answers


  1. Chosen as BEST ANSWER

    I solved the issue. It was an issue with one of the routes not pointing to transactions/bulk. The previous developer made undocumented changes to a couple files without following our version control methods so the production branch was broken.


  2. Assuming that your route is defined well in the routes.php, and that everything else is fine. Then you may try adding the following line in your filters.php

    App::before(function ($request) {
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS');
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search