mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #6299 from turbo124/v5-develop
Return 200 HTTP code on webhook response from payfast.
This commit is contained in:
commit
cdcd58a098
@ -144,7 +144,10 @@ class StoreClientRequest extends Request
|
||||
return $item->iso_3166_2 == $country_code || $item->iso_3166_3 == $country_code;
|
||||
})->first();
|
||||
|
||||
if($country)
|
||||
return (string) $country->id;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private function getCurrencyCode($code)
|
||||
|
@ -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') {
|
||||
|
||||
if($this->tryTransformingId('company_gateways', $resource['company_gateway_id']))
|
||||
$payment->company_gateway_id = $this->transformId('company_gateways', $resource['company_gateway_id']);
|
||||
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,11 @@ class ReminderJob implements ShouldQueue
|
||||
if ($invoice->isPayable()) {
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
$invoice->service()->touchReminder($reminder_template)->save();
|
||||
|
||||
$invoice = $this->calcLateFee($invoice, $reminder_template);
|
||||
|
||||
//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}");
|
||||
@ -82,7 +84,7 @@ class ReminderJob implements ShouldQueue
|
||||
if ($invoice->invitations->count() > 0) {
|
||||
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template));
|
||||
}
|
||||
|
||||
}
|
||||
$invoice->service()->setReminder()->save();
|
||||
|
||||
} else {
|
||||
|
@ -115,9 +115,6 @@ class WebhookHandler implements ShouldQueue
|
||||
RequestOptions::JSON => $data, // or 'json' => [...]
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200)
|
||||
$subscription->delete();
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$response,
|
||||
SystemLog::CATEGORY_WEBHOOK,
|
||||
@ -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)
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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){
|
||||
|
||||
|
@ -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')) {
|
||||
|
@ -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()}";
|
||||
|
@ -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()}";
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
$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)
|
||||
$this->setPaymentMethod(GatewayType::CREDIT_CARD)
|
||||
->setPaymentHash($payment_hash)
|
||||
->processPaymentResponse($request);
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -51,7 +51,7 @@ 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)));
|
||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||
$date_collection->push($reminder_date);
|
||||
}
|
||||
|
||||
@ -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,7 +69,7 @@ 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)));
|
||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||
$date_collection->push($reminder_date);
|
||||
}
|
||||
|
||||
@ -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)));
|
||||
$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
12188
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -86,8 +86,12 @@ 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;
|
||||
|
Loading…
Reference in New Issue
Block a user