mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for Stripe (#3702)
* Fixes for tests * Fixes for Stripe * Mail jobs
This commit is contained in:
parent
263d1fd61b
commit
d3b29d8ae2
76
app/Jobs/Mail/EntitySentEmail.php
Normal file
76
app/Jobs/Mail/EntitySentEmail.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class EntitySentEmail implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $user;
|
||||
|
||||
public $invitation;
|
||||
|
||||
public $entity_type;
|
||||
|
||||
public $entity;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($invitation, $entity_type, $user, $company)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->invitation = $invitation;
|
||||
|
||||
$this->entity = $invitation->{$entity_type};
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver($this->entity->client->getSetting('email_sending_method'));
|
||||
|
||||
}
|
||||
|
||||
private function setMailDriver(string $driver)
|
||||
{
|
||||
switch ($driver) {
|
||||
case 'default':
|
||||
break;
|
||||
case 'gmail':
|
||||
$this->setGmailMailer();
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
if($driver == 'default')
|
||||
return;
|
||||
}
|
||||
|
||||
private function setGmailMailer()
|
||||
{
|
||||
$sending_user = $this->entity->client->getSetting('gmail_sending_user_id');
|
||||
|
||||
}
|
||||
}
|
@ -55,7 +55,9 @@ class InvoiceEmailedNotification implements ShouldQueue
|
||||
|
||||
//Fire mail notification here!!!
|
||||
//This allows us better control of how we
|
||||
//handle the mailer
|
||||
//handle the mailer
|
||||
|
||||
EntitySentEmail::dispatch($invitation, 'invoice', $user, $invitation->company);
|
||||
}
|
||||
|
||||
$notification->method = $methods;
|
||||
|
@ -289,6 +289,9 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
$customer = $payment_intent->customer;
|
||||
|
||||
if ($payment_status == 'succeeded') {
|
||||
|
||||
$charge_id = $payment_intent->charges->data[0]->id;
|
||||
|
||||
$this->init();
|
||||
$stripe_payment_method = \Stripe\PaymentMethod::retrieve($payment_method);
|
||||
$stripe_payment_method_obj = $stripe_payment_method->jsonSerialize();
|
||||
@ -333,7 +336,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
|
||||
|
||||
$data = [
|
||||
'payment_method' => $payment_method,
|
||||
'payment_method' => $charge_id,
|
||||
'payment_type' => $payment_type,
|
||||
'amount' => $server_response->amount,
|
||||
];
|
||||
@ -471,12 +474,12 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function refund(Payment $payment, $amount = null)
|
||||
public function refund(Payment $payment, $amount)
|
||||
{
|
||||
$this->gateway();
|
||||
|
||||
$response = $this->gateway
|
||||
->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount ?? $payment->amount])
|
||||
->refund(['transactionReference'=>$payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
|
||||
->send();
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
|
@ -165,12 +165,11 @@ trait Refundable
|
||||
$credit_note->number = $this->client->getNextCreditNumber($this->client);
|
||||
$credit_note->save();
|
||||
|
||||
if ($data['gateway_refund'] !== false) {
|
||||
if ($data['gateway_refund'] !== false && $total_refund > 0) {
|
||||
$gateway = CompanyGateway::find($this->company_gateway_id);
|
||||
|
||||
if ($gateway) {
|
||||
$amount = request()->has('amount') ? request()->amount : null;
|
||||
$response = $gateway->driver($this->client)->refund($this, $amount);
|
||||
$response = $gateway->driver($this->client)->refund($this, $total_refund);
|
||||
|
||||
if (!$response) {
|
||||
throw new PaymentRefundFailed();
|
||||
|
@ -34,63 +34,29 @@ class CreditTest extends TestCase
|
||||
public function testCreditsList()
|
||||
{
|
||||
|
||||
Account::all()->each(function($account) {
|
||||
$account->delete();
|
||||
});
|
||||
|
||||
$data = [
|
||||
'first_name' => $this->faker->firstName,
|
||||
'last_name' => $this->faker->lastName,
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token(),
|
||||
'privacy_policy' => 1,
|
||||
'terms_of_service' => 1
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
])->post('/api/v1/signup?include=account', $data);
|
||||
|
||||
$acc = $response->json();
|
||||
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$company_token = $account->default_company->tokens()->first();
|
||||
$token = $company_token->token;
|
||||
$company = $company_token->company;
|
||||
|
||||
$user = $company_token->user;
|
||||
|
||||
$this->assertNotNull($company_token);
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
|
||||
factory(Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
||||
factory(Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) {
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id,
|
||||
'company_id' => $this->company->id,
|
||||
'is_primary' => 1
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id
|
||||
'company_id' => $this->company->id
|
||||
]);
|
||||
});
|
||||
|
||||
$client = Client::all()->first();
|
||||
|
||||
factory(Credit::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
factory(Credit::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/credits');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
Loading…
x
Reference in New Issue
Block a user