Ejemplo n.º 1
0
 public function paypal_notify()
 {
     $crypt = Loader::helper('encryption');
     $paypal = new \Concrete\Package\PaypalExpressVividStore\Src\VividStore\Payment\Methods\PaypalExpress\Helpers\PaypalExpressHelper();
     if (Config::get('vividstore.paypalExpressMode') == 'test') {
         $type = 'sandbox';
     } else {
         $type = 'live';
     }
     $conf = ['type' => $type];
     $paypal->setConfig($conf);
     if ($paypal->validateIPN()) {
         if (Config::get('vividstore.paypalExpressTransactionType') == "Authorization") {
             $status_message = strtolower($_REQUEST['auth_status']);
         } else {
             $status_message = strtolower($_REQUEST['payment_status']);
         }
         if ($status_message == 'completed') {
             $status = OrderStatus::getByHandle('complete');
         } elseif ($status_message == 'denied' || $status_message == 'reversed') {
             $status = OrderStatus::getByHandle('complete');
         }
         $crypt = Loader::helper('encryption');
         $invoice = $crypt->decrypt($_REQUEST['invoice']);
         $oID = Invoice::getOrderID($invoice);
         $order = Order::getById($oID);
         if ($order) {
             $order->updateStatus($status);
         }
     }
 }
 public function submitPayment()
 {
     $crypt = Loader::helper('encryption');
     $paypal = new \Concrete\Package\PaypalExpressVividStore\Src\VividStore\Payment\Methods\PaypalExpress\Helpers\PaypalExpressHelper();
     $totals = VividCart::getTotals();
     if (Config::get('vividstore.paypalExpressMode') == 'test') {
         $type = 'sandbox';
     } else {
         $type = 'live';
     }
     $invoice = Invoice::get();
     $conf = ['type' => $type, 'username' => Config::get('vividstore.paypalExpressUsername'), 'password' => Config::get('vividstore.paypalExpressPassword'), 'signature' => Config::get('vividstore.paypalExpressSignature'), 'notify_url' => (string) URL::to('/paypal_express_vivid_store/notify'), 'cancel_url' => (string) URL::to('/paypal_express_vivid_store/cancel'), 'return_url' => (string) URL::to('/paypal_express_vivid_store/return'), 'cart_total' => $totals['total'], 'cart_subtotal' => $totals['subTotal'], 'cart_tax' => $totals['taxTotal'], 'cart_shipping' => $totals['shippingTotal'], 'invoice' => $crypt->encrypt($invoice), 'description' => t(SITE), 'currency_code' => Config::get('vividstore.paypalExpressCurrencyCode'), 'payment_action' => Config::get('vividstore.paypalExpressTransactionType')];
     $paypal->setConfig($conf);
     if (isset($_GET['token']) && isset($_GET['PayerID'])) {
         $token = urldecode($_GET['token']);
         $payer_id = urldecode($_GET['PayerID']);
         $data_get = $paypal->getExpressCheckout($token, $payer_id);
         $response = $paypal->makeRequest($data_get, $type);
         if ($response['ACK'] == 'Success') {
             $data_do = $paypal->doExpressCheckout($token, $payer_id);
             $response = $paypal->makeRequest($data_do, $type);
             if ($response['ACK'] == 'Success') {
                 return true;
             }
         }
     } else {
         $items = [];
         $cart = Session::get('cart');
         if ($cart) {
             foreach ($cart as $cartItem) {
                 $pID = $cartItem['product']['pID'];
                 $qty = $cartItem['product']['qty'];
                 $product = VividProduct::getByID($pID);
                 if (is_object($product)) {
                     $tempItem = [];
                     $tempItem['name'] = $product->getProductName();
                     $tempItem['desc'] = strip_tags($product->getProductDesc());
                     $tempItem['price'] = $product->getFormattedPrice();
                     $tempItem['qty'] = $qty;
                     $items[] = $tempItem;
                 }
             }
         }
         $configData = [];
         $configData['items'] = $items;
         $configData['item_sum'] = $totals['total'];
         $data = $paypal->setExpressCheckout($configData);
         $response = $paypal->makeRequest($data, $type);
         if ($response['ACK'] == 'Success') {
             //Redirect to paypal payment page
             header('Location: ' . $paypal->getPaypalUrl($response['TOKEN']));
             exit;
         } else {
             return ['error' => 1, 'errorMessage' => print_r($response, true)];
         }
     }
 }