简体   繁体   中英

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

Whilst using the PayPal PHP SDK from GitHub. I have experienced an error which I cant find a fix for the error is:

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

My Code is Here:

<?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);
?>


If anyone could find a fix or point me in the right direction that would be greatly appreciated. ;)

Its setPaymentMethod() not setPayment_method() , so, change to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM