unicodeveloper / laravel-paystack

:credit_card: :package: :moneybag: Laravel 6, 7, 8, 9, 10 and 11 Package for Paystack
https://paystack.co
MIT License
597 stars 310 forks source link

Client Error: Transaction Initialize ... 401 not found #95

Closed doubleprincez closed 4 years ago

doubleprincez commented 4 years ago

I received the error below while trying to redirect through my webhook to the payment gateway.

"Client error: `POST http:\/\/site_url\/payment\/webhook\/transaction\/initialize` resulted in a `404 Not Found` response:\n{\n \"message\": \"\",\n \"exception\": \"Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\NotFoundHttpException\",\n \"file\": \"C (truncated...)\n"

in payment controller...

use Paystack;

 public function paymentSubmit()
    {
        try {
            return  Paystack::getAuthorizationUrl()->redirectNow();
        } catch (Exception $e) {
            return response()->json($e->getMessage());
        }
    }

composer information:

 "php": "^7.1.3",
"laravel/framework": "5.7.*",
       "unicodeveloper/laravel-paystack": "1.0.*",
bere6255 commented 4 years ago

how do you handle the redirect drop the front-end code

doubleprincez commented 4 years ago

I havent sent it to the front end yet, im trying to get the response first but its not redirecting to the payment gateway.....

        $paymentDetails = (new Paystack)->getPaymentData();
//
        $json_reply = json_decode(json_encode($paymentDetails))->data;

        $user = User::where('id', '=', auth()->id())->first();
//         document transaction
        $this->storeTransaction($user, $paymentDetails);
        return response()->json($json_reply);

having routes of

Route::post('/payment/webhook', 'CheckoutController@paymentSubmit')->name('payment.webhook');

Route::post('/payment/callback', 'CheckoutController@paymentCallback')->name('payment.callback');

passing the authorization url response to dd, i got

 GuzzleHttp\Exception\ClientException {#1138 ▼
  -request: GuzzleHttp\Psr7\Request {#1149 ▼
    -method: "POST"
    -requestTarget: null
    -uri: GuzzleHttp\Psr7\Uri {#1153 ▼
      -scheme: "http"
      -userInfo: ""
      -host: "site.dev"
      -port: null
      -path: "/payment/webhook/transaction/initialize"
      -query: ""
      -fragment: ""
    }
    -headers: array:5 [▼
      "Authorization" => array:1 [▶]
      "Content-Type" => array:1 [▼
        0 => "application/json"
      ]
      "Accept" => array:1 [▼
        0 => "application/json"
      ]
      "User-Agent" => array:1 [▼
        0 => "GuzzleHttp/6.5.1 curl/7.64.0 PHP/7.3.7"
      ]
      "Host" => array:1 [▼
        0 => "site.dev"
      ]
    ]
    -headerNames: array:5 [▼
      "authorization" => "Authorization"
      "content-type" => "Content-Type"
      "accept" => "Accept"
      "user-agent" => "User-Agent"
      "host" => "Host"
    ]
    -protocol: "1.1"
    -stream: GuzzleHttp\Psr7\Stream {#1151 ▼
      -stream: stream resource @622 ▼
        wrapper_type: "PHP"
        stream_type: "TEMP"
        mode: "w+b"
        unread_bytes: 0
        seekable: true
        uri: "php://temp"
        options: []
      }
      -size: 1774
      -seekable: true
      -readable: true
      -writable: true
      -uri: "php://temp"
      -customMetadata: []
    }
  }
  -response: GuzzleHttp\Psr7\Response {#1141 ▼
    -reasonPhrase: "Not Found"
    -statusCode: 404
    -headers: array:8 [▼
      "Date" => array:1 [▼
        0 => "Thu, 19 Mar 2020 10:17:07 GMT"
      ]
      "Server" => array:1 [▼
        0 => "Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.7"
      ]
      "Vary" => array:1 [▼
        0 => "Authorization"
      ]
      "X-Powered-By" => array:1 [▼
        0 => "PHP/7.3.7"
      ]
      "Cache-Control" => array:1 [▼
        0 => "no-cache, private"
      ]
      "Content-Length" => array:1 [▼
        0 => "7860"
      ]
      "Connection" => array:1 [▼
        0 => "close"
      ]
      "Content-Type" => array:1 [▼
        0 => "application/json"
      ]
    ]
    -headerNames: array:8 [▼
      "date" => "Date"
      "server" => "Server"
      "vary" => "Vary"
      "x-powered-by" => "X-Powered-By"
      "cache-control" => "Cache-Control"
      "content-length" => "Content-Length"
      "connection" => "Connection"
      "content-type" => "Content-Type"
    ]
    -protocol: "1.0"
    -stream: GuzzleHttp\Psr7\Stream {#1143 ▼
      -stream: stream resource @628 ▼
        wrapper_type: "PHP"
        stream_type: "TEMP"
        mode: "w+b"
        unread_bytes: 0
        seekable: true
        uri: "php://temp"
        options: []
      }
      -size: 7860
      -seekable: true
      -readable: true
      -writable: true
      -uri: "php://temp"
      -customMetadata: []
    }
  }
  -handlerContext: []
  #message: """
    Client error: `POST http://site.dev/payment/webhook/transaction/initialize` resulted in a `404 Not Found` response:\n
    {\n
        "message": "",\n
        "exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",\n
        "file": "C (truncated...)\n
    """
  #code: 404
  #file: "C:\xampp\htdocs\laravel_site_offline\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php"
  #line: 113
  trace: {▶}
doubleprincez commented 4 years ago

I've been able to trace the error down to .env......... paystack_payment_url ought to be https://api.paystack.co but i was using my paying url i.e http://site.dev/payment/webhook