加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 持续时间后支付网关更改方法

发布时间:2020-12-13 16:08:58 所属栏目:PHP教程 来源:网络整理
导读:我正在使用电子商务.完成付款后,应该将其捕获并且几天后,应该从客户帐户处理或扣除. 示例:如果客户使用Paypal初始付款,那么它将是“授权”在特定交易转换为“销售”之后(最多21天)意味着已处理. 客户可以使用信用卡付款.我们可以使用Paypal或需要使用其他付
我正在使用电子商务.完成付款后,应该将其捕获并且几天后,应该从客户帐户处理或扣除.

示例:如果客户使用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

解决方法

添加composer.json

"require": {
        "paypal/rest-api-sdk-php": "*"
    }

在yii中查看代码示例

use Yii;
use yiibaseErrorException;
use yiihelpersArrayHelper;
use yiibaseComponent;
use yiihelpersUrl;

use PayPalApiAddress;
use PayPalApiCreditCard;
use PayPalApiAmount;
use PayPalApiPayer;
use PayPalApiPayment;
use PayPalApiTransaction;
use PayPalApiFundingInstrument;
use PayPalAuthOAuthTokenCredential;
use PayPalApiDetails;
use PayPalApiItem;
use PayPalApiItemList;
use PayPalApiRedirectUrls;
use PayPalRestApiContext;


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;
    }



}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读