stripe = $stripe; } public function paymentView(array $data) { $data['gateway'] = $this->stripe; $data['return_url'] = $this->buildReturnUrl($data); $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['amount_with_fee'], $this->stripe->client->currency()->precision); $data['client'] = $this->stripe->client; $data['country'] = $this->stripe->client->country->iso_3166_2; return render('gateways.stripe.sofort.pay', $data); } private function buildReturnUrl($data): string { return route('client.payments.response', [ 'company_gateway_id' => $this->stripe->company_gateway->id, 'gateway_type_id' => GatewayType::SOFORT, 'hashed_ids' => implode(",", $data['hashed_ids']), 'amount' => $data['amount'], 'fee' => $data['fee'], ]); } public function paymentResponse($request) { $state = array_merge($request->all(), []); $amount = $state['amount'] + $state['fee']; $state['amount'] = $this->stripe->convertToStripeAmount($amount, $this->stripe->client->currency()->precision); if ($request->redirect_status == 'succeeded') { return $this->processSuccessfulPayment($state); } return $this->processUnsuccessfulPayment($state); } public function processSuccessfulPayment($state) { $state['charge_id'] = $state['source']; $this->stripe->init(); $state['payment_type'] = PaymentType::SOFORT; $data = [ 'payment_method' => $state['charge_id'], 'payment_type' => $state['payment_type'], 'amount' => $state['amount'], 'gateway_type_id' => GatewayType::SOFORT, ]; $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); /** @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */ if (isset($state['hashed_ids'])) { $this->stripe->attachInvoices($payment, $state['hashed_ids']); } event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state, 'data' => $data ]; SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client); return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } public function processUnsuccessfulPayment($state) { return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_cancelled')); } }