1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Merge pull request #6299 from turbo124/v5-develop

Return 200 HTTP code on webhook response from payfast.
This commit is contained in:
David Bomba 2021-07-20 17:23:57 +10:00 committed by GitHub
commit cdcd58a098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 12273 additions and 67 deletions

View File

@ -144,7 +144,10 @@ class StoreClientRequest extends Request
return $item->iso_3166_2 == $country_code || $item->iso_3166_3 == $country_code;
})->first();
return (string) $country->id;
if($country)
return (string) $country->id;
return "";
}
private function getCurrencyCode($code)

View File

@ -1139,7 +1139,10 @@ class Import implements ShouldQueue
$payment->save(['timestamps' => false]);
if (array_key_exists('company_gateway_id', $resource) && isset($resource['company_gateway_id']) && $resource['company_gateway_id'] != 'NULL') {
$payment->company_gateway_id = $this->transformId('company_gateways', $resource['company_gateway_id']);
if($this->tryTransformingId('company_gateways', $resource['company_gateway_id']))
$payment->company_gateway_id = $this->transformId('company_gateways', $resource['company_gateway_id']);
$payment->save();
}

View File

@ -71,18 +71,20 @@ class ReminderJob implements ShouldQueue
if ($invoice->isPayable()) {
$reminder_template = $invoice->calculateTemplate('invoice');
$invoice->service()->touchReminder($reminder_template)->save();
$invoice = $this->calcLateFee($invoice, $reminder_template);
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number}");
});
//check if this reminder needs to be emailed
if(in_array($reminder_template, ['reminder1','reminder2','reminder3']) && $invoice->client->getSetting("enable_".$reminder_template))
{
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number}");
});
if ($invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template));
if ($invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template));
}
}
$invoice->service()->setReminder()->save();
} else {

View File

@ -111,12 +111,9 @@ class WebhookHandler implements ShouldQueue
try {
$response = $client->post($subscription->target_url, [
RequestOptions::JSON => $data, // or 'json' => [...]
]);
if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200)
$subscription->delete();
$response = $client->post($subscription->target_url, [
RequestOptions::JSON => $data, // or 'json' => [...]
]);
SystemLogger::dispatch(
$response,
@ -127,10 +124,13 @@ class WebhookHandler implements ShouldQueue
$this->company
);
// if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200)
// return true;// $subscription->delete();
}
catch(\Exception $e){
// nlog($e->getMessage());
nlog($e->getMessage());
SystemLogger::dispatch(
$e->getMessage(),
@ -143,8 +143,6 @@ class WebhookHandler implements ShouldQueue
}
}
public function failed($exception)

View File

@ -62,7 +62,7 @@ class SupportMessageSent extends Mailable
$user = auth()->user();
if(Ninja::isHosted())
$subject = "{$priority}Hosted-{$company->db} :: Customer Support - [{$plan}] ".date('M jS, g:ia');
$subject = "{$priority}Hosted-{$company->db} :: Customer Support - {$plan} ".date('M jS, g:ia');
else
$subject = "{$priority}Self Hosted :: Customer Support - [{$plan}] ".date('M jS, g:ia');

View File

@ -19,6 +19,8 @@ use App\Models\Webhook;
class InvoiceObserver
{
public $afterCommit = true;
/**
* Handle the client "created" event.
*
@ -27,6 +29,7 @@ class InvoiceObserver
*/
public function created(Invoice $invoice)
{
$subscriptions = Webhook::where('company_id', $invoice->company->id)
->where('event_id', Webhook::EVENT_CREATE_INVOICE)
->exists();

View File

@ -283,7 +283,7 @@ class BaseDriver extends AbstractPaymentDriver
$fee_total = $this->payment_hash->fee_total;
/*Hydrate invoices*/
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->get();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) use ($fee_total) {
if (collect($invoice->line_items)->contains('type_id', '3')) {
@ -303,7 +303,7 @@ class BaseDriver extends AbstractPaymentDriver
*/
public function unWindGatewayFees(PaymentHash $payment_hash)
{
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->get();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) {
$invoice->service()->removeUnpaidGatewayFees();
@ -384,7 +384,7 @@ class BaseDriver extends AbstractPaymentDriver
$nmo->company = $gateway->client->company;
$nmo->settings = $gateway->client->company->settings;
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice){

View File

@ -271,7 +271,7 @@ class BasePaymentDriver
public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment
{
$paid_invoices = $payment_hash->invoices();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$payment->invoices()->sync($invoices);
$payment->save();
@ -300,7 +300,7 @@ class BasePaymentDriver
// $invoice_totals = array_sum(array_column($payment_invoices,'amount'));
/*Hydrate invoices*/
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->get();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) use ($fee_total) {
if (collect($invoice->line_items)->contains('type_id', '3')) {

View File

@ -149,7 +149,7 @@ class BraintreePaymentDriver extends BaseDriver
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first();
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";

View File

@ -198,7 +198,7 @@ class CheckoutComPaymentDriver extends BaseDriver
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first();
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";

View File

@ -61,7 +61,7 @@ class CustomPaymentDriver extends BaseDriver
if (count($this->payment_hash->invoices()) > 0) {
$invoice_id = $this->decodePrimaryKey($this->payment_hash->invoices()[0]->invoice_id);
$invoice = Invoice::findOrFail($invoice_id);
$invoice = Invoice::withTrashed()->find($invoice_id);
$variables = (new HtmlEngine($invoice->invitations->first()))->generateLabelsAndValues();
}

View File

@ -248,7 +248,7 @@ class CreditCard
$payment = $this->payfast->createPayment($payment_record, Payment::STATUS_COMPLETED);
return redirect()->route('client.payments.show', ['payment' => $this->payfast->encodePrimaryKey($payment->id)]);
//return redirect()->route('client.payments.show', ['payment' => $this->payfast->encodePrimaryKey($payment->id)]);
}
private function processUnsuccessfulPayment($server_response)

View File

@ -169,6 +169,7 @@ class PayFastPaymentDriver extends BaseDriver
{
$data = $request->all();
nlog("payfast");
nlog($data);
if(array_key_exists('m_payment_id', $data))
@ -179,17 +180,23 @@ class PayFastPaymentDriver extends BaseDriver
switch ($hash)
{
case 'cc_auth':
return $this->setPaymentMethod(GatewayType::CREDIT_CARD)
->authorizeResponse($request);
$this->setPaymentMethod(GatewayType::CREDIT_CARD)
->authorizeResponse($request);
return response()->json([], 200);
break;
default:
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$data['m_payment_id']])->first();
return $this->setPaymentMethod(GatewayType::CREDIT_CARD)
->setPaymentHash($payment_hash)
->processPaymentResponse($request);
$this->setPaymentMethod(GatewayType::CREDIT_CARD)
->setPaymentHash($payment_hash)
->processPaymentResponse($request);
return response()->json([], 200);
break;
}

View File

@ -199,7 +199,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
{
$_invoice = collect($this->payment_hash->data->invoices)->first();
$invoice = Invoice::findOrFail($this->decodePrimaryKey($_invoice->invoice_id));
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id));
$line_item = collect($invoice->line_items)->first();

View File

@ -60,7 +60,8 @@ class ACH
$customer = $this->stripe->findOrCreateCustomer();
try {
$source = $this->stripe->stripe->customers->createSource($customer->id, ['source' => $stripe_response->token->id]);
$source = Customer::createSource($customer->id, ['source' => $stripe_response->token->id], $this->stripe->stripe_connect_auth);
// $source = $this->stripe->stripe->customers->createSource($customer->id, ['source' => $stripe_response->token->id]);
} catch (InvalidRequestException $e) {
throw new PaymentFailed($e->getMessage(), $e->getCode());
}

View File

@ -52,7 +52,7 @@ class Charge
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first();
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->stripe->client->present()->name()}";
@ -62,7 +62,6 @@ class Charge
$this->stripe->init();
$response = null;
try {
@ -75,7 +74,7 @@ class Charge
'confirm' => true,
'description' => $description,
];
nlog($data);
$response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth);
// $response = $local_stripe->paymentIntents->create($data);

View File

@ -51,8 +51,8 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder1) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
$date_collection->push($reminder_date);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
if (is_null($this->invoice->reminder1_sent) &&
@ -60,7 +60,7 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder1) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
@ -69,8 +69,8 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder1) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
$date_collection->push($reminder_date);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
if (is_null($this->invoice->reminder2_sent) &&
@ -78,7 +78,7 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder2) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
@ -87,7 +87,7 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder2) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
@ -96,7 +96,7 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder2) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
@ -105,7 +105,7 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder3) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
@ -114,7 +114,7 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder3) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
@ -123,16 +123,24 @@ class UpdateReminder extends AbstractService
$this->settings->enable_reminder3) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
if ($this->invoice->last_sent_date &&
$this->settings->enable_reminder_endless) {
$reminder_date = $this->addTimeInterval($this->invoice->last_sent_date, (int)$this->settings->endless_reminder_frequency_id)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
$date_collection->push($reminder_date);
$reminder_date = $this->addTimeInterval($this->invoice->last_sent_date, (int)$this->settings->endless_reminder_frequency_id);
if($reminder_date){
$reminder_date->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
$date_collection->push($reminder_date);
}
}
if($date_collection->count() >=1 && $date_collection->sort()->first()->gte(now()))
@ -143,6 +151,20 @@ class UpdateReminder extends AbstractService
return $this->invoice;
}
private function testReminderValid($reminder_number, $reminder_schedule) :bool
{
$reminder_sent = "reminder{$reminder_number}_sent";
$schedule_reminder = "schedule_reminder{$reminder_number}";
$enable_reminder = "enable_reminder{$reminder_number}";
$late_fee_amount = "late_fee_amount{$reminder_number}";
$late_fee_percent = "late_fee_percent{$reminder_number}";
return (is_null($this->invoice->{$reminder_sent}) &&
$this->settings->{$schedule_reminder} == $reminder_schedule &&
($this->settings->{$enable_reminder} || $late_fee_percent > 0 || $late_fee_amount > 0));
}
private function addTimeInterval($date, $endless_reminder_frequency_id) :?Carbon
{

12188
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -86,9 +86,13 @@ class ReminderTest extends TestCase
{
$this->invoice->date = now()->subDays(2)->format('Y-m-d');
$this->invoice->due_date = Carbon::now()->addDays(30)->format('Y-m-d');
$this->invoice->due_date = now()->addDays(30)->format('Y-m-d');
$this->invoice->reminder1_sent = now()->subDays(1)->format('Y-m-d');
$this->invoice->last_sent_date = now()->subDays(1)->format('Y-m-d');
$this->invoice->next_send_date = now()->subDays(1)->format('Y-m-d');
$this->invoice->reminder2_sent = null;
$settings = $this->company->settings;
$settings->enable_reminder1 = true;
$settings->schedule_reminder1 = 'after_invoice_date';