Merge pull request #4546 from beganovich/v5-amount-with-fee

(v5) Change amount_with_fee source location
This commit is contained in:
Benjamin Beganović 2020-12-22 09:26:24 +01:00 committed by GitHub
commit 6009d49330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 152 additions and 173 deletions

View File

@ -112,8 +112,8 @@ class InvoiceItemSum
{ {
$item_tax = 0; $item_tax = 0;
// info(print_r($this->item,1)); // info(print_r($this->item,1));
// info(print_r($this->invoice,1)); // info(print_r($this->invoice,1));
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100)); $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100));
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);

View File

@ -12,7 +12,6 @@
namespace App\Http\Requests\Invoice; namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Http\ValidationRules\Invoice\UniqueInvoiceNumberRule;
use App\Http\ValidationRules\Project\ValidProjectForClient; use App\Http\ValidationRules\Project\ValidProjectForClient;
use App\Models\Invoice; use App\Models\Invoice;
use App\Utils\Traits\CleanLineItems; use App\Utils\Traits\CleanLineItems;

View File

@ -55,4 +55,3 @@ class PaymentMap
]; ];
} }
} }

View File

@ -60,37 +60,38 @@ class BaseTransformer
if ($code) { if ($code) {
$currency = $this->maps['currencies']->where('code', $code)->first(); $currency = $this->maps['currencies']->where('code', $code)->first();
if($currency_id) if ($currency_id) {
return $currency->id; return $currency->id;
} }
}
return $this->maps['company']->settings->currency_id; return $this->maps['company']->settings->currency_id;
} }
public function getClient($client_name, $client_email) public function getClient($client_name, $client_email)
{ {
$clients = $this->maps['company']->clients; $clients = $this->maps['company']->clients;
$clients = $clients->where('name', $client_name); $clients = $clients->where('name', $client_name);
if($clients->count() >= 1) if ($clients->count() >= 1) {
return $clients->first()->id; return $clients->first()->id;
}
$contacts = ClientContact::where('company_id', $this->maps['company']->id) $contacts = ClientContact::where('company_id', $this->maps['company']->id)
->where('email', $client_email); ->where('email', $client_email);
if($contacts->count() >=1) if ($contacts->count() >=1) {
return $contacts->first()->client_id; return $contacts->first()->client_id;
}
return NULL; return null;
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
/** /**
* @param $name * @param $name
* *
@ -148,11 +149,11 @@ class BaseTransformer
*/ */
public function getFloat($data, $field) public function getFloat($data, $field)
{ {
if (array_key_exists($field, $data)) {
if(array_key_exists($field, $data))
$number = preg_replace('/[^0-9-.]+/', '', $data[$field]); $number = preg_replace('/[^0-9-.]+/', '', $data[$field]);
else } else {
$number = 0; $number = 0;
}
return Number::parseStringFloat($number); return Number::parseStringFloat($number);
} }

View File

@ -11,8 +11,6 @@
namespace App\Import\Transformers; namespace App\Import\Transformers;
use Illuminate\Support\Str;
/** /**
* Class InvoiceItemTransformer. * Class InvoiceItemTransformer.
*/ */

View File

@ -11,8 +11,6 @@
namespace App\Import\Transformers; namespace App\Import\Transformers;
use Illuminate\Support\Str;
/** /**
* Class InvoiceTransformer. * Class InvoiceTransformer.
*/ */

View File

@ -11,8 +11,6 @@
namespace App\Import\Transformers; namespace App\Import\Transformers;
use Illuminate\Support\Str;
/** /**
* Class PaymentTransformer. * Class PaymentTransformer.
*/ */

View File

@ -11,8 +11,6 @@
namespace App\Import\Transformers; namespace App\Import\Transformers;
use Illuminate\Support\Str;
/** /**
* Class ProductTransformer. * Class ProductTransformer.
*/ */

View File

@ -126,17 +126,17 @@ info(print_r($data,1));
private function importInvoice() private function importInvoice()
{ {
$invoice_transformer = new InvoiceTransformer($this->maps); $invoice_transformer = new InvoiceTransformer($this->maps);
$records = $this->getCsvData(); $records = $this->getCsvData();
$invoice_number_key = array_search('Invoice Number', reset($records)); $invoice_number_key = array_search('Invoice Number', reset($records));
if ($this->skip_header) if ($this->skip_header) {
array_shift($records); array_shift($records);
}
if(!$invoice_number_key){ if (!$invoice_number_key) {
info("no invoice number to use as key - returning"); info("no invoice number to use as key - returning");
return; return;
} }
@ -144,15 +144,12 @@ info(print_r($data,1));
$unique_invoices = []; $unique_invoices = [];
//get an array of unique invoice numbers //get an array of unique invoice numbers
foreach($records as $key => $value) foreach ($records as $key => $value) {
{
$unique_invoices[] = $value[$invoice_number_key]; $unique_invoices[] = $value[$invoice_number_key];
} }
foreach($unique_invoices as $unique) foreach ($unique_invoices as $unique) {
{ $invoices = array_filter($records, function ($value) use ($invoice_number_key, $unique) {
$invoices = array_filter($records, function($value) use($invoice_number_key, $unique){
return $value[$invoice_number_key] == $unique; return $value[$invoice_number_key] == $unique;
}); });
@ -163,9 +160,7 @@ info(print_r($data,1));
$invoice = $invoice_transformer->transform($invoice_data); $invoice = $invoice_transformer->transform($invoice_data);
$this->processInvoice($invoices, $invoice); $this->processInvoice($invoices, $invoice);
} }
} }
private function processInvoice($invoices, $invoice) private function processInvoice($invoices, $invoice)
@ -174,15 +169,12 @@ info(print_r($data,1));
$item_transformer = new InvoiceItemTransformer($this->maps); $item_transformer = new InvoiceItemTransformer($this->maps);
$items = []; $items = [];
foreach($invoices as $record) foreach ($invoices as $record) {
{
$keys = $this->column_map; $keys = $this->column_map;
$values = array_intersect_key($record, $this->column_map); $values = array_intersect_key($record, $this->column_map);
$invoice_data = array_combine($keys, $values); $invoice_data = array_combine($keys, $values);
$items[] = $item_transformer->transform($invoice_data); $items[] = $item_transformer->transform($invoice_data);
} }
$invoice['line_items'] = $this->cleanItems($items); $invoice['line_items'] = $this->cleanItems($items);
@ -193,6 +185,9 @@ info(print_r($data,1));
$this->error_array['invoices'] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; $this->error_array['invoices'] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())];
} else { } else {
if ($validator->fails()) {
$this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())];
} else {
$invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record))); $invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record)));
$this->maps['invoices'][] = $invoice->id; $this->maps['invoices'][] = $invoice->id;
@ -203,7 +198,6 @@ info(print_r($data,1));
private function performInvoiceActions($invoice, $record, $invoice_repository) private function performInvoiceActions($invoice, $record, $invoice_repository)
{ {
$invoice = $this->actionInvoiceStatus($invoice, $record, $invoice_repository); $invoice = $this->actionInvoiceStatus($invoice, $record, $invoice_repository);
} }
@ -217,7 +211,7 @@ info(print_r($data,1));
case 'Sent': case 'Sent':
$invoice = $invoice->service()->markSent()->save(); $invoice = $invoice->service()->markSent()->save();
break; break;
case 'Viewed'; case 'Viewed':
$invoice = $invoice->service()->markSent()->save(); $invoice = $invoice->service()->markSent()->save();
break; break;
default: default:
@ -225,7 +219,7 @@ info(print_r($data,1));
break; break;
} }
if($invoice->balance < $invoice->amount && $invoice->status_id <= Invoice::STATUS_SENT){ if ($invoice->balance < $invoice->amount && $invoice->status_id <= Invoice::STATUS_SENT) {
$invoice->status_id = Invoice::STATUS_PARTIAL; $invoice->status_id = Invoice::STATUS_PARTIAL;
$invoice->save(); $invoice->save();
} }
@ -243,11 +237,11 @@ info(print_r($data,1));
$client_repository = new ClientRepository($contact_repository); $client_repository = new ClientRepository($contact_repository);
$client_transformer = new ClientTransformer($this->maps); $client_transformer = new ClientTransformer($this->maps);
if ($this->skip_header) if ($this->skip_header) {
array_shift($records); array_shift($records);
}
foreach ($records as $record) { foreach ($records as $record) {
$keys = $this->column_map; $keys = $this->column_map;
$values = array_intersect_key($record, $this->column_map); $values = array_intersect_key($record, $this->column_map);
@ -280,17 +274,16 @@ info(print_r($data,1));
private function importProduct() private function importProduct()
{ {
$product_repository = new ProductRepository(); $product_repository = new ProductRepository();
$product_transformer = new ProductTransformer($this->maps); $product_transformer = new ProductTransformer($this->maps);
$records = $this->getCsvData(); $records = $this->getCsvData();
if ($this->skip_header) if ($this->skip_header) {
array_shift($records); array_shift($records);
}
foreach ($records as $record) foreach ($records as $record) {
{
$keys = $this->column_map; $keys = $this->column_map;
$values = array_intersect_key($record, $this->column_map); $values = array_intersect_key($record, $this->column_map);

View File

@ -75,7 +75,7 @@ class AuthorizeCreditCard
$client_gateway_token = $authorise_payment_method->createClientGatewayToken($payment_profile, $gateway_customer_reference); $client_gateway_token = $authorise_payment_method->createClientGatewayToken($payment_profile, $gateway_customer_reference);
} }
$data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($gateway_customer_reference, $payment_profile_id, $data['amount_with_fee']); $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($gateway_customer_reference, $payment_profile_id, $data['total']['amount_with_fee']);
return $this->handleResponse($data, $request); return $this->handleResponse($data, $request);
} }

View File

@ -64,8 +64,8 @@ class CreditCard
$data['company_gateway'] = $this->checkout->company_gateway; $data['company_gateway'] = $this->checkout->company_gateway;
$data['client'] = $this->checkout->client; $data['client'] = $this->checkout->client;
$data['currency'] = $this->checkout->client->getCurrencyCode(); $data['currency'] = $this->checkout->client->getCurrencyCode();
$data['value'] = $this->checkout->convertToCheckoutAmount($data['amount_with_fee'], $this->checkout->client->getCurrencyCode()); $data['value'] = $this->checkout->convertToCheckoutAmount($data['total']['amount_with_fee'], $this->checkout->client->getCurrencyCode());
$data['raw_value'] = $data['amount_with_fee']; $data['raw_value'] = $data['total']['amount_with_fee'];
$data['customer_email'] = $this->checkout->client->present()->email; $data['customer_email'] = $this->checkout->client->present()->email;
return render('gateways.checkout.credit_card.pay', $data); return render('gateways.checkout.credit_card.pay', $data);

View File

@ -88,7 +88,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
$this->initializeOmnipayGateway(); $this->initializeOmnipayGateway();
$this->payment_hash->data = array_merge((array) $this->payment_hash->data, ['amount' => $data['amount_with_fee']]); $this->payment_hash->data = array_merge((array) $this->payment_hash->data, ['amount' => $data['total']['amount_with_fee']]);
$this->payment_hash->save(); $this->payment_hash->save();
$response = $this->omnipay_gateway $response = $this->omnipay_gateway
@ -100,7 +100,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
return $response->redirect(); return $response->redirect();
} }
PaymentFailureMailer::dispatch($this->client, $response->getData(), $this->client->company, $data['amount_with_fee']); PaymentFailureMailer::dispatch($this->client, $response->getData(), $this->client->company, $data['total']['amount_with_fee']);
$message = [ $message = [
'server_response' => $response->getMessage(), 'server_response' => $response->getMessage(),
@ -183,7 +183,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
'currency' => $this->client->getCurrencyCode(), 'currency' => $this->client->getCurrencyCode(),
'transactionType' => 'Purchase', 'transactionType' => 'Purchase',
'clientIp' => request()->getClientIp(), 'clientIp' => request()->getClientIp(),
'amount' => $data['amount_with_fee'], 'amount' => $data['total']['amount_with_fee'],
'returnUrl' => route('client.payments.response', [ 'returnUrl' => route('client.payments.response', [
'company_gateway_id' => $this->company_gateway->id, 'company_gateway_id' => $this->company_gateway->id,
'payment_hash' => $this->payment_hash->hash, 'payment_hash' => $this->payment_hash->hash,
@ -223,11 +223,11 @@ class PayPalExpressPaymentDriver extends BaseDriver
}); });
}); });
if ($total != $data['amount_with_fee']) { if ($total != $data['total']['amount_with_fee']) {
$items[0][] = new Item([ $items[0][] = new Item([
'name' => trans('texts.taxes_and_fees'), 'name' => trans('texts.taxes_and_fees'),
'description' => '', 'description' => '',
'price' => $data['amount_with_fee'] - $total, 'price' => $data['total']['amount_with_fee'] - $total,
'quantity' => 1, 'quantity' => 1,
]); ]);
} }

View File

@ -22,6 +22,8 @@ use App\Models\Payment;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver; use App\PaymentDrivers\StripePaymentDriver;
use Exception;
use Stripe\Customer;
use Stripe\Exception\CardException; use Stripe\Exception\CardException;
use Stripe\Exception\InvalidRequestException; use Stripe\Exception\InvalidRequestException;
@ -68,10 +70,10 @@ class ACH
{ {
$this->stripe->init(); $this->stripe->init();
$bank_account = \Stripe\Customer::retrieveSource($request->customer, $request->source); $bank_account = Customer::retrieveSource($request->customer, $request->source);
try { try {
$status = $bank_account->verify(['amounts' => request()->transactions]); $bank_account->verify(['amounts' => request()->transactions]);
$token->meta->verified_at = now(); $token->meta->verified_at = now();
$token->save(); $token->save();
@ -90,7 +92,7 @@ class ACH
$data['currency'] = $this->stripe->client->getCurrencyCode(); $data['currency'] = $this->stripe->client->getCurrencyCode();
$data['payment_method_id'] = GatewayType::BANK_TRANSFER; $data['payment_method_id'] = GatewayType::BANK_TRANSFER;
$data['customer'] = $this->stripe->findOrCreateCustomer(); $data['customer'] = $this->stripe->findOrCreateCustomer();
$data['amount'] = $this->stripe->convertToStripeAmount($data['amount_with_fee'], $this->stripe->client->currency()->precision); $data['amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision);
return render('gateways.stripe.ach.pay', $data); return render('gateways.stripe.ach.pay', $data);
} }
@ -205,7 +207,7 @@ class ACH
]; ];
return $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); return $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
} catch (\Exception $e) { } catch (Exception $e) {
return $this->stripe->processInternallyFailedPayment($this->stripe, $e); return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
} }
} }

View File

@ -17,6 +17,7 @@ use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver; use App\PaymentDrivers\StripePaymentDriver;
@ -36,7 +37,7 @@ class Alipay
$data['gateway'] = $this->stripe; $data['gateway'] = $this->stripe;
$data['return_url'] = $this->buildReturnUrl(); $data['return_url'] = $this->buildReturnUrl();
$data['currency'] = $this->stripe->client->getCurrencyCode(); $data['currency'] = $this->stripe->client->getCurrencyCode();
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['amount_with_fee'], $this->stripe->client->currency()->precision); $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision);
$data['invoices'] = $this->stripe->payment_hash->invoices(); $data['invoices'] = $this->stripe->payment_hash->invoices();
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
@ -77,7 +78,7 @@ class Alipay
'transaction_reference' => $source, 'transaction_reference' => $source,
]; ];
$payment = $this->stripe->createPayment($data, \App\Models\Payment::STATUS_PENDING); $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
SystemLogger::dispatch( SystemLogger::dispatch(
['response' => $this->stripe->payment_hash->data, 'data' => $data], ['response' => $this->stripe->payment_hash->data, 'data' => $data],

View File

@ -16,12 +16,13 @@ use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver; use App\PaymentDrivers\StripePaymentDriver;
use Stripe\PaymentIntent;
use Stripe\PaymentMethod;
class CreditCard class CreditCard
{ {
@ -59,7 +60,7 @@ class CreditCard
public function paymentView(array $data) public function paymentView(array $data)
{ {
$payment_intent_data = [ $payment_intent_data = [
'amount' => $this->stripe->convertToStripeAmount($data['amount_with_fee'], $this->stripe->client->currency()->precision), 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision),
'currency' => $this->stripe->client->getCurrencyCode(), 'currency' => $this->stripe->client->getCurrencyCode(),
'customer' => $this->stripe->findOrCreateCustomer(), 'customer' => $this->stripe->findOrCreateCustomer(),
'description' => collect($data['invoices'])->pluck('id'), // TODO: More meaningful description. 'description' => collect($data['invoices'])->pluck('id'), // TODO: More meaningful description.
@ -91,7 +92,7 @@ class CreditCard
$state = array_merge($state, $request->all()); $state = array_merge($state, $request->all());
$state['store_card'] = boolval($state['store_card']); $state['store_card'] = boolval($state['store_card']);
$state['payment_intent'] = \Stripe\PaymentIntent::retrieve($state['server_response']->id); $state['payment_intent'] = PaymentIntent::retrieve($state['server_response']->id);
$state['customer'] = $state['payment_intent']->customer; $state['customer'] = $state['payment_intent']->customer;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state); $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state);
@ -134,7 +135,7 @@ class CreditCard
$this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer); $this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer);
} }
$payment = $this->stripe->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); $payment = $this->stripe->createPayment($data, Payment::STATUS_COMPLETED);
SystemLogger::dispatch( SystemLogger::dispatch(
['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data], ['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data],
@ -174,7 +175,7 @@ class CreditCard
throw new PaymentFailed('Failed to process the payment.', 500); throw new PaymentFailed('Failed to process the payment.', 500);
} }
private function storePaymentMethod(\Stripe\PaymentMethod $method, $payment_method_id, $customer) private function storePaymentMethod(PaymentMethod $method, $payment_method_id, $customer)
{ {
try { try {
$payment_meta = new \stdClass; $payment_meta = new \stdClass;
@ -195,26 +196,4 @@ class CreditCard
return $this->stripe->processInternallyFailedPayment($this->stripe, $e); return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
} }
} }
private function saveCard($state)
{
$state['payment_method']->attach(['customer' => $state['customer']]);
$company_gateway_token = new ClientGatewayToken();
$company_gateway_token->company_id = $this->stripe->client->company->id;
$company_gateway_token->client_id = $this->stripe->client->id;
$company_gateway_token->token = $state['payment_method']->id;
$company_gateway_token->company_gateway_id = $this->stripe->company_gateway->id;
$company_gateway_token->gateway_type_id = $state['gateway_type_id'];
$company_gateway_token->gateway_customer_reference = $state['customer'];
$company_gateway_token->meta = $state['payment_meta'];
$company_gateway_token->save();
if ($this->stripe->client->gateway_tokens->count() == 1) {
$this->stripe->client->gateway_tokens()->update(['is_default' => 0]);
$company_gateway_token->is_default = 1;
$company_gateway_token->save();
}
}
} }

View File

@ -12,14 +12,14 @@
namespace App\PaymentDrivers\Stripe; namespace App\PaymentDrivers\Stripe;
use App\Events\Payment\PaymentWasCreated; use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver; use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Ninja;
class SOFORT class SOFORT
{ {
@ -34,74 +34,90 @@ class SOFORT
public function paymentView(array $data) public function paymentView(array $data)
{ {
$data['gateway'] = $this->stripe; $data['gateway'] = $this->stripe;
$data['return_url'] = $this->buildReturnUrl($data); $data['return_url'] = $this->buildReturnUrl();
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['amount_with_fee'], $this->stripe->client->currency()->precision); $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision);
$data['client'] = $this->stripe->client; $data['client'] = $this->stripe->client;
$data['country'] = $this->stripe->client->country->iso_3166_2; $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); return render('gateways.stripe.sofort.pay', $data);
} }
private function buildReturnUrl($data): string private function buildReturnUrl(): string
{ {
return route('client.payments.response', [ return route('client.payments.response', [
'company_gateway_id' => $this->stripe->company_gateway->id, 'company_gateway_id' => $this->stripe->company_gateway->id,
'gateway_type_id' => GatewayType::SOFORT, 'payment_hash' => $this->stripe->payment_hash->hash,
'hashed_ids' => implode(',', $data['hashed_ids']), 'payment_method_id' => GatewayType::SOFORT,
'amount' => $data['amount'],
'fee' => $data['fee'],
]); ]);
} }
public function paymentResponse($request) public function paymentResponse($request)
{ {
$state = array_merge($request->all(), []); $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all());
$amount = $state['amount'] + $state['fee']; $this->stripe->payment_hash->save();
$state['amount'] = $this->stripe->convertToStripeAmount($amount, $this->stripe->client->currency()->precision);
if ($request->redirect_status == 'succeeded') { if ($request->redirect_status == 'succeeded') {
return $this->processSuccessfulPayment($state); return $this->processSuccessfulPayment($request->source);
} }
return $this->processUnsuccessfulPayment($state); return $this->processUnsuccessfulPayment();
} }
public function processSuccessfulPayment($state) public function processSuccessfulPayment(string $source)
{ {
$state['charge_id'] = $state['source']; /* @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */
$this->stripe->init(); $this->stripe->init();
$state['payment_type'] = PaymentType::SOFORT;
$data = [ $data = [
'payment_method' => $state['charge_id'], 'payment_method' => $this->stripe->payment_hash->data->source,
'payment_type' => $state['payment_type'], 'payment_type' => PaymentType::SOFORT,
'amount' => $state['amount'], 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision),
'gateway_type_id' => GatewayType::SOFORT, 'transaction_reference' => $source,
]; ];
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
/* @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */ SystemLogger::dispatch(
if (isset($state['hashed_ids'])) { ['response' => $this->stripe->payment_hash->data, 'data' => $data],
$this->stripe->attachInvoices($payment, $state['hashed_ids']); SystemLog::CATEGORY_GATEWAY_RESPONSE,
} SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_STRIPE,
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $this->stripe->client
);
$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)]); return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]);
} }
public function processUnsuccessfulPayment($state) public function processUnsuccessfulPayment()
{ {
return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_cancelled')); $server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch($this->stripe->client, $server_response->redirect_status, $this->stripe->client->company, $server_response->amount);
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
);
throw new PaymentFailed('Failed to process the payment.', 500);
} }
} }

View File

@ -21,17 +21,18 @@ use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentHash; use App\Models\PaymentHash;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\Stripe\ACH;
use App\PaymentDrivers\Stripe\Alipay; use App\PaymentDrivers\Stripe\Alipay;
use App\PaymentDrivers\Stripe\Charge; use App\PaymentDrivers\Stripe\Charge;
use App\PaymentDrivers\Stripe\CreditCard; use App\PaymentDrivers\Stripe\CreditCard;
use App\PaymentDrivers\Stripe\SOFORT; use App\PaymentDrivers\Stripe\SOFORT;
use App\PaymentDrivers\Stripe\Utilities; use App\PaymentDrivers\Stripe\Utilities;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Exception;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\View\View;
use Stripe\Customer; use Stripe\Customer;
use Stripe\Exception\ApiErrorException;
use Stripe\PaymentIntent; use Stripe\PaymentIntent;
use Stripe\PaymentMethod;
use Stripe\SetupIntent; use Stripe\SetupIntent;
use Stripe\Stripe; use Stripe\Stripe;
use Stripe\StripeClient; use Stripe\StripeClient;
@ -55,7 +56,7 @@ class StripePaymentDriver extends BaseDriver
public static $methods = [ public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class, GatewayType::CREDIT_CARD => CreditCard::class,
GatewayType::BANK_TRANSFER => ACH::class, GatewayType::BANK_TRANSFER => SOFORT::class,
GatewayType::ALIPAY => Alipay::class, GatewayType::ALIPAY => Alipay::class,
GatewayType::SOFORT => SOFORT::class, GatewayType::SOFORT => SOFORT::class,
GatewayType::APPLE_PAY => 1, // TODO GatewayType::APPLE_PAY => 1, // TODO
@ -152,8 +153,7 @@ class StripePaymentDriver extends BaseDriver
* Proxy method to pass the data into payment method authorizeView(). * Proxy method to pass the data into payment method authorizeView().
* *
* @param array $data * @param array $data
* * @return \Illuminate\Http\RedirectResponse|mixed
* @return Factory|View
*/ */
public function authorizeView(array $data) public function authorizeView(array $data)
{ {
@ -169,8 +169,8 @@ class StripePaymentDriver extends BaseDriver
/** /**
* Processes the gateway response for credit card authorization. * Processes the gateway response for credit card authorization.
* *
* @param Request $request The returning request object * @param \Illuminate\Http\Request $request
* @return Factory|View * @return \Illuminate\Http\RedirectResponse|mixed
*/ */
public function authorizeResponse($request) public function authorizeResponse($request)
{ {
@ -187,7 +187,7 @@ class StripePaymentDriver extends BaseDriver
* Process the payment with gateway. * Process the payment with gateway.
* *
* @param array $data * @param array $data
* @return Factory|View|void * @return \Illuminate\Http\RedirectResponse|mixed
*/ */
public function processPaymentView(array $data) public function processPaymentView(array $data)
{ {
@ -216,7 +216,7 @@ class StripePaymentDriver extends BaseDriver
* *
* @param array $data The data array to be passed to Stripe * @param array $data The data array to be passed to Stripe
* @return PaymentIntent The Stripe payment intent object * @return PaymentIntent The Stripe payment intent object
* @throws \Stripe\Exception\ApiErrorException * @throws ApiErrorException
*/ */
public function createPaymentIntent($data): ?PaymentIntent public function createPaymentIntent($data): ?PaymentIntent
{ {
@ -230,7 +230,7 @@ class StripePaymentDriver extends BaseDriver
* to enter card details without initiating a transaction. * to enter card details without initiating a transaction.
* *
* @return SetupIntent * @return SetupIntent
* @throws \Stripe\Exception\ApiErrorException * @throws ApiErrorException
*/ */
public function getSetupIntent(): SetupIntent public function getSetupIntent(): SetupIntent
{ {
@ -253,7 +253,7 @@ class StripePaymentDriver extends BaseDriver
* *
* @return null|Customer A Stripe customer object * @return null|Customer A Stripe customer object
* @throws \Laracasts\Presenter\Exceptions\PresenterException * @throws \Laracasts\Presenter\Exceptions\PresenterException
* @throws \Stripe\Exception\ApiErrorException * @throws ApiErrorException
*/ */
public function findOrCreateCustomer(): ?Customer public function findOrCreateCustomer(): ?Customer
{ {
@ -277,7 +277,7 @@ class StripePaymentDriver extends BaseDriver
} }
if (!$customer) { if (!$customer) {
throw new \Exception('Unable to create gateway customer'); throw new Exception('Unable to create gateway customer');
} }
return $customer; return $customer;
@ -316,7 +316,7 @@ class StripePaymentDriver extends BaseDriver
'description' => $response->failure_reason, 'description' => $response->failure_reason,
'code' => 422, 'code' => 422,
]; ];
} catch (\Exception $e) { } catch (Exception $e) {
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client); SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
info($e->getMessage()); info($e->getMessage());
@ -394,7 +394,7 @@ class StripePaymentDriver extends BaseDriver
try { try {
$stripe_payment_method = $this->getStripePaymentMethod($payment_method); $stripe_payment_method = $this->getStripePaymentMethod($payment_method);
$stripe_payment_method->attach(['customer' => $customer->id]); $stripe_payment_method->attach(['customer' => $customer->id]);
} catch (\Stripe\Exception\ApiErrorException | \Exception $e) { } catch (ApiErrorException | Exception $e) {
$this->processInternallyFailedPayment($this, $e); $this->processInternallyFailedPayment($this, $e);
} }
} }
@ -413,7 +413,7 @@ class StripePaymentDriver extends BaseDriver
); );
try { try {
$response = $stripe->paymentMethods->detach($token->token); $stripe->paymentMethods->detach($token->token);
} catch (Exception $e) { } catch (Exception $e) {
SystemLogger::dispatch([ SystemLogger::dispatch([
'server_response' => $e->getMessage(), 'data' => request()->all(), 'server_response' => $e->getMessage(), 'data' => request()->all(),
@ -431,13 +431,13 @@ class StripePaymentDriver extends BaseDriver
* *
* @param string $source * @param string $source
* *
* @return \Stripe\PaymentMethod|void * @return PaymentMethod|void
*/ */
public function getStripePaymentMethod(string $source) public function getStripePaymentMethod(string $source)
{ {
try { try {
return \Stripe\PaymentMethod::retrieve($source); return PaymentMethod::retrieve($source);
} catch (\Stripe\Exception\ApiErrorException | \Exception $e) { } catch (ApiErrorException | Exception $e) {
return $this->processInternallyFailedPayment($this, $e); return $this->processInternallyFailedPayment($this, $e);
} }
} }

View File

@ -94,8 +94,9 @@ class HandleRestore extends AbstractService
$new_invoice_number = substr($this->invoice->number, 0, $pos); $new_invoice_number = substr($this->invoice->number, 0, $pos);
if(strlen($new_invoice_number) == 0) if (strlen($new_invoice_number) == 0) {
$new_invoice_number = null; $new_invoice_number = null;
}
try { try {
$this->invoice->number = $new_invoice_number; $this->invoice->number = $new_invoice_number;

View File

@ -7,7 +7,7 @@ return [
'production' => env('NINJA_PROD', false), 'production' => env('NINJA_PROD', false),
'license' => env('NINJA_LICENSE', ''), 'license' => env('NINJA_LICENSE', ''),
'version_url' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v5-stable/VERSION.txt', 'version_url' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v5-stable/VERSION.txt',
'app_name' => env('APP_NAME','Invoice Ninja'), 'app_name' => env('APP_NAME', 'Invoice Ninja'),
'app_env' => env('APP_ENV', 'selfhosted'), 'app_env' => env('APP_ENV', 'selfhosted'),
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),

View File

@ -30,6 +30,3 @@ class ChangeProductsTableCostResolution extends Migration
// //
} }
} }

View File

@ -1,2 +1,2 @@
/*! For license information please see stripe-sofort.js.LICENSE.txt */ /*! For license information please see stripe-sofort.js.LICENSE.txt */
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=6)}({6:function(e,t,n){e.exports=n("RFiP")},RFiP:function(e,t){function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}new function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),n(this,"setupStripe",(function(){return r.stripe=Stripe(r.key),r})),n(this,"handle",(function(){var e={type:"sofort",amount:document.querySelector('meta[name="amount"]').content,currency:"eur",redirect:{return_url:document.querySelector('meta[name="return-url"]').content},sofort:{country:document.querySelector('meta[name="country"').content}};document.getElementById("pay-now").addEventListener("click",(function(t){document.getElementById("pay-now-button").disabled=!0,document.querySelector("#pay-now-button > svg").classList.remove("hidden"),document.querySelector("#pay-now-button > span").classList.add("hidden"),r.stripe.createSource(e).then((function(e){if(e.hasOwnProperty("source"))return window.location=e.source.redirect.url;document.getElementById("pay-now-button").disabled=!1,document.querySelector("#pay-now-button > svg").classList.add("hidden"),document.querySelector("#pay-now-button > span").classList.remove("hidden"),this.errors.textContent="",this.errors.textContent=e.error.message,this.errors.hidden=!1,document.getElementById("pay-now").disabled=!1}))}))})),this.key=t,this.errors=document.getElementById("errors")}(document.querySelector('meta[name="stripe-publishable-key"]').content).setupStripe().handle()}}); !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=6)}({6:function(e,t,n){e.exports=n("RFiP")},RFiP:function(e,t){function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}new function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),n(this,"setupStripe",(function(){return r.stripe=Stripe(r.key),r})),n(this,"handle",(function(){var e={type:"sofort",amount:document.querySelector('meta[name="amount"]').content,currency:"eur",redirect:{return_url:document.querySelector('meta[name="return-url"]').content},sofort:{country:document.querySelector('meta[name="country"').content}};document.getElementById("pay-now").addEventListener("click",(function(t){document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),r.stripe.createSource(e).then((function(e){if(e.hasOwnProperty("source"))return window.location=e.source.redirect.url;document.getElementById("pay-now").disabled=!1,document.querySelector("#pay-now > svg").classList.add("hidden"),document.querySelector("#pay-now > span").classList.remove("hidden"),this.errors.textContent="",this.errors.textContent=e.error.message,this.errors.hidden=!1,document.getElementById("pay-now").disabled=!1}))}))})),this.key=t,this.errors=document.getElementById("errors")}(document.querySelector('meta[name="stripe-publishable-key"]').content).setupStripe().handle()}});

View File

@ -10,7 +10,7 @@
"/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=c4012ad90f17d60432ad", "/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=c4012ad90f17d60432ad",
"/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=6dbe9316b98deea55421", "/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=6dbe9316b98deea55421",
"/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=f4659d26a26d2f408397", "/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=f4659d26a26d2f408397",
"/js/clients/payments/stripe-sofort.js": "/js/clients/payments/stripe-sofort.js?id=7f5b13e34c75e63c015e", "/js/clients/payments/stripe-sofort.js": "/js/clients/payments/stripe-sofort.js?id=bb7c55ca3da2d29e55d2",
"/js/clients/quotes/action-selectors.js": "/js/clients/quotes/action-selectors.js?id=1b8f9325aa6e8595e7fa", "/js/clients/quotes/action-selectors.js": "/js/clients/quotes/action-selectors.js?id=1b8f9325aa6e8595e7fa",
"/js/clients/quotes/approve.js": "/js/clients/quotes/approve.js?id=85bcae0a646882e56b12", "/js/clients/quotes/approve.js": "/js/clients/quotes/approve.js?id=85bcae0a646882e56b12",
"/js/clients/shared/multiple-downloads.js": "/js/clients/shared/multiple-downloads.js?id=5c35d28cf0a3286e7c45", "/js/clients/shared/multiple-downloads.js": "/js/clients/shared/multiple-downloads.js?id=5c35d28cf0a3286e7c45",

View File

@ -30,23 +30,23 @@ class ProcessSOFORT {
.content, .content,
}, },
sofort: { sofort: {
country: document.querySelector('meta[name="country"').content, country: document.querySelector('meta[name="country"]').content,
}, },
}; };
document.getElementById('pay-now').addEventListener('click', (e) => { document.getElementById('pay-now').addEventListener('click', (e) => {
document.getElementById('pay-now-button').disabled = true; document.getElementById('pay-now').disabled = true;
document.querySelector('#pay-now-button > svg').classList.remove('hidden'); document.querySelector('#pay-now > svg').classList.remove('hidden');
document.querySelector('#pay-now-button > span').classList.add('hidden'); document.querySelector('#pay-now > span').classList.add('hidden');
this.stripe.createSource(data).then(function(result) { this.stripe.createSource(data).then(function(result) {
if (result.hasOwnProperty('source')) { if (result.hasOwnProperty('source')) {
return (window.location = result.source.redirect.url); return (window.location = result.source.redirect.url);
} }
document.getElementById('pay-now-button').disabled = false; document.getElementById('pay-now').disabled = false;
document.querySelector('#pay-now-button > svg').classList.add('hidden'); document.querySelector('#pay-now > svg').classList.add('hidden');
document.querySelector('#pay-now-button > span').classList.remove('hidden'); document.querySelector('#pay-now > span').classList.remove('hidden');
this.errors.textContent = ''; this.errors.textContent = '';
this.errors.textContent = result.error.message; this.errors.textContent = result.error.message;

View File

@ -150,7 +150,6 @@ class ImportCsvTest extends TestCase
CSVImport::dispatchNow($data, $this->company); CSVImport::dispatchNow($data, $this->company);
$this->assertGreaterThan($pre_import, Product::count()); $this->assertGreaterThan($pre_import, Product::count());
} }
private function getCsvData($csvfile) private function getCsvData($csvfile)