0
public function pay(Request $request){

$api = new \Instamojo\Instamojo(
       config('services.instamojo.api_key'),
       config('services.instamojo.auth_token'),
       config('services.instamojo.url')
   );

 try {
   $response = $api->paymentRequestCreate(array(
       "purpose" => "FIFA 16",
       "amount" => $request->amount,
       "buyer_name" => "$request->name",
       "send_email" => true,
       "email" => "$request->email",
       "phone" => "$request->mobile_number",
       "redirect_url" => "http://127.0.0.1:8000/pay-success"
       ));
        
       header('Location: ' . $response['longurl']);
       exit();
   }catch (Exception $e) {
    print('Error: ' . $e->getMessage());
  }
}

在 $api = new \Instamojo\Instamojo( 行提交表单后出错。

错误:- 调用私人 Instamojo\Instamojo::__construct()

4

1 回答 1

0

正确用法是这样的

$api = \Instamojo\Instamojo::init($authType, [
    'client_id' => '<clientId>',
    'client_secret' => '<clientSecret>',
    'username' => '<userName>',   // optional
    'password' => '<password>',   // optional
    'scope' => '<scope if any>'   // optional
], false);

try {
    $response = $api->createPaymentRequest(array(
        "purpose" => "FIFA 16",
        "amount" => $request->amount,
        "buyer_name" => "$request->name",
        "send_email" => true,
        "email" => "$request->email",
        "phone" => "$request->mobile_number",
        "redirect_url" => "http://127.0.0.1:8000/pay-success"
    ));

    header('Location: ' . $response['longurl']);
    exit();
} catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

$authType可以是appuser。如果要使用测试环境,则将第三个参数作为true或传递false生产

注意:有一个问题Instamojo-php v1.0。问题是InvalidRequestException.php异常类命名空间不正确。所以,修复是手动将这个异常类的命名空间从更改Instamojo\ExceptionInstamojo\Exceptions

于 2021-06-23T09:40:52.980 回答