/** * @throws CardDeclinedException * @throws UnknownErrorException */ public function takePayment() { $settings = ClientHelper::getPaymentGatewayInfo('stripe'); $clientInfo = ClientHelper::getClientInfo(); Stripe::setApiKey($settings->sandbox_mode ? $settings->test_secret : $settings->secret); // Create the charge on Stripe's servers - this will charge the user's card try { $charge = Charge::create(array("amount" => $this->order->getTotalPrice(), "currency" => $clientInfo->currency->currency_iso, "source" => $this->stripeToken, "description" => $clientInfo->name, "metadata" => ["order_id" => $this->order->getId()])); $payment = new Payment($this->order->getTotalPrice(), date("Y-m-d"), 'stripe', $charge->getLastResponse()->body); $this->order->addPayment($payment); $this->orderRepository->save($this->order); } catch (Card $e) { throw new CardDeclinedException(); } catch (\Exception $e) { dd($e); throw new UnknownErrorException($e->getMessage()); } }
public function checkout(View $view) { $paymentGateways = ClientHelper::getPaymentGatewayInfo(); $view->with('paymentGateways', $paymentGateways); }
private function setApiContext() { $settings = ClientHelper::getPaymentGatewayInfo('paypal'); $client_id = $settings->sandbox_mode ? $settings->test_client_id : $settings->client_id; $secret = $settings->sandbox_mode ? $settings->test_secret : $settings->secret; $this->apiContext = new ApiContext(new OAuthTokenCredential($client_id, $secret)); $this->apiContext->setConfig(['mode' => $settings->sandbox_mode ? 'sandbox' : 'live', 'log.FileName' => './storage/logs/paypal.log', 'log.LogLevel' => $settings->sandbox_mode ? 'DEBUG' : 'INFO', 'cache.enabled' => false]); }