【发布时间】:2019-12-26 06:02:31
【问题描述】:
我正在尝试将 Paypal 作为支付网关集成到我的 Laravel 5.8 网站中。为此,我使用了 Laravel-Omnipay 包,它提供了 Omnipay 与 Laravel 的集成。
至于我的Paypal 企业帐户,我已经设置了我的凭据。使用带有以下代码的贝宝沙箱:
Route::get('paypal', function() {
$gateway = Omnipay::create('PayPal_Rest');
$gateway->initialize(array(
'clientId' => 'MySandboxClientId',
'secret' => 'MySandboxSecret',
'testMode' => true,
));
$card = new CreditCard(array(
'firstName' => 'first name',
'lastName' => 'last name',
'number' => '5498876202508868',
'cvv' => '123',
'expiryMonth' => '09',
'expiryYear' => '2024',
'billingAddress1' => '1 Scrubby Creek Road',
'billingCountry' => 'AU',
'billingCity' => 'Scrubby Creek',
'billingPostcode' => '4999',
'billingState' => 'QLD',
));
try {
$transaction = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'card' => $card,
));
$response = $transaction->send();
$data = $response->getData();
dd($data);
echo "Gateway purchase response data == " . print_r($data, true) . "\n";
if ($response->isSuccessful()) {
echo "Purchase transaction was successful!\n";
}
} catch (\Exception $e) {
echo "Exception caught while attempting authorize.\n";
echo "Exception type == " . get_class($e) . "\n";
echo "Message == " . $e->getMessage() . "\n";
}
});
但是,当我尝试使用自己的信用卡进行实时付款时。我可以Unauthorized payment. 错误。我使用的代码与上面相同,我只是将 clientId 和 secret 替换为我的实时沙箱凭据。
如何实时调用 REST Api。我需要进行一笔 1 美元的交易,以便测试该卡是否有效。
【问题讨论】: