2

由于我直接使用 PayPal REST API 的尝试失败了,我试图看看 Omnipay 是否是一种选择……有没有办法将 REST API 与 Omnipay 一起使用?到目前为止,我见过的唯一集成需要一个usernameand password,而不是client idand client secret

$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();
4

3 回答 3

3

对于发现这篇文章的其他任何人,都支持 REST API。

RestGateway.php源代码完整文档中的摘录

  • 两种环境都支持 PayPal REST API。使用沙盒环境
  • 用于测试目的,然后转移到现场环境进行生产处理。
  • 测试时,使用您的测试凭据生成访问令牌以调用
  • 沙盒 URI。当您准备上线时,请使用分配给
  • 您的应用程序生成一个新的访问令牌以与实时 URI 一起使用。

提交 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

于 2015-10-23T04:40:02.927 回答
0

不,Omnipay 还不支持 REST API。

也就是说,Omnipay 抽象了各种 API 之间的差异,因此您使用哪个 API 并不重要。您在上面发布的代码应该可以在 PayPal Express Checkout 中正常工作,因此只需确保您使用正确的 API 密钥,一切都会很容易。

于 2014-02-26T17:10:22.570 回答
0

REST API 在 PayPal 中仍然很新,而且还不够完整。还没有很多 3rd 方框架实现它。

看起来您正在使用 PHP 并尝试实现 Express Checkout..?? 如果是这样,我建议您查看我的 PayPal 类库。您可以在几分钟内完成。

它也使用 API 用户名、密码和签名。您可以从 API 访问部分下的 PayPal 帐户配置文件中获取这些凭据。

我的库附带了功能强大且易于遵循的 Express Checkout 示例,然后您可以从空模板开始设置自己的模板,只需填写您需要的任何参数。

于 2014-02-25T20:36:15.390 回答