Add back interface methods for new payment flows

This commit is contained in:
David Bomba 2024-09-04 13:48:23 +10:00
parent 4e59f4d8a8
commit cba76cd608
16 changed files with 427 additions and 303 deletions

View File

@ -101,7 +101,10 @@ class ActivityExport extends BaseExport
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->company->settings));
$this->date_format = DateFormat::find($this->company->settings->date_format_id)->format;
/** @var \App\Models\DateFormat $df */
$df = DateFormat::query()->find($this->company->settings->date_format_id);
$this->date_format = $df->format;
if (count($this->input['report_keys']) == 0) {
$this->input['report_keys'] = array_values($this->entity_keys);

View File

@ -845,7 +845,7 @@ class BaseExport
/**
* Apply Product Filters
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return Builder
*/
@ -870,7 +870,7 @@ class BaseExport
/**
* Add Client Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $clients
*
* @return Builder
@ -893,7 +893,7 @@ class BaseExport
/**
* Add Vendor Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $vendors
*
* @return Builder
@ -917,7 +917,7 @@ class BaseExport
/**
* AddProjectFilter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $projects
*
* @return Builder
@ -941,7 +941,7 @@ class BaseExport
/**
* Add Category Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $expense_categories
*
* @return Builder
@ -966,7 +966,7 @@ class BaseExport
/**
* Add Payment Status Filters
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status
*
* @return Builder
@ -1024,10 +1024,10 @@ class BaseExport
/**
* Add RecurringInvoice Status Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status
*
* @return Builder
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function addRecurringInvoiceStatusFilter(Builder $query, string $status): Builder
{
@ -1067,7 +1067,7 @@ class BaseExport
/**
* Add QuoteStatus Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status
*
* @return Builder
@ -1133,7 +1133,7 @@ class BaseExport
/**
* Add PurchaseOrder Status Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status
*
* @return Builder
@ -1183,7 +1183,7 @@ class BaseExport
/**
* Add Invoice Status Filter
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status
* @return Builder
*/
@ -1249,7 +1249,7 @@ class BaseExport
/**
* Add Date Range
*
* @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $query
* @param ?string $table_name
* @return Builder
*/

View File

@ -278,12 +278,12 @@ class RotessaPaymentDriver extends BaseDriver
return $this->company_gateway->getConfigField('testMode') ? 'https://sandbox-api.rotessa.com/v1/' : 'https://api.rotessa.com/v1/';
}
public function processPaymentViewData(array $data)
public function processPaymentViewData(array $data): array
{
return $this->payment_method->paymentData($data);
}
public function livewirePaymentView(array $data)
public function livewirePaymentView(array $data): string
{
return $this->payment_method->livewirePaymentView($data);
}

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class Bancontact
class Bancontact implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,32 +38,7 @@ class Bancontact
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['bancontact'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::BANCONTACT,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.bancontact.pay', $data);
}
@ -143,4 +119,41 @@ class Bancontact
throw new PaymentFailed('Failed to process the payment.', 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['bancontact'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::BANCONTACT,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.bancontact.pay_livewire';
}
}

View File

@ -19,12 +19,13 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Number;
use App\Utils\Traits\MakesHash;
use Stripe\PaymentIntent;
class BankTransfer
class BankTransfer implements LivewireMethodInterface
{
use MakesHash;
@ -38,37 +39,7 @@ class BankTransfer
public function paymentView(array $data)
{
$this->stripe->init();
$intent = \Stripe\PaymentIntent::create([
'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
'currency' => $this->stripe->client->currency()->code,
'customer' => $this->stripe->findOrCreateCustomer()->id,
'description' => $this->stripe->getDescription(false),
'payment_method_types' => ['customer_balance'],
'payment_method_data' => [
'type' => 'customer_balance',
],
'payment_method_options' => [
'customer_balance' => [
'funding_type' => 'bank_transfer',
'bank_transfer' => $this->resolveBankType()
],
],
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::DIRECT_DEBIT,
],
], $this->stripe->stripe_connect_auth);
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency())]);
$this->stripe->payment_hash->save();
$data = [];
$data['return_url'] = $this->buildReturnUrl();
$data['gateway'] = $this->stripe;
$data['client_secret'] = $intent ? $intent->client_secret : false;
$data = $this->paymentData($data);
return render('gateways.stripe.bank_transfer.pay', $data);
}
@ -317,4 +288,46 @@ class BankTransfer
throw new PaymentFailed('Failed to process the payment.', 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$intent = \Stripe\PaymentIntent::create([
'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
'currency' => $this->stripe->client->currency()->code,
'customer' => $this->stripe->findOrCreateCustomer()->id,
'description' => $this->stripe->getDescription(false),
'payment_method_types' => ['customer_balance'],
'payment_method_data' => [
'type' => 'customer_balance',
],
'payment_method_options' => [
'customer_balance' => [
'funding_type' => 'bank_transfer',
'bank_transfer' => $this->resolveBankType()
],
],
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::DIRECT_DEBIT,
],
], $this->stripe->stripe_connect_auth);
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency())]);
$this->stripe->payment_hash->save();
$data = [];
$data['return_url'] = $this->buildReturnUrl();
$data['gateway'] = $this->stripe;
$data['client_secret'] = $intent ? $intent->client_secret : false;
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.bank_transfer.pay_livewire';
}
}

View File

@ -19,6 +19,7 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\Common\MethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Ninja;
@ -29,7 +30,7 @@ use Stripe\ApplePayDomain;
use Stripe\Exception\ApiErrorException;
use Stripe\PaymentIntent;
class BrowserPay implements MethodInterface
class BrowserPay implements MethodInterface, LivewireMethodInterface
{
protected StripePaymentDriver $stripe;
@ -64,7 +65,8 @@ class BrowserPay implements MethodInterface
return redirect()->route('client.payment_methods.index');
}
public function paymentView(array $data): View
public function paymentData(array $data): array
{
$payment_intent_data = [
'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
@ -93,6 +95,13 @@ class BrowserPay implements MethodInterface
'requestPayerEmail' => true,
];
return $data;
}
public function paymentView(array $data): View
{
$data = $this->paymentData($data);
return render('gateways.stripe.browser_pay.pay', $data);
}
@ -153,7 +162,7 @@ class BrowserPay implements MethodInterface
$this->stripe->client->company,
);
return redirect()->route('client.payments.show', ['payment' => $payment->hashed_id]);
return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]);
}
/**
@ -231,4 +240,9 @@ class BrowserPay implements MethodInterface
return str_replace(['https://', '/public'], '', $domain);
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.browser_pay.pay_livewire';
}
}

View File

@ -19,12 +19,13 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\Stripe\Jobs\UpdateCustomer;
use App\PaymentDrivers\StripePaymentDriver;
use Stripe\PaymentIntent;
use Stripe\PaymentMethod;
class CreditCard
class CreditCard implements LivewireMethodInterface
{
public $stripe;
@ -57,7 +58,7 @@ class CreditCard
return redirect()->route('client.payment_methods.index');
}
public function paymentView(array $data)
public function paymentData(array $data): array
{
$description = $this->stripe->getDescription(false);
@ -77,9 +78,21 @@ class CreditCard
$data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data);
$data['gateway'] = $this->stripe;
return $data;
}
public function paymentView(array $data)
{
$data = $this->paymentData($data);
return render('gateways.stripe.credit_card.pay', $data);
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.credit_card.pay_livewire';
}
public function paymentResponse(PaymentResponseRequest $request)
{
$this->stripe->init();
@ -160,7 +173,7 @@ class CreditCard
}
}
return redirect()->route('client.payments.show', ['payment' => $payment->hashed_id]);
return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]);
}
public function processUnsuccessfulPayment($server_response)

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class EPS
class EPS implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,31 +38,7 @@ class EPS
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['eps'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::EPS,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.eps.pay', $data);
}
@ -142,4 +119,40 @@ class EPS
throw new PaymentFailed('Failed to process the payment.', 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['eps'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::EPS,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.eps.pay_livewire';
}
}

View File

@ -19,9 +19,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class FPX
class FPX implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -38,31 +39,7 @@ class FPX
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => $this->stripe->client->getCurrencyCode(),
'payment_method_types' => ['fpx'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::FPX,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.fpx.pay', $data);
}
@ -143,4 +120,40 @@ class FPX
throw new PaymentFailed('Failed to process the payment.', 400);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => $this->stripe->client->getCurrencyCode(),
'payment_method_types' => ['fpx'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::FPX,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.fpx.pay_livewire';
}
}

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class GIROPAY
class GIROPAY implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,31 +38,7 @@ class GIROPAY
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['giropay'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::GIROPAY,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.giropay.pay', $data);
}
@ -176,6 +153,6 @@ class GIROPAY
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.giropay.pay_livewire';
return 'gateways.giropay.pay_livewire';
}
}

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class Klarna
class Klarna implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,33 +38,7 @@ class Klarna
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$description = $this->stripe->getDescription(false);
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => $this->stripe->client->getCurrencyCode(),
'payment_method_types' => ['klarna'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $description,
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::KLARNA,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.klarna.pay', $data);
}
@ -142,4 +117,42 @@ class Klarna
throw new PaymentFailed(ctrans('texts.gateway_error'), 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$description = $this->stripe->getDescription(false);
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => $this->stripe->client->getCurrencyCode(),
'payment_method_types' => ['klarna'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $description,
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::KLARNA,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.klarna.pay_livewire';
}
}

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class PRZELEWY24
class PRZELEWY24 implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,31 +38,7 @@ class PRZELEWY24
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['p24'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::PRZELEWY24,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.przelewy24.pay', $data);
}
@ -142,4 +119,40 @@ class PRZELEWY24
throw new PaymentFailed('Failed to process the payment.', 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['p24'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::PRZELEWY24,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.przelewy24.pay_livewire';
}
}

View File

@ -19,9 +19,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class SEPA
class SEPA implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -47,33 +48,7 @@ class SEPA
public function paymentView(array $data)
{
$data['gateway'] = $this->stripe;
$data['payment_method_id'] = GatewayType::SEPA;
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$data['payment_hash'] = $this->stripe->payment_hash->hash;
$intent_data = [
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['sepa_debit'],
'setup_future_usage' => 'off_session',
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::SEPA,
],
];
$intent = \Stripe\PaymentIntent::create($intent_data, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.sepa.pay', $data);
}
@ -176,4 +151,42 @@ class SEPA
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
}
}
public function paymentData(array $data): array
{
$data['gateway'] = $this->stripe;
$data['payment_method_id'] = GatewayType::SEPA;
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$data['payment_hash'] = $this->stripe->payment_hash->hash;
$intent_data = [
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['sepa_debit'],
'setup_future_usage' => 'off_session',
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::SEPA,
],
];
$intent = \Stripe\PaymentIntent::create($intent_data, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.sepa.pay_livewire';
}
}

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class SOFORT
class SOFORT implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,31 +38,7 @@ class SOFORT
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['sofort'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::SOFORT,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.sofort.pay', $data);
}
@ -137,4 +114,40 @@ class SOFORT
throw new PaymentFailed('Failed to process the payment.', 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['sofort'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::SOFORT,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.sofort.pay_livewire';
}
}

View File

@ -18,9 +18,10 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\StripePaymentDriver;
class iDeal
class iDeal implements LivewireMethodInterface
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
@ -37,31 +38,7 @@ class iDeal
public function paymentView(array $data)
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['ideal'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::IDEAL,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
$data = $this->paymentData($data);
return render('gateways.stripe.ideal.pay', $data);
}
@ -142,4 +119,40 @@ class iDeal
throw new PaymentFailed('Failed to process the payment.', 500);
}
public function paymentData(array $data): array
{
$this->stripe->init();
$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, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['ideal'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->getDescription(false),
'metadata' => [
'payment_hash' => $this->stripe->payment_hash->hash,
'gateway_type_id' => GatewayType::IDEAL,
],
], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return $data;
}
public function livewirePaymentView(array $data): string
{
return 'gateways.stripe.ideal.pay_livewire';
}
}