首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从上下文调用私有Instamojo\Instamojo::__construct()

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

Stack Overflow用户
提问于 2021-06-22 15:12:33
回答 1查看 471关注 0票数 0
代码语言:javascript
复制
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());
  }
}

= new \Instamojo(行)上提交表单后出现$api错误。

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

EN

回答 1

Stack Overflow用户

发布于 2021-06-23 09:40:52

正确的用法如下

代码语言:javascript
复制
$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。如果您想使用测试环境,那么将第三个参数作为truefalse传递给Production

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68086207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档