持续时间后支付网关更改方法
Posted
技术标签:
【中文标题】持续时间后支付网关更改方法【英文标题】:Payment gateway change method after duration 【发布时间】:2017-07-11 21:24:53 【问题描述】:我正在使用电子商务。付款完成后,应将其捕获并在几天后处理或从客户帐户中扣除。
示例:如果客户使用 Paypal 初始付款,则将是“授权”,并且在(最多 21 天)特定交易转换为“销售”意味着处理之后。
客户可以使用信用卡付款。我们可以使用 Paypal 实现还是需要使用其他付款方式?
据我所知:在 Paypal SDK API 中,您必须再次创建付款然后处理。但我已经有了交易 ID。所以需要重新创建付款吧?
Paypal: How to Capture Authorized Payment?
http://paypal.github.io/PayPal-php-SDK/sample/doc/payments/AuthorizationCapture.html
【问题讨论】:
如果有人可以详细指导或实现这一目标的人。可以分享一下自己的看法。谢谢 【参考方案1】:在 composer.json 中添加
"require":
"paypal/rest-api-sdk-php": "*"
在 yii 中查看代码示例
use Yii;
use yii\base\ErrorException;
use yii\helpers\ArrayHelper;
use yii\base\Component;
use yii\helpers\Url;
use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Api\Amount;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\Transaction;
use PayPal\Api\FundingInstrument;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\RedirectUrls;
use PayPal\Rest\ApiContext;
class Paypal extends Component
public $clientId;
public $clientSecret;
public $currency;
public $returnUrl;
public $cancelUrl;
public $intentType;
public $config;
public function pay($total, $shipping, $tax, $productName, $transactionDescription)
$apiContext = new ApiContext(
new OAuthTokenCredential(
$this->getClientId(), // ClientID
$this->getClientSecret() // ClientSecret
)
);
$apiContext->setConfig(ArrayHelper::merge(
[
'mode' => 'sandbox', // development (sandbox) or production (live) mode
'http.ConnectionTimeOut' => 30,
'http.Retry' => 1,
'log.LogEnabled' => YII_DEBUG ? 1 : 0,
'log.FileName' => Yii::getAlias('@runtime/logs/paypal.log'),
'log.LogLevel' => 'FINE',
'validation.level' => 'log',
'cache.enabled' => 'true'
], $this->getConfig())
);
$payer = new Payer();
$payer->setPaymentMethod("paypal");
if(($subtotal = $total - $shipping - $tax) < 0)
throw new ErrorException('Subtotal is negative');
$item = new Item();
$item->setName($productName)
->setCurrency($this->getCurrency())
->setQuantity(1)
->setPrice($subtotal);
$itemList = new ItemList();
$itemList->addItem($item);
$details = new Details();
$details->setShipping($shipping)
->setTax($tax)
->setSubtotal($subtotal);
$amount = new Amount();
$amount->setCurrency($this->getCurrency())
->setTotal($total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription($transactionDescription)
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(Url::home(true) . Url::to([$this->getReturnUrl()]))
->setCancelUrl(Url::home(true) . Url::to([$this->getCancelUrl()]));
$payment = new Payment();
$payment->setIntent($this->getIntentType())
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try
$payment->create($apiContext);
catch (Exception $ex)
return $payment;
/**
* @return mixed
*/
public function getClientId()
return $this->clientId;
/**
* @return mixed
*/
public function getClientSecret()
return $this->clientSecret;
/**
* @return mixed
*/
public function getCurrency()
return $this->currency;
/**
* @return mixed
*/
public function getReturnUrl()
return $this->returnUrl;
/**
* @return mixed
*/
public function getCancelUrl()
return $this->cancelUrl;
/**
* @return mixed
*/
public function getIntentType()
return $this->intentType;
/**
* @return mixed
*/
public function getConfig()
return $this->config;
【讨论】:
在核心 PHP 中寻找解决方案 @AnkitShah,你不能只使用上面答案中引用的 PayPal Rest API SDK 吗?以上是关于持续时间后支付网关更改方法的主要内容,如果未能解决你的问题,请参考以下文章
如何通过 WooCommerce 中管理员端的更改订单设置支付网关
WooCommerce:如果购物车总金额 = 0,则更改支付网关