Esempio n. 1
0
 public static function getApiContext($clientId, $clientSecret)
 {
     // #### SDK configuration
     // Register the sdk_config.ini file as the configuration source.
     //if(!defined("PP_CONFIG_PATH")) {
     //	define("PP_CONFIG_PATH", CONFIG_PATH); // CONFIG_PATH is defined in init.inc.php
     //}
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential($clientId, $clientSecret));
     $apiContext->setConfig(array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => LOGFILE_PP, 'log.LogLevel' => 'DEBUG', 'validation.level' => 'log', 'cache.enabled' => true));
     return $apiContext;
 }
Esempio n. 2
0
 function getApiContext()
 {
     // Define the location of the sdk_config.ini file
     if (!defined("PP_CONFIG_PATH")) {
         define("PP_CONFIG_PATH", dirname(__DIR__));
     }
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AXC-ruytoWCZuQkziPi--GNQyPRDWnmpfreOdG03cDdLv_PtefyX8Le3VGAVnkV87dJZ0eCvpjfBzZ3I', 'EA554cq5zJhgfbraN3X7jnaa_3j7bwO2IL9kRQ9yw2_1Smf62BpFh3mBgZ4JioL0iUGoCJia2_lGYStz'));
     // Alternatively pass in the configuration via a hashmap.
     // The hashmap can contain any key that is allowed in
     // sdk_config.ini
     $apiContext->setConfig(array('http.ConnectionTimeOut' => 30, 'http.Retry' => 1, 'mode' => 'sandbox', 'log.LogEnabled' => FALSE, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'INFO'));
     return $apiContext;
 }
Esempio n. 3
0
 public function process()
 {
     $sdkConfig = array("mode" => "sandbox");
     // After Step 1
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AXg9iE-m2XOToUfY4sQ7V1vjQ7cSDnQjiop4aj-M7pgB3hO3ObTYVv8dL51FDkxNsX-Ov8N6p22RD6lS', 'ECRT-ONUf7gq42vbEG1lm9yrbvq1kTXFTCwbQuLiB9TFwZm15KvsBharvgUlR6Dls8sbeaiAWsgsfEHB'));
     $apiContext->setConfig($sdkConfig);
     $this->setDummyState();
     $card_info = $this->getState()->get('card');
     $card = new \PayPal\Api\CreditCard();
     $card->setType($this->getCardType());
     $card->setNumber($card_info->number);
     $card->setExpireMonth($card_info->expire_month);
     $card->setExpireYear($card_info->expire_year);
     $card->setCvv2($card_info->cvv2);
     $fi = new \PayPal\Api\FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod("credit_card");
     $payer->setFundingInstruments(array($fi));
     // Specify the payment amount.
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency('GBP');
     $amount->setTotal($this->getState()->get('transaction.total'));
     // ###Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($this->getState()->get('payment.description'));
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     //  try {
     //      $payment->create($apiContext);
     //  } catch (PayPal\Exception\PayPalConnectionException $ex) {
     //      $this->_error->code = $ex->getCode(); // Prints the Error Code
     //      $this->_error->message = $ex->getData(); // Prints the detailed error message
     //  }
     $this->_payment = $payment;
     $this->status = $this->_payment->getState();
     $this->transaction_id = $payment->transactions[0]->related_resources[0]->sale->id;
     $this->amount = $payment->transactions[0]->amount->total;
     return $this;
 }
Esempio n. 4
0
     $paypal_secret = $data["value"];
 }
 $query = 'SELECT * FROM `nodes_config` WHERE `name` = "paypal_test"';
 $res = engine::mysql($query);
 $data = mysql_fetch_array($res);
 if ($data["value"]) {
     $sdkConfig = array("mode" => "sandbox");
 }
 if (!empty($_REQUEST["amount"])) {
     $sum = doubleval($_REQUEST["amount"]);
 } else {
     $sum = 1;
 }
 $cred = new PayPal\auth\OAuthTokenCredential($paypal_id, $paypal_secret, $sdkConfig);
 $apiContext = new PayPal\Rest\ApiContext($cred, 'Request' . time());
 $apiContext->setConfig($sdkConfig);
 $payer = new PayPal\API\Payer();
 $payer->setPaymentMethod('paypal');
 $amount = new PayPal\API\Amount();
 $amount->setCurrency('USD');
 $amount->setTotal($sum);
 $item1 = new PayPal\API\Item();
 $item1->setName($description)->setCurrency('USD')->setQuantity(1)->setPrice($sum);
 $item1->setSku($payment_id);
 $itemList = new PayPal\API\ItemList();
 $itemList->setItems(array($item1));
 $transaction = new PayPal\API\Transaction();
 $transaction->setAmount($amount);
 $transaction->setDescription('');
 $transaction->setItemList($itemList);
 $payment = new PayPal\API\Payment();
Esempio n. 5
0
<?php

require_once 'function.php';
require_once 'sdk/vendor/autoload.php';
// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AY_WvE4xZOUXLJKLW0sG0CijfhToPVJNZuUr9XpyedhJWEU81tYoWMhQgmxYnm_F-5BZWfEBP2QzuXA6', 'EMEjgxK4lsdgAYL0OAQvzAQ2adyxO9tyD-Ib_7exG2AvQmVX_noXeN_IoQjQK3wxAWbma6jFoA9cCm_3'));
// After Step 2
$creditCard = new \PayPal\Api\CreditCard();
$creditCard->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
// Step 2.1 : Between Step 2 and Step 3
$apiContext->setConfig(array('log.LogEnabled' => true, 'log.FileName' => 'PayPal.log', 'log.LogLevel' => 'FINE'));
// After Step 3
try {
    $creditCard->create($apiContext);
    display($creditCard);
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
    // This will print the detailed information on the exception.
    //REALLY HELPFUL FOR DEBUGGING
    display($ex->getData());
}
 private static function _setConfig(PayPal\Rest\ApiContext &$apiContext, $settings)
 {
     $apiContext->setConfig($settings);
 }
Esempio n. 7
0
 /**
  * @Route("/{id}/pay/")
  * @Method({"POST"})
  */
 public function finalizePayment(Request $request, $id)
 {
     try {
         $cred = $request->request->get('access_token');
         $payment_id = $request->request->get('payment_id');
         $payer_id = $request->request->get('payer_id');
         if (!$cred || !$payment_id || !$payer_id) {
             throw new Error();
         }
     } catch (Exception $ex) {
         return $this->fail();
     }
     $order = $this->getOrderManager()->findById($id);
     if (!$order) {
         return $this->fail();
     }
     if ($order->getDeposited() && $order->getPaid()) {
         return $this->fail();
     }
     $clientId = $this->container->getParameter('paypal_client_id');
     $secret = $this->container->getParameter('paypal_secret');
     $sdkConfig = $this->container->getParameter('paypal_sdk_config');
     $cred = new \PayPal\Auth\OAuthTokenCredential($clientId, $secret);
     $apiContext = new \PayPal\Rest\ApiContext($cred);
     $apiContext->setConfig($sdkConfig);
     $payment = new \PayPal\Api\Payment();
     $payment->setId($payment_id);
     $execution = new \PayPal\Api\PaymentExecution();
     $execution->setPayerId($payer_id);
     try {
         $payment->execute($execution, $apiContext);
     } catch (Exception $ex) {
         return $this->fail();
     }
     $transaction = new Transaction($payment_id, new \DateTime('now'));
     if (!$order->getDeposited()) {
         $order->setDeposited(true);
         $order->setDeposit($transaction);
     } else {
         $order->setPaid(true);
         $order->setPayment($transaction);
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($transaction);
     $em->persist($order);
     $em->flush();
     return $this->succeed();
 }
Esempio n. 8
0
 protected function paypal()
 {
     $configuration = Registry::get("configuration");
     $parsed = $configuration->parse("configuration/payment");
     if (!empty($parsed->payment->paypal) && !empty($parsed->payment->paypal->clientid)) {
         $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential($parsed->payment->paypal->clientid, $parsed->payment->paypal->secret));
         $apiContext->setConfig(array('mode' => 'live'));
         return $apiContext;
     }
 }
 private static function getApiContext(Config $config)
 {
     /*
      * Set up the context configuration
      */
     $contextConfig = array('mode' => $config->EndpointMode, 'log.LogEnabled' => false);
     // if logs are enable
     if ($config->EnableLog) {
         $contextConfig['log.LogEnabled'] = true;
         $contextConfig['log.FileName'] = $config->LogFilename;
         $contextConfig['log.LogLevel'] = "FINE";
         $contextConfig['validation.level'] = "log";
     }
     /*
      * Build the context object and return it
      */
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential($config->ClientId, $config->ClientSecret));
     $apiContext->setConfig($contextConfig);
     return $apiContext;
 }
function apiContext()
{
    $apiContext = new PayPal\Rest\ApiContext(new PayPal\Auth\OAuthTokenCredential(CLIENT_ID, CLIENT_SECRET));
    $apiContext->setConfig(array('mode' => 'live', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => 'PayPal.log', 'log.LogLevel' => 'FINE', 'validation.level' => 'log'));
    return $apiContext;
}