调用未定义的方法PayPal \ Api \ Payer :: setPayment_method()

时间:2017-05-22 09:50:20

标签: php rest api paypal sdk

使用GitHub的PayPal PHP SDK。 我遇到了一个错误,我无法找到错误的修复:

Call to undefined method PayPal\Api\Payer::setPayment_method()

我的代码就在这里:

<?php
use PayPal\Rest\ApiContext;
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;

session_start();

require 'vendor/autoload.php';
$api = new ApiContext(
  new OAuthTokenCredential(
      'My PayPal Public DEV KEY',
      'MY PayPal Private DEV KEY'
    )
);
$api->setConfig([
  'mode' => 'sandbox',
  'http.ConnectionTimeOut' => 120,
  'log.LogEnabled' => false,
  'log.FileName' => '',
  'log.LogLevel' => 'FINE',
  'validation.level' => 'log'
]);

$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();

$payer->setPayment_method('paypal');
$details->setTax('0.00')
        ->setSubtotal('20.00');
$amount->setCurrency('USD')
       ->setTotal('20.00')
       ->setDetails($details);

$transaction->setAmount($amount)
            ->setDescription('Access');
$payment->setIntent('sale')
        ->setPayer($payer)
        ->setTransaction([$transaction]);

$redirectUrls->setReturnUrl('http://127.0.0.1/paypal/validate.php?approved=true')
             ->setCancelUrl('http://127.0.0.1/paypal/validate.php?approved=false');
$payment->setRedirectUrls($redirectUrls);
?>


如果有人能找到解决办法或指出我正确的方向,我将不胜感激。 ;)

1 个答案:

答案 0 :(得分:4)

setPaymentMethod()而非setPayment_method(),因此,请更改为:

...
$payer->setPaymentMethod('paypal');
...