从上下文调用私有 Instamojo\Instamojo::__construct()

问题描述 投票:0回答:2
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( line 上提交表单后出错。

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

laravel laravel-5 laravel-4 instamojo
2个回答
0
投票

从哪里获取client_id和client_secret的值?


-2
投票

正确的用法是这样的

$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
可以是
app
user
。如果您想使用 Test 环境,则将第三个参数作为
true
false
传递给 Production

注意:

Instamojo-php v1.0
有问题。问题是
InvalidRequestException.php
异常类命名空间不正确。因此,修复方法是手动将该异常类的命名空间从
Instamojo\Exception
更改为
Instamojo\Exceptions

© www.soinside.com 2019 - 2024. All rights reserved.