由于我尝试使用 PayPal REST API 直接失败,我正在尝试查看 Omnipay 是否是一个选项...有没有办法将 REST API 与 Omnipay 一起使用?到目前为止,我见过的唯一集成需要用户名
和密码
,而不是客户端ID
和客户端密码
:
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('XXXXX');
$gateway->setPassword('XXXX');
$gateway->setSignature('XXXXX');
$response = $gateway->completePurchase(
array(
'cancelUrl' => 'www.xyz.com/cancelurl',
'returnUrl' => 'www.xyz.com/returnurl',
'amount' => '25.00',
'currency' => 'CAD'
)
)->send();
最佳答案
对于发现这篇文章的其他人,这里有对 REST API 的支持。
源代码完整文档中的 RestGateway.php
摘录
- The PayPal REST APIs are supported in two environments. Use the Sandbox environment
- for testing purposes, then move to the live environment for production processing.
- When testing, generate an access token with your test credentials to make calls to
- the Sandbox URIs. When you’re set to go live, use the live credentials assigned to
- your app to generate a new access token to be used with the live URIs.
提交 https://github.com/thephpleague/omnipay-paypal/pull/21
// Create a gateway for the PayPal RestGateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('RestGateway');
// Initialise the gateway
$gateway->initialize(array(
'clientId' => 'MyPayPalClientId',
'secret' => 'MyPayPalSecret',
'testMode' => true, // Or false when you are ready for live transactions
));
// Create a credit card object
// DO NOT USE THESE CARD VALUES -- substitute your own
// see the documentation in the class header.
$card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '01',
'expiryYear' => '2020',
'cvv' => '123',
'billingAddress1' => '1 Scrubby Creek Road',
'billingCountry' => 'AU',
'billingCity' => 'Scrubby Creek',
'billingPostcode' => '4999',
'billingState' => 'QLD',
));
// Do an authorisation transaction on the gateway
$transaction = $gateway->authorize(array(
'amount' => '10.00',
'currency' => 'AUD',
'description' => 'This is a test authorize transaction.',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Authorize transaction was successful!\n";
// Find the authorization ID
$auth_id = $response->getTransactionReference();
}
来自 RestAuthorizeRequest.php
关于php - Omnipay:PayPal REST API 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22024237/