/**
  * @param Request $http
  * @throws CheckoutException
  */
 public function processRequest(Request $http)
 {
     try {
         $response = \WebToPay::checkResponse($http->all(), array('projectid' => $this->projectId, 'sign_password' => $this->signPassword));
         if ($response['test'] !== '0') {
             //throw new CheckoutException('Testing, real payment was not made');
         }
         if ($response['type'] !== 'macro') {
             throw new CheckoutException('Only macro payment callbacks are accepted');
         }
         if ($response['orderid'] != $this->request->transaction) {
             throw new CheckoutException('Incorrect transaction');
         }
         if ($response['amount'] != $this->request->amount * 100) {
             throw new CheckoutException('Incorrect amount');
         }
         if ($response['currency'] != $this->request->currency) {
             throw new CheckoutException('Incorrect currency');
         }
         if ($this->request->status == TransactionData::PAID) {
             throw new CheckoutException('Transaction already done.');
         }
         TransactionData::update($this->request->transaction, ['date_paid' => time(), 'status' => TransactionData::PAID, 'gateway_response' => $response]);
         Callback::call($this->request);
         echo 'OK';
     } catch (CheckoutException $e) {
         throw new CheckoutException('Gateway got error', 500, $e);
     }
 }
 /**
  * @param $transactionId
  * @param Request $request
  * @throws CheckoutException
  */
 public function index($transactionId, Request $request)
 {
     $transaction = TransactionData::get($transactionId);
     if (empty($transaction->transaction)) {
         throw new CheckoutException('No transaction found!');
     }
     $gatewayClass = '\\Kiberzauras\\Checkout\\Gateway\\' . Provider::getGatewayName($transaction->provider) . "Gateway";
     (new $gatewayClass($transaction))->processRequest($request);
 }
Exemplo n.º 3
0
 /**
  * @param null $callback_url
  * @param null $accept_url
  * @param null $cancel_url
  * @throws CheckoutException
  */
 public function pay($callback_url = null, $accept_url = null, $cancel_url = null)
 {
     $this->callback_url = $callback_url;
     $this->accept_url = $accept_url;
     $this->cancel_url = $cancel_url;
     if (!$this->accept_url) {
         $this->accept_url = url('/');
     }
     if (!$this->cancel_url) {
         $this->cancel_url = url('/');
     }
     if (count($this->product_list) && $this->amount > 0) {
         throw new CheckoutException('Can\'t use setAmount() together with addProduct(), please choose only one.');
     }
     if (!$this->currency) {
         throw new CheckoutException('Currency code required');
     }
     $expose = [];
     if (count($this->product_list)) {
         $expose = $this->handleProducts();
     }
     if ($this->amount <= 0) {
         throw new CheckoutException('Amount (price) must be greater than zero');
     }
     if (count($this->recurring_setup)) {
         if (!in_array($this->provider, array(Provider::PAYPAL, Provider::BRAINTREE, Provider::GOOGLEWALLET))) {
             throw new CheckoutException('Your selected provider cant serve subscriptions');
         }
     }
     $this->request = get_object_vars($this);
     $this->request['product_list'] = $expose;
     unset($this->request['request']);
     $this->request = TransactionData::generate($this->request);
     $gatewayClass = '\\Kiberzauras\\Checkout\\Gateway\\' . Provider::getGatewayName($this->provider) . "Gateway";
     (new $gatewayClass($this->request))->startPayment();
 }