diff --git a/app/DataMapper/PaymentMethodMeta.php b/app/DataMapper/PaymentMethodMeta.php new file mode 100644 index 000000000000..5585f70448c4 --- /dev/null +++ b/app/DataMapper/PaymentMethodMeta.php @@ -0,0 +1,25 @@ +transformKeys(request()->input('invoice_ids'))) @@ -114,7 +114,7 @@ class PaymentController extends Controller 'fee' => $gateway->calcGatewayFee($amount), 'amount_with_fee' => ($amount + $gateway->calcGatewayFee($amount)), 'gateway' => $gateway, - 'payment_method_id' => $payment_method_id, + 'gateway_type_id' => $gateway_type_id, 'token' => auth()->user()->client->gateway_token($gateway->id), ]; diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 00eacb07ff56..b6e978710612 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -12,8 +12,10 @@ namespace App\Http\Controllers\ClientPortal; use App\Http\Controllers\Controller; +use App\Models\ClientGatewayToken; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; +use Yajra\DataTables\Facades\DataTables; class PaymentMethodController extends Controller { @@ -25,7 +27,32 @@ class PaymentMethodController extends Controller */ public function index() { - echo 'list of payment methods here'; + $payment_methods = ClientGatewayToken::whereClientId(auth()->user()->client->id); + + if (request()->ajax()) { + + return DataTables::of($payment_methods)->addColumn('action', function ($invoice) { + return ''.ctrans('texts.view').''; + }) + ->editColumn('status_id', function ($invoice){ + return Invoice::badgeForStatus($invoice->status); + })->editColumn('invoice_date', function ($invoice){ + return $this->formatDate($invoice->invoice_date, $invoice->client->date_format()); + })->editColumn('due_date', function ($invoice){ + return $this->formatDate($invoice->due_date, $invoice->client->date_format()); + })->editColumn('balance', function ($invoice) { + return Number::formatMoney($invoice->balance, $invoice->client); + })->editColumn('amount', function ($invoice) { + return Number::formatMoney($invoice->amount, $invoice->client); + }) + ->rawColumns(['action', 'status_id']) + ->make(true); + + } + + $data['html'] = $builder; + + return view('portal.default.payment_methods.index', $data); } /** diff --git a/app/Models/ClientGatewayToken.php b/app/Models/ClientGatewayToken.php index b72d3b83b3e4..a2d72af8b2c7 100644 --- a/app/Models/ClientGatewayToken.php +++ b/app/Models/ClientGatewayToken.php @@ -14,11 +14,16 @@ namespace App\Models; use App\Models\Client; use App\Models\Company; use App\Models\CompanyGateway; +use App\Models\GatewayType; use App\Models\User; class ClientGatewayToken extends BaseModel { + protected $casts = [ + 'meta' => 'object', + ]; + public function client() { return $this->hasOne(Client::class); @@ -29,6 +34,11 @@ class ClientGatewayToken extends BaseModel return $this->hasOne(CompanyGateway::class); } + public function gateway_type() + { + return $this->hasOne(GatewayType::class); + } + public function company() { return $this->hasOne(Company::class); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 34384afcd5ba..cbd8c0dcef8e 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -94,9 +94,9 @@ class StripePaymentDriver extends BasePaymentDriver } - public function viewForType($payment_type) + public function viewForType($gateway_type_id) { - switch ($payment_type) { + switch ($gateway_type_id) { case GatewayType::CREDIT_CARD: return 'portal.default.gateways.stripe.credit_card'; break; @@ -142,25 +142,36 @@ class StripePaymentDriver extends BasePaymentDriver $server_response = json_decode($request->input('gateway_response')); $gateway_id = $request->input('gateway_id'); - $gateway_type_id = $request->input('payment_method_id'); + $gateway_type_id = $request->input('gateway_type_id'); $is_default = $request->input('is_default'); $payment_method = $server_response->payment_method; - $this->init(); - $customer = $this->findOrCreateCustomer(); + $this->init(); $stripe_payment_method = \Stripe\PaymentMethod::retrieve($payment_method); + $stripe_payment_method_obj = $stripe_payment_method->jsonSerialize(); $stripe_payment_method->attach(['customer' => $customer->id]); + $payment_meta = new \stdClass; + + if($stripe_payment_method_obj['type'] == 'card') { + $payment_meta->exp_month = $stripe_payment_method_obj['card']['exp_month']; + $payment_meta->exp_year = $stripe_payment_method_obj['card']['exp_year']; + $payment_meta->brand = $stripe_payment_method_obj['card']['brand']; + $payment_meta->last4 = $stripe_payment_method_obj['card']['last4']; + $payment_meta->type = $stripe_payment_method_obj['type']; + } + $cgt = new ClientGatewayToken; $cgt->company_id = $this->client->company->id; $cgt->client_id = $this->client->id; $cgt->token = $payment_method; $cgt->company_gateway_id = $this->company_gateway->id; - $cgt->payment_method_id = $gateway_type_id; + $cgt->gateway_type_id = $gateway_type_id; $cgt->gateway_customer_reference = $customer->id; + $cgt->meta = $payment_meta; $cgt->save(); diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index ccae173e58a6..46b5bd9903d0 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -349,7 +349,7 @@ class CreateUsersTable extends Migration $table->unsignedInteger('company_id')->unique(); $table->unsignedInteger('user_id'); $table->unsignedInteger('gateway_id'); - $table->unsignedInteger('gateway_type_id')->nullable(); + $table->text('gateway_types')->default(''); $table->unsignedInteger('accepted_credit_cards'); $table->boolean('require_cvv')->default(true); $table->boolean('show_address')->default(true)->nullable(); @@ -401,7 +401,7 @@ class CreateUsersTable extends Migration $t->text('line_items')->default(''); $t->text('settings')->default(''); - $t->text('backup')->default(''); + $t->text('backup')->nullable(); $t->text('footer')->default(''); $t->text('public_notes')->default(''); @@ -457,7 +457,7 @@ class CreateUsersTable extends Migration $t->text('line_items')->default(''); $t->text('settings')->default(''); - $t->text('backup')->default(''); + $t->text('backup')->nullable(); $t->text('footer')->default(''); $t->text('public_notes')->default(''); @@ -517,7 +517,7 @@ class CreateUsersTable extends Migration $t->text('line_items')->default(''); $t->text('settings')->default(''); - $t->text('backup')->default(''); + $t->text('backup')->nullable(); $t->text('footer')->default(''); $t->text('public_notes')->default(''); @@ -574,7 +574,7 @@ class CreateUsersTable extends Migration $t->text('line_items')->default(''); $t->text('settings')->default(''); - $t->text('backup')->default(''); + $t->text('backup')->nullable(); $t->text('footer')->default(''); $t->text('public_notes')->default(''); @@ -705,7 +705,7 @@ class CreateUsersTable extends Migration $t->decimal('amount', 13, 2)->default(0); $t->datetime('payment_date')->nullable(); $t->string('transaction_reference')->nullable(); - $t->string('payer_id')->default(''); + $t->string('payer_id')->nullable(); $t->timestamps(6); $t->softDeletes(); $t->boolean('is_deleted')->default(false); @@ -867,7 +867,7 @@ class CreateUsersTable extends Migration Schema::create('backups', function ($table) { $table->increments('id'); $table->unsignedInteger('activity_id'); - $table->text('json_backup')->default(''); + $table->text('json_backup')->nullable(); $table->timestamps(6); $table->foreign('activity_id')->references('id')->on('activities')->onDelete('cascade'); @@ -908,8 +908,9 @@ class CreateUsersTable extends Migration $table->text('token')->default(''); $table->unsignedInteger('company_gateway_id'); $table->string('gateway_customer_reference')->default(''); - $table->unsignedInteger('payment_method_id'); + $table->unsignedInteger('gateway_type_id'); $table->boolean('is_default')->default(0); + $table->text('meta')->default(''); $table->softDeletes(); $table->timestamps(6); diff --git a/resources/views/portal/default/gateways/pay_now.blade.php b/resources/views/portal/default/gateways/pay_now.blade.php index ac14ee0f06fc..e55099e5b655 100644 --- a/resources/views/portal/default/gateways/pay_now.blade.php +++ b/resources/views/portal/default/gateways/pay_now.blade.php @@ -49,7 +49,7 @@ - @include($gateway->driver(auth()->user()->client)->viewForType($payment_method_id)) + @include($gateway->driver(auth()->user()->client)->viewForType($gateway_type_id)) diff --git a/resources/views/portal/default/gateways/stripe/create_customer.blade.php b/resources/views/portal/default/gateways/stripe/create_customer.blade.php index 49e34df48c2a..2c07cf6e25c8 100644 --- a/resources/views/portal/default/gateways/stripe/create_customer.blade.php +++ b/resources/views/portal/default/gateways/stripe/create_customer.blade.php @@ -10,7 +10,7 @@ ->method('POST'); !!} {!! Former::hidden('company_gateway_id')->value($gateway->gateway_id) !!} - {!! Former::hidden('payment_method_id')->value($gateway->gateway_type_id) !!} + {!! Former::hidden('gateway_type_id')->value($gateway->gateway_type_id) !!} {!! Former::hidden('gateway_response')->id('gateway_response') !!} {!! Former::hidden('is_default')->id('is_default') !!} diff --git a/resources/views/portal/default/payment_methods/index.blade.php b/resources/views/portal/default/payment_methods/index.blade.php new file mode 100644 index 000000000000..973233d7c493 --- /dev/null +++ b/resources/views/portal/default/payment_methods/index.blade.php @@ -0,0 +1,99 @@ +@extends('portal.default.layouts.master') +@section('header') + @parent + + +@stop +@section('body') +
+
+ +{!! Former::framework('TwitterBootstrap4'); !!} + +{!! Former::horizontal_open() + ->id('payment_form') + ->route('client.invoices.bulk') + ->method('POST'); !!} + +{!! Former::hidden('hashed_ids')->id('hashed_ids') !!} +{!! Former::hidden('action')->id('action') !!} + +{!! Former::close() !!} + + + +
+
+ +@endsection +@push('scripts') + + + + +@endpush + diff --git a/tests/Feature/RecurringInvoicesCronTest.php b/tests/Feature/RecurringInvoicesCronTest.php index 51c43d30f743..56509b2cdef3 100644 --- a/tests/Feature/RecurringInvoicesCronTest.php +++ b/tests/Feature/RecurringInvoicesCronTest.php @@ -48,7 +48,7 @@ class RecurringInvoicesCronTest extends TestCase $recurring_invoices->each(function ($inv, $key) { - Log::error(Carbon::parse($inv->next_send_date)->format(config('ninja.date_time_format'))); + // Log::error(Carbon::parse($inv->next_send_date)->format(config('ninja.date_time_format'))); });