mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01:00
commit
7f1c290d23
3
.env.ci
3
.env.ci
@ -19,4 +19,5 @@ DB_HOST=127.0.0.1
|
||||
NINJA_ENVIRONMENT=hosted
|
||||
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
|
||||
TRAVIS=true
|
||||
API_SECRET=superdoopersecrethere
|
||||
API_SECRET=superdoopersecrethere
|
||||
PHANTOMJS_PDF_GENERATION=false
|
||||
|
@ -7,8 +7,8 @@
|
||||
### Fixed:
|
||||
- Fixes for counters where patterns without {$counter} could causes endless recursion.
|
||||
- Fixes for surcharge tax displayed amount on PDF.
|
||||
|
||||
### Removed:
|
||||
- Fixes for custom designs not rendering the custom template
|
||||
- Fixes for missing bulk actions on Subscriptions
|
||||
|
||||
## v5.1.43
|
||||
|
||||
|
10
app/Exceptions/FilePermissionsFailure.php
Normal file
10
app/Exceptions/FilePermissionsFailure.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FilePermissionsFailure extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Exceptions\InternalPDFFailure;
|
||||
use App\Exceptions\PhantomPDFFailure;
|
||||
use Exception;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
@ -94,7 +97,7 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
}
|
||||
|
||||
if(config('ninja.expanded_logging'))
|
||||
// if(config('ninja.expanded_logging'))
|
||||
parent::report($exception);
|
||||
|
||||
}
|
||||
@ -134,6 +137,12 @@ class Handler extends ExceptionHandler
|
||||
{
|
||||
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>$exception->getMessage()], 400);
|
||||
}elseif($exception instanceof InternalPDFFailure && $request->expectsJson()){
|
||||
return response()->json(['message' => $exception->getMessage()], 500);
|
||||
}elseif($exception instanceof PhantomPDFFailure && $request->expectsJson()){
|
||||
return response()->json(['message' => $exception->getMessage()], 500);
|
||||
}elseif($exception instanceof FilePermissionsFailure) {
|
||||
return response()->json(['message' => $exception->getMessage()], 500);
|
||||
} elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Too many requests'], 429);
|
||||
} elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {
|
||||
@ -152,8 +161,7 @@ class Handler extends ExceptionHandler
|
||||
} elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Method not support for this route'], 404);
|
||||
} elseif ($exception instanceof ValidationException && $request->expectsJson()) {
|
||||
info(print_r($exception->validator->getMessageBag(), 1));
|
||||
|
||||
nlog($exception->validator->getMessageBag());
|
||||
return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
|
||||
} elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
@ -161,9 +169,7 @@ class Handler extends ExceptionHandler
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
} elseif ($exception instanceof GenericPaymentDriverFailure) {
|
||||
$data['message'] = $exception->getMessage();
|
||||
//dd($data);
|
||||
// return view('errors.layout', $data);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
10
app/Exceptions/InternalPDFFailure.php
Normal file
10
app/Exceptions/InternalPDFFailure.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InternalPDFFailure extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
10
app/Exceptions/PhantomPDFFailure.php
Normal file
10
app/Exceptions/PhantomPDFFailure.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class PhantomPDFFailure extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
@ -61,6 +62,9 @@ class SelfUpdateController extends BaseController
|
||||
return response()->json(['message' => ctrans('texts.self_update_not_available')], 403);
|
||||
}
|
||||
|
||||
if(!$this->testWritable())
|
||||
throw new FilePermissionsFailure('Cannot update system because files are not writable!');
|
||||
|
||||
// Check if new version is available
|
||||
if($updater->source()->isNewVersionAvailable()) {
|
||||
|
||||
@ -90,6 +94,19 @@ class SelfUpdateController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
private function testWritable()
|
||||
{
|
||||
$directoryIterator = new \RecursiveDirectoryIterator(base_path());
|
||||
|
||||
foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) {
|
||||
if ($file->isFile() && ! $file->isWritable()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkVersion()
|
||||
{
|
||||
return trim(file_get_contents(config('ninja.version_url')));
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace App\Jobs\Entity;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Models\Account;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
@ -168,6 +169,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
else {
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
nlog(print_r($e->getMessage(), 1));
|
||||
}
|
||||
@ -176,8 +178,20 @@ class CreateEntityPdf implements ShouldQueue
|
||||
info($maker->getCompiledHTML());
|
||||
}
|
||||
|
||||
|
||||
if ($pdf) {
|
||||
Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
try{
|
||||
|
||||
Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
|
||||
throw new FilePermissionsFailure('Could not write the PDF, permission issues!');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
|
242
app/PaymentDrivers/Stripe/Connect/Account.php
Normal file
242
app/PaymentDrivers/Stripe/Connect/Account.php
Normal file
@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\PaymentDrivers\Stripe\Connect;
|
||||
|
||||
use App\Exceptions\PaymentFailed;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Jobs\Mail\PaymentFailureMailer;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\StripePaymentDriver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Exception;
|
||||
use Stripe\Customer;
|
||||
use Stripe\Exception\CardException;
|
||||
use Stripe\Exception\InvalidRequestException;
|
||||
|
||||
class Account
|
||||
{
|
||||
|
||||
//https://stripe.com/docs/api/accounts/object?lang=php
|
||||
/**
|
||||
*
|
||||
capabilities.acss_debit_payments
|
||||
string
|
||||
The status of the ACSS Direct Debits payments capability of the account, or whether the account can directly process ACSS Direct Debits charges.
|
||||
|
||||
capabilities.afterpay_clearpay_payments
|
||||
string
|
||||
The status of the Afterpay Clearpay capability of the account, or whether the account can directly process Afterpay Clearpay charges.
|
||||
|
||||
capabilities.au_becs_debit_payments
|
||||
string
|
||||
The status of the BECS Direct Debit (AU) payments capability of the account, or whether the account can directly process BECS Direct Debit (AU) charges.
|
||||
|
||||
capabilities.bacs_debit_payments
|
||||
string
|
||||
The status of the Bacs Direct Debits payments capability of the account, or whether the account can directly process Bacs Direct Debits charges.
|
||||
|
||||
capabilities.bancontact_payments
|
||||
string
|
||||
The status of the Bancontact payments capability of the account, or whether the account can directly process Bancontact charges.
|
||||
|
||||
capabilities.card_issuing
|
||||
string
|
||||
The status of the card issuing capability of the account, or whether you can use Issuing to distribute funds on cards
|
||||
|
||||
capabilities.card_payments
|
||||
string
|
||||
The status of the card payments capability of the account, or whether the account can directly process credit and debit card charges.
|
||||
|
||||
capabilities.cartes_bancaires_payments
|
||||
string
|
||||
The status of the Cartes Bancaires payments capability of the account, or whether the account can directly process Cartes Bancaires card charges in EUR currency.
|
||||
|
||||
capabilities.eps_payments
|
||||
string
|
||||
The status of the EPS payments capability of the account, or whether the account can directly process EPS charges.
|
||||
|
||||
capabilities.fpx_payments
|
||||
string
|
||||
The status of the FPX payments capability of the account, or whether the account can directly process FPX charges.
|
||||
|
||||
capabilities.giropay_payments
|
||||
string
|
||||
The status of the giropay payments capability of the account, or whether the account can directly process giropay charges.
|
||||
|
||||
capabilities.grabpay_payments
|
||||
string
|
||||
The status of the GrabPay payments capability of the account, or whether the account can directly process GrabPay charges.
|
||||
|
||||
capabilities.ideal_payments
|
||||
string
|
||||
The status of the iDEAL payments capability of the account, or whether the account can directly process iDEAL charges.
|
||||
|
||||
capabilities.jcb_payments
|
||||
string
|
||||
The status of the JCB payments capability of the account, or whether the account (Japan only) can directly process JCB credit card charges in JPY currency.
|
||||
|
||||
capabilities.legacy_payments
|
||||
string
|
||||
The status of the legacy payments capability of the account.
|
||||
|
||||
capabilities.oxxo_payments
|
||||
string
|
||||
The status of the OXXO payments capability of the account, or whether the account can directly process OXXO charges.
|
||||
|
||||
capabilities.p24_payments
|
||||
string
|
||||
The status of the P24 payments capability of the account, or whether the account can directly process P24 charges.
|
||||
|
||||
capabilities.sepa_debit_payments
|
||||
string
|
||||
The status of the SEPA Direct Debits payments capability of the account, or whether the account can directly process SEPA Direct Debits charges.
|
||||
|
||||
capabilities.sofort_payments
|
||||
string
|
||||
The status of the Sofort payments capability of the account, or whether the account can directly process Sofort charges.
|
||||
|
||||
capabilities.tax_reporting_us_1099_k
|
||||
string
|
||||
The status of the tax reporting 1099-K (US) capability of the account.
|
||||
|
||||
capabilities.tax_reporting_us_1099_misc
|
||||
string
|
||||
The status of the tax reporting 1099-MISC (US) capability of the account.
|
||||
|
||||
capabilities.transfers
|
||||
string
|
||||
The status of the transfers capability of the account, or whether your platform can transfer funds to the account.
|
||||
*/
|
||||
|
||||
///
|
||||
// $stripe = new \Stripe\StripeClient(
|
||||
// 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
|
||||
// );
|
||||
// $stripe->accounts->create([
|
||||
// 'type' => 'custom',
|
||||
// 'country' => 'US',
|
||||
// 'email' => 'jenny.rosen@example.com',
|
||||
// 'capabilities' => [
|
||||
// 'card_payments' => ['requested' => true],
|
||||
// 'transfers' => ['requested' => true],
|
||||
// ],
|
||||
// ]);
|
||||
///
|
||||
|
||||
|
||||
//response
|
||||
|
||||
/**
|
||||
* {
|
||||
"id": "acct_1032D82eZvKYlo2C",
|
||||
"object": "account",
|
||||
"business_profile": {
|
||||
"mcc": null,
|
||||
"name": "Stripe.com",
|
||||
"product_description": null,
|
||||
"support_address": null,
|
||||
"support_email": null,
|
||||
"support_phone": null,
|
||||
"support_url": null,
|
||||
"url": null
|
||||
},
|
||||
"capabilities": {
|
||||
"card_payments": "active",
|
||||
"transfers": "active"
|
||||
},
|
||||
"charges_enabled": false,
|
||||
"country": "US",
|
||||
"default_currency": "usd",
|
||||
"details_submitted": false,
|
||||
"email": "site@stripe.com",
|
||||
"metadata": {},
|
||||
"payouts_enabled": false,
|
||||
"requirements": {
|
||||
"current_deadline": null,
|
||||
"currently_due": [
|
||||
"business_profile.product_description",
|
||||
"business_profile.support_phone",
|
||||
"business_profile.url",
|
||||
"external_account",
|
||||
"tos_acceptance.date",
|
||||
"tos_acceptance.ip"
|
||||
],
|
||||
"disabled_reason": "requirements.past_due",
|
||||
"errors": [],
|
||||
"eventually_due": [
|
||||
"business_profile.product_description",
|
||||
"business_profile.support_phone",
|
||||
"business_profile.url",
|
||||
"external_account",
|
||||
"tos_acceptance.date",
|
||||
"tos_acceptance.ip"
|
||||
],
|
||||
"past_due": [],
|
||||
"pending_verification": []
|
||||
},
|
||||
"settings": {
|
||||
"bacs_debit_payments": {},
|
||||
"branding": {
|
||||
"icon": null,
|
||||
"logo": null,
|
||||
"primary_color": null,
|
||||
"secondary_color": null
|
||||
},
|
||||
"card_issuing": {
|
||||
"tos_acceptance": {
|
||||
"date": null,
|
||||
"ip": null
|
||||
}
|
||||
},
|
||||
"card_payments": {
|
||||
"decline_on": {
|
||||
"avs_failure": true,
|
||||
"cvc_failure": false
|
||||
},
|
||||
"statement_descriptor_prefix": null
|
||||
},
|
||||
"dashboard": {
|
||||
"display_name": "Stripe.com",
|
||||
"timezone": "US/Pacific"
|
||||
},
|
||||
"payments": {
|
||||
"statement_descriptor": null,
|
||||
"statement_descriptor_kana": null,
|
||||
"statement_descriptor_kanji": null
|
||||
},
|
||||
"payouts": {
|
||||
"debit_negative_balances": true,
|
||||
"schedule": {
|
||||
"delay_days": 7,
|
||||
"interval": "daily"
|
||||
},
|
||||
"statement_descriptor": null
|
||||
},
|
||||
"sepa_debit_payments": {}
|
||||
},
|
||||
"type": "standard"
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//then create the account link
|
||||
|
||||
// https://stripe.com/docs/api/account_links/create?lang=php
|
||||
}
|
436
app/PaymentDrivers/StripeConnectPaymentDriver.php
Normal file
436
app/PaymentDrivers/StripeConnectPaymentDriver.php
Normal file
@ -0,0 +1,436 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\PaymentDrivers;
|
||||
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\Stripe\ACH;
|
||||
use App\PaymentDrivers\Stripe\Alipay;
|
||||
use App\PaymentDrivers\Stripe\Charge;
|
||||
use App\PaymentDrivers\Stripe\CreditCard;
|
||||
use App\PaymentDrivers\Stripe\SOFORT;
|
||||
use App\PaymentDrivers\Stripe\Utilities;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Exception;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Stripe\Customer;
|
||||
use Stripe\Exception\ApiErrorException;
|
||||
use Stripe\PaymentIntent;
|
||||
use Stripe\PaymentMethod;
|
||||
use Stripe\SetupIntent;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\StripeClient;
|
||||
|
||||
class StripeConnectPaymentDriver extends BaseDriver
|
||||
{
|
||||
use MakesHash, Utilities;
|
||||
|
||||
public $refundable = true;
|
||||
|
||||
public $token_billing = true;
|
||||
|
||||
public $can_authorise_credit_card = true;
|
||||
|
||||
/** @var \Stripe\StripeClient */
|
||||
public $stripe;
|
||||
|
||||
protected $customer_reference = 'customerReferenceParam';
|
||||
|
||||
public $payment_method;
|
||||
|
||||
public static $methods = [
|
||||
GatewayType::CREDIT_CARD => CreditCard::class,
|
||||
GatewayType::BANK_TRANSFER => ACH::class,
|
||||
GatewayType::ALIPAY => Alipay::class,
|
||||
GatewayType::SOFORT => SOFORT::class,
|
||||
GatewayType::APPLE_PAY => 1, // TODO
|
||||
GatewayType::SEPA => 1, // TODO
|
||||
];
|
||||
|
||||
const SYSTEM_LOG_TYPE = SystemLog::TYPE_STRIPE;
|
||||
|
||||
/**
|
||||
* Initializes the Stripe API.
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->stripe = new StripeClient(
|
||||
$this->company_gateway->getConfigField('apiKey')
|
||||
);
|
||||
|
||||
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
|
||||
}
|
||||
|
||||
public function setPaymentMethod($payment_method_id)
|
||||
{
|
||||
$class = self::$methods[$payment_method_id];
|
||||
|
||||
$this->payment_method = new $class($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the gateway types.
|
||||
*/
|
||||
public function gatewayTypes(): array
|
||||
{
|
||||
$types = [
|
||||
GatewayType::CREDIT_CARD,
|
||||
GatewayType::CRYPTO,
|
||||
// GatewayType::SEPA, // TODO: Missing implementation
|
||||
// GatewayType::APPLE_PAY, // TODO:: Missing implementation
|
||||
];
|
||||
|
||||
if ($this->client
|
||||
&& isset($this->client->country)
|
||||
&& in_array($this->client->country->iso_3166_3, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP'])) {
|
||||
$types[] = GatewayType::SOFORT;
|
||||
}
|
||||
|
||||
if ($this->client
|
||||
&& isset($this->client->country)
|
||||
&& in_array($this->client->country->iso_3166_3, ['USA'])) {
|
||||
$types[] = GatewayType::BANK_TRANSFER;
|
||||
}
|
||||
|
||||
if ($this->client
|
||||
&& isset($this->client->country)
|
||||
&& in_array($this->client->country->iso_3166_3, ['AUS', 'DNK', 'DEU', 'ITA', 'LUX', 'NOR', 'SVN', 'GBR', 'AUT', 'EST', 'GRC', 'JPN', 'MYS', 'PRT', 'ESP', 'USA', 'BEL', 'FIN', 'HKG', 'LVA', 'NLD', 'SGP', 'SWE', 'CAN', 'FRA', 'IRL', 'LTU', 'NZL', 'SVK', 'CHE'])) {
|
||||
$types[] = GatewayType::ALIPAY;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
public function viewForType($gateway_type_id)
|
||||
{
|
||||
switch ($gateway_type_id) {
|
||||
case GatewayType::CREDIT_CARD:
|
||||
return 'gateways.stripe.credit_card';
|
||||
break;
|
||||
case GatewayType::SOFORT:
|
||||
return 'gateways.stripe.sofort';
|
||||
break;
|
||||
case GatewayType::BANK_TRANSFER:
|
||||
return 'gateways.stripe.ach';
|
||||
break;
|
||||
case GatewayType::SEPA:
|
||||
return 'gateways.stripe.sepa';
|
||||
break;
|
||||
case GatewayType::CRYPTO:
|
||||
case GatewayType::ALIPAY:
|
||||
case GatewayType::APPLE_PAY:
|
||||
return 'gateways.stripe.other';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getClientRequiredFields(): array
|
||||
{
|
||||
$fields = [
|
||||
['name' => 'client_postal_code', 'label' => ctrans('texts.postal_code'), 'type' => 'text', 'validation' => 'required'],
|
||||
];
|
||||
|
||||
if ($this->company_gateway->require_client_name) {
|
||||
$fields[] = ['name' => 'client_name', 'label' => ctrans('texts.client_name'), 'type' => 'text', 'validation' => 'required'];
|
||||
}
|
||||
|
||||
if ($this->company_gateway->require_client_phone) {
|
||||
$fields[] = ['name' => 'client_phone', 'label' => ctrans('texts.client_phone'), 'type' => 'tel', 'validation' => 'required'];
|
||||
}
|
||||
|
||||
if ($this->company_gateway->require_contact_name) {
|
||||
$fields[] = ['name' => 'contact_first_name', 'label' => ctrans('texts.first_name'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'contact_last_name', 'label' => ctrans('texts.last_name'), 'type' => 'text', 'validation' => 'required'];
|
||||
}
|
||||
|
||||
if ($this->company_gateway->require_contact_email) {
|
||||
$fields[] = ['name' => 'contact_email', 'label' => ctrans('texts.email'), 'type' => 'text', 'validation' => 'required,email:rfc'];
|
||||
}
|
||||
|
||||
if ($this->company_gateway->require_billing_address) {
|
||||
$fields[] = ['name' => 'client_address_line_1', 'label' => ctrans('texts.address1'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_address_line_2', 'label' => ctrans('texts.address2'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_city', 'label' => ctrans('texts.city'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_state', 'label' => ctrans('texts.state'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_country_id', 'label' => ctrans('texts.country'), 'type' => 'text', 'validation' => 'required'];
|
||||
}
|
||||
|
||||
if ($this->company_gateway->require_shipping_address) {
|
||||
$fields[] = ['name' => 'client_shipping_address_line_1', 'label' => ctrans('texts.shipping_address1'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_shipping_address_line_2', 'label' => ctrans('texts.shipping_address2'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_shipping_city', 'label' => ctrans('texts.shipping_city'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_shipping_state', 'label' => ctrans('texts.shipping_state'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_shipping_postal_code', 'label' => ctrans('texts.shipping_postal_code'), 'type' => 'text', 'validation' => 'required'];
|
||||
$fields[] = ['name' => 'client_shipping_country_id', 'label' => ctrans('texts.shipping_country'), 'type' => 'text', 'validation' => 'required'];
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy method to pass the data into payment method authorizeView().
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
*/
|
||||
public function authorizeView(array $data)
|
||||
{
|
||||
return $this->payment_method->authorizeView($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the gateway response for credit card authorization.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
*/
|
||||
public function authorizeResponse($request)
|
||||
{
|
||||
return $this->payment_method->authorizeResponse($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the payment with gateway.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
*/
|
||||
public function processPaymentView(array $data)
|
||||
{
|
||||
return $this->payment_method->paymentView($data);
|
||||
}
|
||||
|
||||
public function processPaymentResponse($request)
|
||||
{
|
||||
return $this->payment_method->paymentResponse($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new String Payment Intent.
|
||||
*
|
||||
* @param array $data The data array to be passed to Stripe
|
||||
* @return PaymentIntent The Stripe payment intent object
|
||||
* @throws ApiErrorException
|
||||
*/
|
||||
public function createPaymentIntent($data): ?PaymentIntent
|
||||
{
|
||||
$this->init();
|
||||
|
||||
return PaymentIntent::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a setup intent that allows the user
|
||||
* to enter card details without initiating a transaction.
|
||||
*
|
||||
* @return SetupIntent
|
||||
* @throws ApiErrorException
|
||||
*/
|
||||
public function getSetupIntent(): SetupIntent
|
||||
{
|
||||
$this->init();
|
||||
|
||||
return SetupIntent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Stripe publishable key.
|
||||
* @return null|string The stripe publishable key
|
||||
*/
|
||||
public function getPublishableKey(): ?string
|
||||
{
|
||||
return $this->company_gateway->getPublishableKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds or creates a Stripe Customer object.
|
||||
*
|
||||
* @return null|Customer A Stripe customer object
|
||||
* @throws \Laracasts\Presenter\Exceptions\PresenterException
|
||||
* @throws ApiErrorException
|
||||
*/
|
||||
public function findOrCreateCustomer(): ?Customer
|
||||
{
|
||||
$customer = null;
|
||||
|
||||
$this->init();
|
||||
|
||||
$client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)->whereCompanyGatewayId($this->company_gateway->id)->first();
|
||||
|
||||
if ($client_gateway_token && $client_gateway_token->gateway_customer_reference) {
|
||||
$customer = Customer::retrieve($client_gateway_token->gateway_customer_reference);
|
||||
} else {
|
||||
$data['name'] = $this->client->present()->name();
|
||||
$data['phone'] = $this->client->present()->phone();
|
||||
|
||||
if (filter_var($this->client->present()->email(), FILTER_VALIDATE_EMAIL)) {
|
||||
$data['email'] = $this->client->present()->email();
|
||||
}
|
||||
|
||||
$customer = Customer::create($data);
|
||||
}
|
||||
|
||||
if (!$customer) {
|
||||
throw new Exception('Unable to create gateway customer');
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function refund(Payment $payment, $amount, $return_client_response = false)
|
||||
{
|
||||
$this->init();
|
||||
|
||||
/** Response from Stripe SDK/API. */
|
||||
$response = null;
|
||||
|
||||
try {
|
||||
$response = $this->stripe
|
||||
->refunds
|
||||
->create(['charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision)]);
|
||||
|
||||
if ($response->status == $response::STATUS_SUCCEEDED) {
|
||||
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
|
||||
|
||||
return [
|
||||
'transaction_reference' => $response->charge,
|
||||
'transaction_response' => json_encode($response),
|
||||
'success' => $response->status == $response::STATUS_SUCCEEDED ? true : false,
|
||||
'description' => $response->metadata,
|
||||
'code' => $response,
|
||||
];
|
||||
}
|
||||
|
||||
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||
|
||||
return [
|
||||
'transaction_reference' => null,
|
||||
'transaction_response' => json_encode($response),
|
||||
'success' => false,
|
||||
'description' => $response->failure_reason,
|
||||
'code' => 422,
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||
|
||||
nlog($e->getMessage());
|
||||
|
||||
return [
|
||||
'transaction_reference' => null,
|
||||
'transaction_response' => json_encode($response),
|
||||
'success' => false,
|
||||
'description' => $e->getMessage(),
|
||||
'code' => 422,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function verificationView(ClientGatewayToken $payment_method)
|
||||
{
|
||||
return $this->payment_method->verificationView($payment_method);
|
||||
}
|
||||
|
||||
public function processVerification(Request $request, ClientGatewayToken $payment_method)
|
||||
{
|
||||
return $this->payment_method->processVerification($request, $payment_method);
|
||||
}
|
||||
|
||||
public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment)
|
||||
{
|
||||
if ($request->type == 'source.chargeable') {
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
return response([], 200);
|
||||
}
|
||||
|
||||
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
||||
{
|
||||
return (new Charge($this))->tokenBilling($cgt, $payment_hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach Stripe payment method to Stripe client.
|
||||
*
|
||||
* @param string $payment_method
|
||||
* @param mixed $customer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function attach(string $payment_method, $customer): void
|
||||
{
|
||||
try {
|
||||
$stripe_payment_method = $this->getStripePaymentMethod($payment_method);
|
||||
$stripe_payment_method->attach(['customer' => $customer->id]);
|
||||
} catch (ApiErrorException | Exception $e) {
|
||||
$this->processInternallyFailedPayment($this, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach payment method from the Stripe.
|
||||
* https://stripe.com/docs/api/payment_methods/detach
|
||||
*
|
||||
* @param ClientGatewayToken $token
|
||||
* @return void
|
||||
*/
|
||||
public function detach(ClientGatewayToken $token)
|
||||
{
|
||||
$stripe = new StripeClient(
|
||||
$this->company_gateway->getConfigField('apiKey')
|
||||
);
|
||||
|
||||
try {
|
||||
$stripe->paymentMethods->detach($token->token);
|
||||
} catch (Exception $e) {
|
||||
SystemLogger::dispatch([
|
||||
'server_response' => $e->getMessage(), 'data' => request()->all(),
|
||||
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCompanyGatewayId(): int
|
||||
{
|
||||
return $this->company_gateway->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payment method from Stripe.
|
||||
*
|
||||
* @param string $source
|
||||
*
|
||||
* @return PaymentMethod|void
|
||||
*/
|
||||
public function getStripePaymentMethod(string $source)
|
||||
{
|
||||
try {
|
||||
return PaymentMethod::retrieve($source);
|
||||
} catch (ApiErrorException | Exception $e) {
|
||||
return $this->processInternallyFailedPayment($this, $e);
|
||||
}
|
||||
}
|
||||
}
|
@ -183,7 +183,7 @@ class SubscriptionService
|
||||
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
}
|
||||
|
||||
public function calculateUpgradePrice(RecurringInvoice $recurring_invoice, Subscription $target)
|
||||
public function calculateUpgradePrice(RecurringInvoice $recurring_invoice, Subscription $target) :?float
|
||||
{
|
||||
//calculate based on daily prices
|
||||
|
||||
@ -206,14 +206,17 @@ class SubscriptionService
|
||||
//user has multiple amounts outstanding
|
||||
return $target->price - $this->calculateProRataRefund($outstanding->first());
|
||||
}
|
||||
elseif ($outstanding->count > 1) {
|
||||
elseif ($outstanding->count() > 1) {
|
||||
//user is changing plan mid frequency cycle
|
||||
//we cannot handle this if there are more than one invoice outstanding.
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private function calculateProRataRefund($invoice)
|
||||
private function calculateProRataRefund($invoice) :float
|
||||
{
|
||||
//determine the start date
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Utils\PhantomJS;
|
||||
|
||||
use App\Exceptions\PhantomPDFFailure;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Design;
|
||||
@ -91,8 +92,6 @@ class Phantom
|
||||
|
||||
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);
|
||||
|
||||
// nlog($instance);
|
||||
// nlog($file_path);
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
@ -128,6 +127,8 @@ class Phantom
|
||||
SystemLog::TYPE_PDF_FAILURE,
|
||||
$invitation->contact->client
|
||||
);
|
||||
|
||||
throw new PhantomPDFFailure('There was an error generating the PDF with Phantom JS');
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace App\Utils\Traits\Pdf;
|
||||
|
||||
use App\Exceptions\InternalPDFFailure;
|
||||
use Beganovich\Snappdf\Snappdf;
|
||||
|
||||
trait PdfMaker
|
||||
@ -33,8 +34,14 @@ trait PdfMaker
|
||||
$pdf->setChromiumPath(config('ninja.snappdf_chromium_path'));
|
||||
}
|
||||
|
||||
return $pdf
|
||||
->setHtml($html)
|
||||
->generate();
|
||||
$generated = $pdf
|
||||
->setHtml($html)
|
||||
->generate();
|
||||
|
||||
if($generated)
|
||||
return $generated;
|
||||
|
||||
|
||||
throw new InternalPDFFailure('There was an issue generating the PDF locally');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class StripeConnectGateway extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
$gateway = [
|
||||
'id' => 56,
|
||||
'name' => 'Stripe Connect',
|
||||
'provider' => 'StripeConnect',
|
||||
'sort_order' => 1,
|
||||
'key' => 'd14dd26a47cecc30fdd65700bfb67b34',
|
||||
'fields' => '{"apiKey":"", "publishableKey":""}'
|
||||
];
|
||||
|
||||
Gateway::create($gateway);
|
||||
|
||||
if(Ninja::isNinja())
|
||||
{
|
||||
Gateway::where('id', 20)->update(['visible' => 0]);
|
||||
Gateway::where('id', 56)->update(['visible' => 1]);
|
||||
}
|
||||
|
||||
Model::guard();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user