stripe = $stripe; } public function authorizeView($data) { return render('gateways.stripe.sofort.authorize', $data); } public function paymentView(array $data) { $data['gateway'] = $this->stripe; $data['return_url'] = $this->buildReturnUrl(); $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision); $data['client'] = $this->stripe->client; $data['country'] = $this->stripe->client->country->iso_3166_2; $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); $this->stripe->payment_hash->save(); return render('gateways.stripe.sofort.pay', $data); } private function buildReturnUrl(): string { return route('client.payments.response', [ 'company_gateway_id' => $this->stripe->company_gateway->id, 'payment_hash' => $this->stripe->payment_hash->hash, 'payment_method_id' => GatewayType::SOFORT, ]); } public function paymentResponse($request) { $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all()); $this->stripe->payment_hash->save(); if ($request->redirect_status == 'succeeded') { return $this->processSuccessfulPayment($request->source); } return $this->processUnsuccessfulPayment(); } public function processSuccessfulPayment(string $source) { /* @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */ $this->stripe->init(); $data = [ 'payment_method' => $this->stripe->payment_hash->data->source, 'payment_type' => PaymentType::SOFORT, 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision), 'transaction_reference' => $source, 'gateway_type_id' => GatewayType::SOFORT, ]; $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( ['response' => $this->stripe->payment_hash->data, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client, $this->stripe->client->company, ); return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } public function processUnsuccessfulPayment() { $server_response = $this->stripe->payment_hash->data; PaymentFailureMailer::dispatch( $this->stripe->client, $server_response, $this->stripe->client->company, $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision) ); $message = [ 'server_response' => $server_response, 'data' => $this->stripe->payment_hash->data, ]; SystemLogger::dispatch( $message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client, $this->stripe->client->company, ); throw new PaymentFailed('Failed to process the payment.', 500); } }