Example #1
0
 /**
  * Products Constructor
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('Bedard.Shop', 'shop', 'customers');
     $this->addCss('/plugins/bedard/shop/assets/css/backend.css');
     // Load currency
     $this->vars['currency'] = PaySettings::get('currency_symbol');
 }
Example #2
0
 /**
  * Opens an omnipay gateway for Paypal Express
  * @return  Omnipay
  */
 public function openPaypalExpressGateway()
 {
     $gateway = Omnipay::create('PayPal_Express');
     $gateway->setUsername(PaySettings::get('paypal_express_username'));
     $gateway->setPassword(PaySettings::get('paypal_express_password'));
     $gateway->setSignature(PaySettings::get('paypal_express_signature'));
     if (PaySettings::get('paypal_express_sandbox')) {
         $gateway->setTestMode(true);
     }
     return $gateway;
 }
Example #3
0
 /**
  * Calls the purchase method with Omnipay
  * @param   Order       $order
  * @param   CartModel   $cart
  * @param   CreditCard  $card
  * @return  Redirect
  */
 private function beginPaypalCheckout(Order $order, CartModel $cart, CreditCard $card)
 {
     try {
         $gateway = $this->openPaypalExpressGateway();
         $items = $this->getItems($order, $cart);
         $response = $gateway->purchase(['returnUrl' => $this->property('returnUrl'), 'cancelUrl' => $this->property('canceledUrl'), 'amount' => number_format($cart->total, 2), 'currency' => PaySettings::get('currency_code')])->setItems($items)->setShippingAmount('0.00')->setCard($card)->setAddressOverride(1)->setNoShipping(2)->send();
         if ($response->isRedirect()) {
             return Redirect::to($response->getRedirectUrl());
         } else {
             throw new Exception('Invalid response');
         }
     } catch (Exception $e) {
         Log::error('Failed to begin checkout on cart #' . $cart->id, ['gateway' => 'Paypal Express', 'message' => $e->getMessage(), 'timestamp' => time()]);
         return Redirect::to($this->property('canceledUrl'));
     }
 }
Example #4
0
 /**
  * Attempt to complete the purchase
  * @return  Redirect
  */
 public function onRun()
 {
     try {
         $gateway = $this->openPaypalExpressGateway();
         $session = Session::get('bedard_shop_order');
         $order = Order::where('hash', $session['hash'])->where('is_complete', false)->find($session['id']);
         $response = $gateway->completePurchase(['amount' => $order->amount, 'currency' => PaySettings::get('currency_code')])->send();
         $data = $response->getData();
         $order->gateway_code = $data['PAYMENTINFO_0_TRANSACTIONID'];
         if ($response->isSuccessful()) {
             $order->cart->markAsComplete($order);
         } else {
             throw new Exception('Failed response from PayPal.');
         }
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
Example #5
0
 /**
  * Discounts Index
  */
 public function index()
 {
     $this->vars['currency'] = PaySettings::get('currency_symbol');
     $this->asExtension('ListController')->index();
 }