Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/Payment/Stripe.php
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | public function createMandate(Wallet $wallet, array $payment): ?array | ||||
]; | ]; | ||||
// Note: Stripe does not allow to set amount for 'setup' operation | // Note: Stripe does not allow to set amount for 'setup' operation | ||||
// We'll dispatch WalletCharge job when we receive a webhook request | // We'll dispatch WalletCharge job when we receive a webhook request | ||||
$session = StripeAPI\Checkout\Session::create($request); | $session = StripeAPI\Checkout\Session::create($request); | ||||
$payment['amount'] = 0; | $payment['amount'] = 0; | ||||
$payment['credit_amount'] = 0; | |||||
$payment['currency_amount'] = 0; | $payment['currency_amount'] = 0; | ||||
$payment['vat_rate_id'] = null; | |||||
$payment['id'] = $session->setup_intent; | $payment['id'] = $session->setup_intent; | ||||
$payment['type'] = self::TYPE_MANDATE; | $payment['type'] = self::TYPE_MANDATE; | ||||
$this->storePayment($payment, $wallet->id); | $this->storePayment($payment, $wallet->id); | ||||
return [ | return [ | ||||
'id' => $session->id, | 'id' => $session->id, | ||||
]; | ]; | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | class Stripe extends \App\Providers\PaymentProvider | ||||
{ | { | ||||
if ($payment['type'] == self::TYPE_RECURRING) { | if ($payment['type'] == self::TYPE_RECURRING) { | ||||
return $this->paymentRecurring($wallet, $payment); | return $this->paymentRecurring($wallet, $payment); | ||||
} | } | ||||
// Register the user in Stripe, if not yet done | // Register the user in Stripe, if not yet done | ||||
$customer_id = self::stripeCustomerId($wallet, true); | $customer_id = self::stripeCustomerId($wallet, true); | ||||
$amount = $this->exchange($payment['amount'], $wallet->currency, $payment['currency']); | $amount = $this->exchange($payment['amount'], $wallet->currency, $payment['currency']); | ||||
$payment['currency_amount'] = $amount; | $payment['currency_amount'] = $amount; | ||||
$request = [ | $request = [ | ||||
'customer' => $customer_id, | 'customer' => $customer_id, | ||||
'cancel_url' => self::redirectUrl(), // required | 'cancel_url' => self::redirectUrl(), // required | ||||
'success_url' => self::redirectUrl(), // required | 'success_url' => self::redirectUrl(), // required | ||||
'payment_method_types' => ['card'], // required | 'payment_method_types' => ['card'], // required | ||||
▲ Show 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | protected static function creditPayment(Payment $payment, $intent) | ||||
) { | ) { | ||||
$method = self::paymentMethod($pm); | $method = self::paymentMethod($pm); | ||||
} | } | ||||
// TODO: Localization? | // TODO: Localization? | ||||
$description = $payment->type == self::TYPE_RECURRING ? 'Auto-payment' : 'Payment'; | $description = $payment->type == self::TYPE_RECURRING ? 'Auto-payment' : 'Payment'; | ||||
$description .= " transaction {$payment->id} using {$method}"; | $description .= " transaction {$payment->id} using {$method}"; | ||||
$payment->wallet->credit($payment->amount, $description); | $payment->wallet->credit($payment, $description); | ||||
// Unlock the disabled auto-payment mandate | // Unlock the disabled auto-payment mandate | ||||
if ($payment->wallet->balance >= 0) { | if ($payment->wallet->balance >= 0) { | ||||
$payment->wallet->setSetting('mandate_disabled', null); | $payment->wallet->setSetting('mandate_disabled', null); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |