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)];
         }
     }
 }
Exemplo n.º 2
0
 public function on_start()
 {
     Route::register('/paypal_express_vivid_store/return', 'Concrete\\Package\\PaypalExpressVividStore\\Src\\PaypalHandler::paypal_return');
     Route::register('/paypal_express_vivid_store/notify', 'Concrete\\Package\\PaypalExpressVividStore\\Src\\PaypalHandler::paypal_notify');
     Route::register('/paypal_express_vivid_store/cancel', 'Concrete\\Package\\PaypalExpressVividStore\\Src\\PaypalHandler::paypal_cancel');
     Events::addListener('on_vividstore_order', function ($event) {
         $order = $event->getCurrentOrder();
         //TODO: maybe try to get the payment method handle
         if ($order->getPaymentMethodName() == 'Paypal Express') {
             $invoice = Invoice::get();
             $oID = $order->getOrderID();
             Invoice::setOrderID($invoice, $oID);
             Invoice::remove();
         }
     });
 }