1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Working on payment failure emails

This commit is contained in:
David Bomba 2021-02-01 16:30:28 +11:00
parent 7e7564c085
commit c14d34350f
4 changed files with 25 additions and 6 deletions

View File

@ -69,6 +69,8 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
*/
public function handle()
{
nlog("payment failure mailer ");
/*If we are migrating data we don't want to fire these notification*/
if ($this->company->is_disabled) {
return true;
@ -81,11 +83,12 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
$this->setMailDriver();
//iterate through company_users
$this->company->company_users->each(function ($company_user) {
$this->company->company_users->each(function ($company_user) {
//determine if this user has the right permissions
$methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure']);
//if mail is a method type -fire mail!!
if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]);

View File

@ -333,13 +333,15 @@ class BaseDriver extends AbstractPaymentDriver
public function processInternallyFailedPayment($gateway, $e)
{
if ($e instanceof Exception) {
$error = $e->getMessage();
}
if ($e instanceof CheckoutHttpException) {
$error = $e->getBody();
}
else if ($e instanceof Exception) {
$error = $e->getMessage();
}
else
$error = $e->getMessage();
$amount = optional($this->payment_hash->data)->value ?? optional($this->payment_hash->data)->amount;

View File

@ -77,7 +77,7 @@ class Charge
'confirm' => true,
'description' => $description,
]);
info("attempting token billing");
SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (CardException $e) {
// Since it's a decline, \Stripe\Exception\CardException will be caught
@ -89,6 +89,7 @@ class Charge
'param' => $e->getError()->param,
'message' => $e->getError()->message,
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (RateLimitException $e) {
@ -101,7 +102,9 @@ class Charge
'param' => '',
'message' => 'Too many requests made to the API too quickly',
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (InvalidRequestException $e) {
// Invalid parameters were supplied to Stripe's API
@ -114,6 +117,8 @@ class Charge
'message' => 'Invalid parameters were supplied to Stripe\'s API',
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (AuthenticationException $e) {
// Authentication with Stripe's API failed
@ -126,6 +131,8 @@ class Charge
'message' => 'Authentication with Stripe\'s API failed',
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (ApiConnectionException $e) {
// Network communication with Stripe failed
@ -138,6 +145,8 @@ class Charge
'message' => 'Network communication with Stripe failed',
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (ApiErrorException $e) {
$data = [
@ -148,6 +157,8 @@ class Charge
'message' => 'API Error',
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
@ -160,6 +171,8 @@ class Charge
'message' => $e->getMessage(),
];
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
}

View File

@ -25,6 +25,7 @@ trait UserNotifies
$notifiable_methods = [];
$notifications = $company_user->notifications;
//if a user owns this record or is assigned to it, they are attached the permission for notification.
if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) {
array_push($required_permissions, 'all_user_notifications');
}