Fix PaymentWasCreated event second parameter (#3175)

This commit is contained in:
Benjamin Beganović 2019-12-28 07:25:18 +01:00 committed by David Bomba
parent e406020ee5
commit 1f7c661929
3 changed files with 48 additions and 48 deletions

View File

@ -92,14 +92,14 @@ class CreateTestData extends Command
$user = User::whereEmail('small@example.com')->first(); $user = User::whereEmail('small@example.com')->first();
if(!$user) if(!$user)
{ {
$user = factory(\App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
// 'account_id' => $account->id, // 'account_id' => $account->id,
'email' => 'small@example.com', 'email' => 'small@example.com',
'confirmation_code' => $this->createDbHash(config('database.default')) 'confirmation_code' => $this->createDbHash(config('database.default'))
]); ]);
} }
$token = \Illuminate\Support\Str::random(64); $token = \Illuminate\Support\Str::random(64);
$company_token = CompanyToken::create([ $company_token = CompanyToken::create([
@ -147,14 +147,14 @@ class CreateTestData extends Command
$user = User::whereEmail('medium@example.com')->first(); $user = User::whereEmail('medium@example.com')->first();
if(!$user) if(!$user)
{ {
$user = factory(\App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
// 'account_id' => $account->id, // 'account_id' => $account->id,
'email' => 'medium@example.com', 'email' => 'medium@example.com',
'confirmation_code' => $this->createDbHash(config('database.default')) 'confirmation_code' => $this->createDbHash(config('database.default'))
]); ]);
} }
$token = \Illuminate\Support\Str::random(64); $token = \Illuminate\Support\Str::random(64);
$company_token = CompanyToken::create([ $company_token = CompanyToken::create([
@ -203,14 +203,14 @@ class CreateTestData extends Command
$user = User::whereEmail('large@example.com')->first(); $user = User::whereEmail('large@example.com')->first();
if(!$user) if(!$user)
{ {
$user = factory(\App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
// 'account_id' => $account->id, // 'account_id' => $account->id,
'email' => 'large@example.com', 'email' => 'large@example.com',
'confirmation_code' => $this->createDbHash(config('database.default')) 'confirmation_code' => $this->createDbHash(config('database.default'))
]); ]);
} }
$token = \Illuminate\Support\Str::random(64); $token = \Illuminate\Support\Str::random(64);
$company_token = CompanyToken::create([ $company_token = CompanyToken::create([
@ -283,7 +283,7 @@ class CreateTestData extends Command
$invoice = InvoiceFactory::create($client->company->id,$client->user->id);//stub the company and user_id $invoice = InvoiceFactory::create($client->company->id,$client->user->id);//stub the company and user_id
$invoice->client_id = $client->id; $invoice->client_id = $client->id;
$invoice->date = $faker->date(); $invoice->date = $faker->date();
$invoice->line_items = $this->buildLineItems(); $invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false; $invoice->uses_inclusive_taxes = false;
@ -315,7 +315,7 @@ class CreateTestData extends Command
$invoice->save(); $invoice->save();
event(new CreateInvoiceInvitation($invoice)); event(new CreateInvoiceInvitation($invoice));
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance); UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance);
$this->invoice_repo->markSent($invoice); $this->invoice_repo->markSent($invoice);
@ -349,7 +349,7 @@ class CreateTestData extends Command
$quote = QuoteFactory::create($client->company->id,$client->user->id);//stub the company and user_id $quote = QuoteFactory::create($client->company->id,$client->user->id);//stub the company and user_id
$quote->client_id = $client->id; $quote->client_id = $client->id;
$quote->date = $faker->date(); $quote->date = $faker->date();
$quote->line_items = $this->buildLineItems(); $quote->line_items = $this->buildLineItems();
$quote->uses_inclusive_taxes = false; $quote->uses_inclusive_taxes = false;
@ -379,7 +379,7 @@ class CreateTestData extends Command
$quote = $quote_calc->getInvoice(); $quote = $quote_calc->getInvoice();
$quote->save(); $quote->save();
CreateQuoteInvitations::dispatch($quote, $quote->company); CreateQuoteInvitations::dispatch($quote, $quote->company);
@ -393,19 +393,19 @@ class CreateTestData extends Command
$item->quantity = 1; $item->quantity = 1;
$item->cost =10; $item->cost =10;
if(rand(0, 1)) if(rand(0, 1))
{ {
$item->tax_name1 = 'GST'; $item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00; $item->tax_rate1 = 10.00;
} }
if(rand(0, 1)) if(rand(0, 1))
{ {
$item->tax_name1 = 'VAT'; $item->tax_name1 = 'VAT';
$item->tax_rate1 = 17.50; $item->tax_rate1 = 17.50;
} }
if(rand(0, 1)) if(rand(0, 1))
{ {
$item->tax_name1 = 'Sales Tax'; $item->tax_name1 = 'Sales Tax';
$item->tax_rate1 = 5; $item->tax_rate1 = 5;
@ -421,7 +421,7 @@ class CreateTestData extends Command
{ {
/* Warm up the cache !*/ /* Warm up the cache !*/
$cached_tables = config('ninja.cached_tables'); $cached_tables = config('ninja.cached_tables');
foreach ($cached_tables as $name => $class) { foreach ($cached_tables as $name => $class) {
if (! Cache::has($name)) { if (! Cache::has($name)) {
// check that the table exists in case the migration is pending // check that the table exists in case the migration is pending

View File

@ -54,12 +54,12 @@ use Omnipay\Common\Item;
'PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE' => 'None', 'PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE' => 'None',
'PAYMENTINFO_0_ERRORCODE' => '0', 'PAYMENTINFO_0_ERRORCODE' => '0',
'PAYMENTINFO_0_ACK' => 'Success', 'PAYMENTINFO_0_ACK' => 'Success',
) )
*/ */
class PayPalExpressPaymentDriver extends BasePaymentDriver class PayPalExpressPaymentDriver extends BasePaymentDriver
{ {
use MakesHash; use MakesHash;
protected $refundable = false; protected $refundable = false;
@ -80,7 +80,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
/** /**
* Processes the payment with this gateway * Processes the payment with this gateway
* *
* @var $data['invoices'] * @var $data['invoices']
* @var $data['amount'] * @var $data['amount']
* @var $data['fee'] * @var $data['fee']
@ -88,13 +88,13 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
* @var $data['token'] * @var $data['token']
* @var $data['payment_method_id'] * @var $data['payment_method_id']
* @var $data['hashed_ids'] * @var $data['hashed_ids']
* *
* @param array $data variables required to build payment page * @param array $data variables required to build payment page
* @return view Gateway and payment method specific view * @return view Gateway and payment method specific view
*/ */
public function processPaymentView(array $data) public function processPaymentView(array $data)
{ {
$response = $this->purchase($this->paymentDetails($data), $this->paymentItems($data)); $response = $this->purchase($this->paymentDetails($data), $this->paymentItems($data));
@ -103,14 +103,14 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
$response->redirect(); $response->redirect();
} elseif ($response->isSuccessful()) { } elseif ($response->isSuccessful()) {
// payment was successful: update database // payment was successful: update database
/* for this driver this method wont be hit*/ /* for this driver this method wont be hit*/
} else { } else {
// payment failed: display message to customer // payment failed: display message to customer
SystemLogger::dispatch([ SystemLogger::dispatch([
'server_response' => $response->getData(), 'server_response' => $response->getData(),
'data' => $data 'data' => $data
], ],
SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_PAYPAL, SystemLog::TYPE_PAYPAL,
@ -118,7 +118,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
); );
throw new \Exception("Error Processing Payment", 1); throw new \Exception("Error Processing Payment", 1);
} }
} }
@ -131,13 +131,13 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
if ($response->isCancelled()) { if ($response->isCancelled()) {
return redirect()->route('client.invoices.index')->with('warning',ctrans('texts.status_voided')); return redirect()->route('client.invoices.index')->with('warning',ctrans('texts.status_voided'));
} }
elseif($response->isSuccessful()){ elseif($response->isSuccessful()){
SystemLogger::dispatch([ SystemLogger::dispatch([
'server_response' => $response->getData(), 'server_response' => $response->getData(),
'data' => $request->all() 'data' => $request->all()
], ],
SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_PAYPAL, SystemLog::TYPE_PAYPAL,
@ -145,12 +145,12 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
); );
} }
elseif (! $response->isSuccessful()) { elseif (! $response->isSuccessful()) {
SystemLogger::dispatch([ SystemLogger::dispatch([
'data' => $request->all(), 'data' => $request->all(),
'server_response' => $response->getData() 'server_response' => $response->getData()
], ],
SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_PAYPAL, SystemLog::TYPE_PAYPAL,
@ -164,8 +164,8 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
$this->attachInvoices($payment, $request->input('hashed_ids')); $this->attachInvoices($payment, $request->input('hashed_ids'));
event(new PaymentWasCreated($payment)); event(new PaymentWasCreated($payment, $payment->company));
UpdateInvoicePayment::dispatchNow($payment, $payment->company); UpdateInvoicePayment::dispatchNow($payment, $payment->company);
return redirect()->route('client.payments.show', ['payment'=>$this->encodePrimaryKey($payment->id)]); return redirect()->route('client.payments.show', ['payment'=>$this->encodePrimaryKey($payment->id)]);
@ -193,7 +193,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
{ {
$url = $this->client->company->domain() . "client/payments/process/response"; $url = $this->client->company->domain() . "client/payments/process/response";
$url .= "?company_gateway_id={$this->company_gateway->id}&gateway_type_id=".GatewayType::PAYPAL; $url .= "?company_gateway_id={$this->company_gateway->id}&gateway_type_id=".GatewayType::PAYPAL;
$url .= "&hashed_ids=" . implode(",", $input['hashed_ids']); $url .= "&hashed_ids=" . implode(",", $input['hashed_ids']);
$url .= "&amount=".$input['amount']; $url .= "&amount=".$input['amount'];
$url .= "&fee=".$input['fee']; $url .= "&fee=".$input['fee'];
@ -210,7 +210,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
private function buildDescription($input) : string private function buildDescription($input) : string
{ {
$invoice_numbers = ""; $invoice_numbers = "";
foreach($input['invoices'] as $invoice) foreach($input['invoices'] as $invoice)
{ {
$invoice_numbers .= $invoice->number." "; $invoice_numbers .= $invoice->number." ";
@ -222,7 +222,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
private function buildTransactionId($input) : string private function buildTransactionId($input) : string
{ {
return implode(",", $input['hashed_ids']); return implode(",", $input['hashed_ids']);
} }
private function paymentItems($input) : array private function paymentItems($input) : array
@ -231,7 +231,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
$items = []; $items = [];
$total = 0; $total = 0;
foreach ($input['invoices'] as $invoice) foreach ($input['invoices'] as $invoice)
{ {
foreach($invoice->line_items as $invoiceItem) foreach($invoice->line_items as $invoiceItem)
{ {
@ -266,7 +266,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
return $items; return $items;
} }
public function createPayment($data) : Payment public function createPayment($data) : Payment
{ {
@ -284,4 +284,4 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
return $payment; return $payment;
} }
} }

View File

@ -41,7 +41,7 @@ class RandomDataSeeder extends Seeder
/* Warm up the cache !*/ /* Warm up the cache !*/
$cached_tables = config('ninja.cached_tables'); $cached_tables = config('ninja.cached_tables');
foreach ($cached_tables as $name => $class) { foreach ($cached_tables as $name => $class) {
if (! Cache::has($name)) { if (! Cache::has($name)) {
// check that the table exists in case the migration is pending // check that the table exists in case the migration is pending
@ -63,7 +63,7 @@ class RandomDataSeeder extends Seeder
} }
} }
} }
$this->command->info('Running RandomDataSeeder'); $this->command->info('Running RandomDataSeeder');
@ -141,7 +141,7 @@ class RandomDataSeeder extends Seeder
/** Invoice Factory */ /** Invoice Factory */
factory(\App\Models\Invoice::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); factory(\App\Models\Invoice::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
$invoices = Invoice::cursor(); $invoices = Invoice::cursor();
$invoice_repo = new InvoiceRepository(); $invoice_repo = new InvoiceRepository();
@ -151,15 +151,15 @@ class RandomDataSeeder extends Seeder
if($invoice->uses_inclusive_taxes) if($invoice->uses_inclusive_taxes)
$invoice_calc = new InvoiceSumInclusive($invoice); $invoice_calc = new InvoiceSumInclusive($invoice);
else else
$invoice_calc = new InvoiceSum($invoice); $invoice_calc = new InvoiceSum($invoice);
$invoice = $invoice_calc->build()->getInvoice(); $invoice = $invoice_calc->build()->getInvoice();
$invoice->save(); $invoice->save();
event(new CreateInvoiceInvitation($invoice)); event(new CreateInvoiceInvitation($invoice));
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance); UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance);
$invoice_repo->markSent($invoice); $invoice_repo->markSent($invoice);
@ -169,8 +169,8 @@ class RandomDataSeeder extends Seeder
if(rand(0, 1)) { if(rand(0, 1)) {
$payment = App\Models\Payment::create([ $payment = App\Models\Payment::create([
'date' => now(), 'date' => now(),
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $company->id, 'company_id' => $company->id,
'client_id' => $client->id, 'client_id' => $client->id,
'amount' => $invoice->balance, 'amount' => $invoice->balance,
'transaction_reference' => rand(0,500), 'transaction_reference' => rand(0,500),
@ -180,13 +180,13 @@ class RandomDataSeeder extends Seeder
$payment->invoices()->save($invoice); $payment->invoices()->save($invoice);
event(new PaymentWasCreated($payment)); event(new PaymentWasCreated($payment, $payment->company));
UpdateInvoicePayment::dispatchNow($payment, $payment->company); UpdateInvoicePayment::dispatchNow($payment, $payment->company);
} }
}); });
/** Recurring Invoice Factory */ /** Recurring Invoice Factory */
factory(\App\Models\RecurringInvoice::class,10)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); factory(\App\Models\RecurringInvoice::class,10)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
@ -210,7 +210,7 @@ class RandomDataSeeder extends Seeder
'settings' => ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()), 'settings' => ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()),
'name' => 'Default Client Settings', 'name' => 'Default Client Settings',
]); ]);
if(config('ninja.testvars.stripe')) if(config('ninja.testvars.stripe'))
{ {