php - Omnipay:PayPal REST API 集成

标签 php paypal laravel-4 omnipay

由于我尝试使用 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/

相关文章:

paypal - 在 Paypal Standard 中停止 Paypal 定期付款

python - App Engine python 上用于 PayPal 网络支付标准的加密 PayPal 按钮?

apache - 如何在 htaccess 中将除一个页面之外的所有页面定向到 HTTPS?

php - CakePHP 3 中的 MVC - 模型和 View 之间的关注点分离

php - 我如何从网络上获取 YouTube 视频 ID?

python - django-paypal 教程 : 'reverse' seems to be used incorrectly

php - 更新时格式化的日期时间提交为无效

php - 仅显示三级 Wordpress 菜单

php - 使用 php 分页

php - 拉维尔 4 : how to write the correct nested controller for nested resource?