首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Omnipay: PayPal REST API集成

Omnipay: PayPal REST API集成
EN

Stack Overflow用户
提问于 2014-02-26 03:28:51
回答 3查看 5.2K关注 0票数 2

因为我尝试直接使用Omnipay REST API失败了,所以我想看看是否可以使用PayPal……有没有办法在Omnipay中使用REST API?到目前为止,我见过的唯一集成需要usernamepassword,而不是client idclient secret

代码语言:javascript
复制
$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();
EN

回答 3

Stack Overflow用户

发布于 2015-10-23 12:40:03

对于其他找到这篇文章的人,有对REST API的支持。

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

  • PayPal REST API在两个环境中受支持。使用沙盒environment
  • for测试目的,然后移动到生产processing.
  • When测试的实时环境,使用您的测试凭据生成访问令牌,以调用
  • 沙盒URI。设置为启用时,请使用分配给
  • 应用程序的实时凭据生成新的访问令牌,以便与实时URI一起使用。

提交https://github.com/thephpleague/omnipay-paypal/pull/21

代码语言:javascript
复制
// 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

票数 3
EN

Stack Overflow用户

发布于 2014-02-26 04:36:15

REST API在PayPal中仍然是非常新的,而且还不够完整。目前还没有多少第三方框架实现它。

看起来您正在使用PHP并尝试实现Express Checkout..??如果是这样的话,我建议你看看我的class library for PayPal。你可以在几分钟内完成这项工作。

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

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

票数 0
EN

Stack Overflow用户

发布于 2014-02-27 01:10:23

不,Omnipay还不支持REST API。

也就是说,Omnipay抽象了不同API之间的差异,所以使用哪个API对您来说并不重要。您在上面发布的代码应该可以很好地使用are,所以只需确保您使用的是正确的PayPal密钥,一切都将变得简单。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22024237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档