From 8944727d6b2cdaa05593aca3e0ffa01c2d7d4ca4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 15 Sep 2019 21:40:46 +1000 Subject: [PATCH] Working on client payment methods --- .../ClientPortal/PaymentMethodController.php | 1 - app/Models/CompanyGateway.php | 4 + app/PaymentDrivers/BasePaymentDriver.php | 3 + app/PaymentDrivers/StripePaymentDriver.php | 2 + database/seeds/RandomDataSeeder.php | 11 +- .../default/gateways/authorize.blade.php | 372 ------------------ tests/Feature/CompanyTest.php | 4 +- tests/Unit/EncryptionSettingsTest.php | 59 +++ 8 files changed, 74 insertions(+), 382 deletions(-) create mode 100644 tests/Unit/EncryptionSettingsTest.php diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 9e92c7a8fc20..629076c6ba8a 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -43,7 +43,6 @@ class PaymentMethodController extends Controller ]; return $gateway->driver()->authorizeCreditCardView($data); - //return view('portal.default.gateways.authorize', $data); } /** diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 2122f7e49346..fe9773902d1d 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -79,6 +79,7 @@ class CompanyGateway extends BaseModel */ public function getConfig() { + //return decrypt($this->config); return json_decode(decrypt($this->config)); } @@ -161,6 +162,9 @@ class CompanyGateway extends BaseModel */ public function getPublishableKey() :string { + \Log::error($this->config); + \Log::error(json_decode($this->config)); + \Log::error($this->getConfigField('publishableKey')); return $this->getConfigField('publishableKey'); } diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index c78280fcbe8a..7638104528f6 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -36,6 +36,9 @@ class BasePaymentDriver protected $token_billing = false; + protected $can_authorise_credit_card = false; + + public function __construct(CompanyGateway $company_gateway, $invitation = false) { $this->company_gateway = $company_gateway; diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index a9f818618f36..b7e1df7c4268 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -22,6 +22,8 @@ class StripePaymentDriver extends BasePaymentDriver protected $token_billing = true; + protected $can_authorise_credit_card = true; + protected $customer_reference = 'customerReferenceParam'; diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 4feae7e9562e..ad02f2066d58 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -130,12 +130,9 @@ class RandomDataSeeder extends Seeder ]); - \Log::error("stripe keys?"); - \Log::error(config('ninja.testvars.stripe')); - if(config('ninja.testvars.stripe')) { - \Log::error("inserting stripe keys"); + $cg = new CompanyGateway; $cg->company_id = $company->id; $cg->user_id = $user->id; @@ -145,13 +142,15 @@ class RandomDataSeeder extends Seeder $cg->show_address = true; $cg->show_shipping_address = true; $cg->update_details = true; - $cg->config = encrypt(env('STRIPE_KEYS')); + $cg->config = encrypt(json_encode(config('ninja.testvars.stripe'),true)); $cg->priority_id = 1; $cg->save(); + + \Log::error(decrypt($cg->config)); + } } - } diff --git a/resources/views/portal/default/gateways/authorize.blade.php b/resources/views/portal/default/gateways/authorize.blade.php index 7a03b937cea7..76cb28f78736 100644 --- a/resources/views/portal/default/gateways/authorize.blade.php +++ b/resources/views/portal/default/gateways/authorize.blade.php @@ -25,376 +25,4 @@ @endsection @push('scripts') - - - - - -@endpush -@push('css') - @endpush \ No newline at end of file diff --git a/tests/Feature/CompanyTest.php b/tests/Feature/CompanyTest.php index ddccd2f5d0a4..ea911d36c051 100644 --- a/tests/Feature/CompanyTest.php +++ b/tests/Feature/CompanyTest.php @@ -87,10 +87,8 @@ class CompanyTest extends TestCase ] ) ->assertStatus(200)->decodeResponseJson(); -//Log::error($response); - $company = Company::find($this->decodePrimaryKey($response['data']['company_users'][0]['company']['id'])); - + $company = Company::find($this->decodePrimaryKey($response['data']['company_users'][0]['company']['id'])); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), diff --git a/tests/Unit/EncryptionSettingsTest.php b/tests/Unit/EncryptionSettingsTest.php new file mode 100644 index 000000000000..575ffa2c54e5 --- /dev/null +++ b/tests/Unit/EncryptionSettingsTest.php @@ -0,0 +1,59 @@ +settings = '{"publishable_key":"publish","23_apiKey":"client","enable_ach":"1","enable_sofort":"1","enable_apple_pay":"1","enable_alipay":"1"}'; + + } + + public function testDecryption() + { + + $this->settings = encrypt($this->settings); + + + $this->assertEquals('publish', $this->getConfigField('publishable_key')); + $this->assertEquals('client', $this->getConfigField('23_apiKey')); + $this->assertEquals(1, $this->getConfigField('enable_ach')); + $this->assertEquals(1, $this->getConfigField('enable_sofort')); + } + + + + + /** + * @return mixed + */ + public function getConfig() + { + return json_decode(decrypt($this->settings)); + } + + /** + * @param $field + * + * @return mixed + */ + public function getConfigField($field) + { + return object_get($this->getConfig(), $field, false); + } +} + +