2015-11-25 2 views
0

Я выполнил все инструкции here , чтобы создать будущую оплату в моей заявке.PayPal PHP SDK создает будущую оплату

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

ОК, до сих пор он просто создает платеж, но не выполняет его?

Что мне нужно сделать, чтобы выполнить платеж?

ответ

Смежные вопросы