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()
发布于 2021-06-23 09:40:52
正确的用法如下
$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。如果您想使用测试环境,那么将第三个参数作为true或false传递给Production
注意:,Instamojo-php v1.0有一个问题。问题是InvalidRequestException.php异常类命名空间不正确。因此,修复方法是手动将此异常类的命名空间从Instamojo\Exception更改为Instamojo\Exceptions。
https://stackoverflow.com/questions/68086207
复制相似问题