Clean up stripe bank transfer

This commit is contained in:
David Bomba 2023-02-26 19:57:30 +11:00
parent fe40771a24
commit 408d453052
2 changed files with 36 additions and 17 deletions

View File

@ -68,7 +68,7 @@ class BankTransfer
$data['return_url'] = $this->buildReturnUrl(); $data['return_url'] = $this->buildReturnUrl();
$data['gateway'] = $this->stripe; $data['gateway'] = $this->stripe;
$data['client_secret'] = $intent ? $intent->client_secret : false; $data['client_secret'] = $intent ? $intent->client_secret : false;
return render('gateways.stripe.bank_transfer.pay', $data); return render('gateways.stripe.bank_transfer.pay', $data);
} }
@ -124,31 +124,45 @@ class BankTransfer
} }
/* Create a pending payment */ /* Create a pending payment */
if($pi->status == 'requires_action') { if($pi->status == 'requires_action' && $pi->next_action->type == 'display_bank_transfer_instructions') {
$data = [ $data = [
'payment_method' => $pi->payment_method,
'payment_type' => PaymentType::DIRECT_DEBIT,
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
'transaction_reference' => $pi->id, 'account_holder_name' => $pi->next_action->display_bank_transfer_instructions->financial_addresses[0]->account_holder_name,
'gateway_type_id' => GatewayType::DIRECT_DEBIT, 'account_number' => $pi->next_action->display_bank_transfer_instructions->financial_addresses[0]->account_number,
'sort_code' => $pi->next_action->display_bank_transfer_instructions->financial_addresses[0]->sort_code,
'reference' => $pi->next_action->display_bank_transfer_instructions->reference,
'descripton' => $pi->description,
'gateway' => $this->stripe->company_gateway,
]; ];
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); return render('gateways.stripe.bank_transfer.bank_details', $data);
SystemLogger::dispatch( // $data = [
['response' => $this->stripe->payment_hash->data, 'data' => $data], // 'payment_method' => $pi->payment_method,
SystemLog::CATEGORY_GATEWAY_RESPONSE, // 'payment_type' => PaymentType::DIRECT_DEBIT,
SystemLog::EVENT_GATEWAY_SUCCESS, // 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
SystemLog::TYPE_STRIPE, // 'transaction_reference' => $pi->id,
$this->stripe->client, // 'gateway_type_id' => GatewayType::DIRECT_DEBIT,
$this->stripe->client->company,
);
return redirect($pi->next_action->display_bank_transfer_instructions->hosted_instructions_url); // ];
// $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($pi->next_action->display_bank_transfer_instructions->hosted_instructions_url);
} }
return $this->processUnsuccesfulRedirect(); return $this->processUnsuccesfulRedirect();
} }

View File

@ -260,7 +260,12 @@ class StripePaymentDriver extends BaseDriver
if ( if (
$this->client $this->client
&& isset($this->client->country) && isset($this->client->country)
&& in_array($this->client->country->iso_3166_2, ['FR', 'IE', 'NL', 'GB', 'DE', 'ES', 'JP', 'MX']) && (
(in_array($this->client->country->iso_3166_2, ['FR', 'IE', 'NL', 'DE', 'ES']) && $this->client->currency()->code == 'EUR') ||
($this->client->country->iso_3166_2 == 'JP' && $this->client->currency()->code == 'JPY') ||
($this->client->country->iso_3166_2 == 'MX' && $this->client->currency()->code == 'MXN') ||
($this->client->country->iso_3166_2 == 'GB' && $this->client->currency()->code == 'GBP')
)
) { ) {
$types[] = GatewayType::DIRECT_DEBIT; $types[] = GatewayType::DIRECT_DEBIT;
} }