Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo n.º 4
0
 } else {
     $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);
Ejemplo 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());
}
Ejemplo n.º 6
0
            $anhang["type"] = mime_content_type($pfad);
        } else {
            $anhang["type"] = "application/octet-stream";
        }
        $anrede = $row->anrede == "Frau" ? "geehrte Frau" : "geehrter Herr";
        mail_att($row->email, "Alma Mater Wear: Ihre Rechnung", html_mail($paymentId), $anhang);
        //PayPal SDK konfogurieren
        $sdkConfig = array("mode" => "sandbox");
        if (USE_LIVE_PAYMENT) {
            $sdkConfig["mode"] = "live";
        }
        //Bezahlvorgang abschließen
        if (USE_LIVE_PAYMENT) {
            // actual client ID and secret
            $cred = new \PayPal\Auth\OAuthTokenCredential("Ac_RSNJ2Ss-8Ba7X3TIrveIa-g5p_E_7J_7BukY-_q2MwutfbVvLQAhBHF89Ri2LzHeRtOSZRNPSSG7l", "EK91XgzYqNA-bqlzWQndkXaKw8_tl1ENjSVrW3htCQFZV7sGk6_5mcJGqCcYQizVPUSvMVwIHIh4lymQ", $sdkConfig);
        } else {
            //sandbox stuff
            $cred = new \PayPal\Auth\OAuthTokenCredential("ATNYSszAJLwQn-K4tIPlrVFsR5bKiAN6I07AQkR5pRh-tNllccoGn7bzRtcTZpjM6BgeAfKBAoSpS2sC", "EJQp7OmMT9pjTehZFOvHq5y2aBe5WQlelGH3MZSnd6XFPWdAB9ctwya3OKX9kWFaYTQTR8Vo0m47VPc6", $sdkConfig);
        }
        $apiContext = new \PayPal\Rest\ApiContext($cred, 'Request' . time());
        $apiContext->setConfig($sdkConfig);
        $payment = new \PayPal\Api\Payment();
        $payment->setId($paymentId);
        $execution = new \PayPal\Api\PaymentExecution();
        $execution->setPayerId("{$payerId}");
        $response = $payment->execute($execution, $apiContext);
        // var_dump($response);
        // header("Location: shop.html?checkout=success");
    }
}
//SOFORT wird separat abgewickelt
Ejemplo n.º 7
0
 private static function _getCredential(PayPal\Rest\ApiContext &$apiContext)
 {
     return $apiContext->getCredential();
 }
Ejemplo n.º 8
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();
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 11
0
<?php

header('Content-Type: text/html; charset=utf-8');
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__ . '/vendor/autoload.php';
// Use below for direct download installation
// require __DIR__  . '/vendor/autoload.php';
$apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL'));
$apiContext->setConfig(array('log.LogEnabled' => true, 'log.FileName' => 'PayPal.log', 'log.LogLevel' => 'FINE'));
function getOrderDatesThroughToken($pdo, $token)
{
    $sql = "SELECT orders.id, value, code, shipping, order_user.name, order_user.email FROM orders\n    INNER JOIN order_token ON \n    orders.id = order_token.orderId \n    INNER JOIN currency ON \n    orders.currency = currency.id \n    INNER JOIN order_user ON \n    orders.userId = order_user.id \n    WHERE token = '" . $token . "'";
    // check given order`s value
    $orderValue = $pdo->prepare($sql);
    $orderValue->execute();
    $final = $orderValue->fetch();
    return $final;
}
function updateErrorInPayment($pdo, $orderName)
{
    $sql = "UPDATE orders SET order_status = 3\n    WHERE id = " . $orderName;
    $orderValue = $pdo->prepare($sql);
    $orderValue->execute();
}
function getBaseUrl()
{
    if (PHP_SAPI == 'cli') {
        $trace = debug_backtrace();
        $relativePath = substr(dirname($trace[0]['file']), strlen(dirname(dirname(__FILE__))));
        echo "Warning: This sample may require a server to handle return URL. Cannot execute in command line. Defaulting URL to http://localhost{$relativePath} \n";
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;
}
     $_SESSION['shipping_street2'] = isset($_SESSION['billing_street2']) ? $_SESSION['billing_street2'] : '';
     $_SESSION['shipping_city'] = isset($_SESSION['billing_city']) ? $_SESSION['billing_city'] : '';
     $_SESSION['shipping_state'] = isset($_SESSION['billing_state']) ? $_SESSION['billing_state'] : '';
     $_SESSION['shipping_postal_code'] = isset($_SESSION['billing_postal_code']) ? $_SESSION['billing_postal_code'] : '';
     $_SESSION['shipping_country_code'] = isset($_SESSION['billing_country_code']) ? $_SESSION['billing_country_code'] : '';
 }
 $_SESSION['amount'] = isset($_POST['GrandTotal']) ? str_replace(",", "", $_POST['GrandTotal']) : '0.00';
 $_SESSION['subtotal'] = isset($_POST['NetAmount']) ? str_replace(",", "", $_POST['NetAmount']) : '0.00';
 $_SESSION['shipping_amount'] = isset($_POST['ShippingAmount']) && $_POST['ShippingAmount'] != '' ? str_replace(",", "", $_POST['ShippingAmount']) : '0.00';
 $_SESSION['handling_amount'] = isset($_POST['HandlingAmount']) && $_POST['HandlingAmount'] != '' ? str_replace(",", "", $_POST['HandlingAmount']) : '0.00';
 $_SESSION['tax_amount'] = isset($_POST['TaxAmount']) && $_POST['TaxAmount'] != '' ? str_replace(",", "", $_POST['TaxAmount']) : '0.00';
 $_SESSION['billingInfo'] = isset($_POST['billingInfo']) ? $_POST['billingInfo'] : array();
 $_SESSION['shippingInfo'] = isset($_POST['shippingInfo']) ? $_POST['shippingInfo'] : array();
 ##########[ Create Payment ]############
 // Create new PayPal Api Context
 $paypal_rest = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential($config['RESTAPIClient_Id'], $config['RESTAPIClient_Secret']));
 // Add to header
 $paypal_rest->addRequestHeader('PayPal-Partner-Attribution-Id', 'AngellEYE_SP_POS_VT');
 $addr = new \PayPal\Api\Address();
 $addr->setLine1($_SESSION['billing_street1']);
 $addr->setLine2($_SESSION['billing_street2']);
 $addr->setCity($_SESSION['billing_city']);
 $addr->setCountryCode($_SESSION['billing_country_code']);
 $addr->setPostalCode($_SESSION['billing_postal_code']);
 $addr->setState($_SESSION['billing_state']);
 $card = new \PayPal\Api\CreditCard();
 $card->setNumber($_SESSION['cc_number']);
 $card->setType(strtolower($_SESSION['cc_type']));
 $card->setExpireMonth($_SESSION['cc_exp_month']);
 $card->setExpireYear($_SESSION['cc_exp_year']);
 $card->setCvv2($_SESSION['cvv2']);