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()
从哪里获取client_id和client_secret的值?
正确的用法是这样的
$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