PayPal PHP SDK创建未来付款

时间:2015-11-25 19:40:28

标签: php paypal

我按照所有说明here 在我的申请中创建未来付款。

public function __construct()
{
    $auth = new PayPal\Auth\OAuthTokenCredential(
        'ClientID',     // ClientID
        'Client Secret'      // ClientSecret
    );
    $this->apiContext = new \PayPal\Rest\ApiContext($auth);
    $this->apiContext->setConfig(['mode' => 'live']);

    $this->config['method'] = 'paypal';
    $this->config['currency'] = 'USD';
    $this->config['refreshToken'] = false;
}

function make_payment($config){

    $this->config['method'] = isset($config['method']) ? $config['method'] : 'paypal';
    $this->config['currency'] = isset($config['currency']) ? $config['currency'] : 'USD';
    $this->config['totalAmount'] = isset($config['totalAmount']) ? $config['totalAmount'] : '10.00';
    $this->config['refreshToken'] = isset($config['refreshToken']) ? $config['refreshToken'] : false;
    $this->config['authorization_code'] = $config['authorization_code'];
    $this->config['client_metadata_id'] = $config['client_metadata_id'];

    $payer = new Payer();
    $payer->setPaymentMethod($this->config['method']);

    $amount = new Amount();
    $amount->setCurrency($this->config['currency'])
        ->setTotal($this->config['totalAmount']);

    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setDescription("Recuring Payment");

    $baseUrl = base_url();
    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl($baseUrl."payment/executePayment?success=true")
        ->setCancelUrl($baseUrl."payment/executePayment?success=false");

    $payment = new FuturePayment();
    $payment->setIntent("authorize")
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions(array($transaction));
    $authorization_code = $this->config['authorization_code'];
    $clientMetadataId = $this->config['client_metadata_id'];

    try {
        if($this->config['refreshToken']){
          $refreshToken = FuturePayment::getRefreshToken($authorization_code, $this->apiContext);
          // Update the access token in apiContext
          $payment->updateAccessToken($refreshToken, $this->apiContext);
          $this->config['authorization_code'] = $refreshToken;
        }
        $payment->create($this->apiContext, $clientMetadataId);
    } catch (Exception $ex) {
          $this->message = $ex->getMessage();
        return false;
    }
    return $payment;
}
好的,到现在为止它只是创建付款但不执行它?

执行付款需要做什么?

1 个答案:

答案 0 :(得分:0)

以下是LINKExecutePayment