gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:29 26 4
gpt4 key购买 nike

同时使用来自 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);
?>


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

最佳答案

它的 setPaymentMethod()不是 setPayment_method(),所以,改为:

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

关于php - 调用未定义的方法 PayPal\Api\Payer::setPayment_method(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44109815/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com