diff --git a/app/Classes/General/Abstracts/AbstractControllerLogic.php b/app/Classes/General/Abstracts/AbstractControllerLogic.php index 815219c8..dd463ec5 100644 --- a/app/Classes/General/Abstracts/AbstractControllerLogic.php +++ b/app/Classes/General/Abstracts/AbstractControllerLogic.php @@ -14,6 +14,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\ResourceCollection; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -54,7 +55,7 @@ abstract class AbstractControllerLogic public function execute(Request $request) : JsonResponse { try { - if(Auth::user()){ + if(Auth::user() && App::environment('production')){ if(Auth::user()->type === 3) UserRiskAnalysis::dispatch(Auth::user(), $request->header('captcha-token')); } diff --git a/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php index fa6a9ae7..45398678 100644 --- a/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php +++ b/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php @@ -155,7 +155,9 @@ class CreateCustomerLogic extends AbstractControllerLogic CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject); } - $this->generateEmailVerificationAttemptProcessor->execute($user); + if (App::environment(['production'])) { + $this->generateEmailVerificationAttemptProcessor->execute($user); + } $this->newCustomerToVoucherifyProcessor->execute($company->id, $user, true); diff --git a/config/database.php b/config/database.php index ac0b718b..129244bc 100644 --- a/config/database.php +++ b/config/database.php @@ -63,6 +63,26 @@ return [ ]) : [], ], + 'mysql_test' => [ + 'driver' => 'mysql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE_TEST', 'exchange_test'), + 'username' => env('DB_USERNAME', 'root'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => false, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], + ], + 'dusk' => [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), diff --git a/database/seeds/CompaniesTableSeeder.php b/database/seeds/CompaniesTableSeeder.php index 51122432..0c587ca6 100644 --- a/database/seeds/CompaniesTableSeeder.php +++ b/database/seeds/CompaniesTableSeeder.php @@ -1,5 +1,6 @@ - - + + diff --git a/tests/Feature/Accounts/CheckEmailControllerTest.php b/tests/Feature/Accounts/CheckEmailControllerTest.php new file mode 100644 index 00000000..19f24aa7 --- /dev/null +++ b/tests/Feature/Accounts/CheckEmailControllerTest.php @@ -0,0 +1,53 @@ +postJson(route('api.account.registration.register', [ + "company_name" => "", + "name" => "user one", + "email" => "user1@mail.com", + "password" => "password", + "password_confirmation" => "password", + "phone" => "0123456789", + "type" => 0 + ])); + + $response = $this->postJson(route('api.account.authentication.authenticate.email.check', [ + 'email' => 'user1@mail.com', + ])); + + $response->assertStatus(200)->assertJson([ + "title" => "User found Successful", + "message" => "Account Already Exists", + "payload" => [] + ]); + } + + public function testNonExistingUserEmail() + { + $response = $this->postJson(route('api.account.authentication.authenticate.email.check', [ + 'email' => 'user2@mail.com', + ])); + + // dd($response); + + $response->assertStatus(404)->assertJson([ + "title" => "User found failed", + "message" => "Unable to find any record based on the criteria provided", + "payload" => [] + ]); + } +} diff --git a/tests/Feature/Accounts/UserAuthenticationControllerTest.php b/tests/Feature/Accounts/UserAuthenticationControllerTest.php new file mode 100644 index 00000000..60b20600 --- /dev/null +++ b/tests/Feature/Accounts/UserAuthenticationControllerTest.php @@ -0,0 +1,45 @@ +postJson(route('api.account.registration.register', [ + "company_name" => "", + "name" => "user one", + "email" => "user1@mail.com", + "password" => "password", + "password_confirmation" => "password", + "phone" => "0123456789", + "type" => 0 + ])); + + $response = $this->postJson(route('api.account.authentication.authenticate.attempt', [ + 'email' => 'user1@mail.com', + 'password' => 'password' + ])); + + $response->assertStatus(200); + } + + public function test_non_existing_user_login() + { + $response = $this->postJson(route('api.account.authentication.authenticate.attempt', [ + 'email' => 'user2@mail.com', + 'password' => 'password' + ])); + + $response->assertStatus(401); + } +} diff --git a/tests/Feature/Bookings/CreateBookingControllerTest.php b/tests/Feature/Bookings/CreateBookingControllerTest.php new file mode 100644 index 00000000..0eb3378d --- /dev/null +++ b/tests/Feature/Bookings/CreateBookingControllerTest.php @@ -0,0 +1,186 @@ +seed(CountriesTableSeeder::class); + $this->seed(CurrenciesTableSeeder::class); + $this->seed(CompaniesTableSeeder::class); + + // create currency rate + DB::table('currency_rates')->insert(array ( + 0 => + array ( + 'id' => 1, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_cash, + 'payment_method_type' => 1, + 'service_id' => 1, + ), + 1 => + array ( + 'id' => 2, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_cheque, + 'payment_method_type' => 2, + 'service_id' => 1, + ), + 2 => + array ( + 'id' => 3, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_wallet, + 'payment_method_type' => 4, + 'service_id' => 1, + ), + 3 => + array ( + 'id' => 4, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_online, + 'payment_method_type' => 5, + 'service_id' => 1, + ) + )); + + // create service + DB::table('service_types')->insert([ + 'id' => 1, + 'name' => 'X1 Transfer', + 'status' => 2, + ]); + + // create standard segment + DB::table('segments')->insert([ + 'id' => 1, + 'name' => 'Standard Segment', + 'type' => SegmentConstants::STANDARD_SEGMENT, + 'status' => 2 + ]); + // create platinum segment + DB::table('segments')->insert([ + 'id' => 2, + 'name' => 'platinum member', + 'type' => SegmentConstants::CUSTOM_SEGMENT, + 'status' => 2, + ]); + // create standard segment constant + DB::table('segment_constants')->insert([ + 'id' => 1, + 'segment_id' => 1, + 'name' => 'Service Type', + 'reference' => 'SERVICE_TYPE', + 'detail' => '{"id":1,"bank_id":1,"service_charge":{"type":"percentage","value":2},"minimum_charge":{"type":"fixed_amount","value":10},"tax":{"type":"percentage","value":0},"po_limit":{"type":"fixed_amount","value":3},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":100},"rates":[]}]}', + ]); + // create platinum segment constant + DB::table('segment_constants')->insert([ + 'id' => 2, + 'segment_id' => 2, + 'name' => 'Custom Service Type', + 'reference' => 'CUSTOM_SERVICE_TYPE', + 'detail' => '{"id":1,"minimum_charge":{"type":"fixed_amount","value":0},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":0.01},"rates":[{"payment_type":1,"payment_method":"cash","selling":{"type":"rate","value":"1.54100"}},{"payment_type":2,"payment_method":"cheque","selling":{"type":"rate","value":"1.53100"}},{"payment_type":4,"payment_method":"wallet","selling":{"type":"rate","value":"1.54700"}},{"payment_type":5,"payment_method":"payment_gateway","selling":{"type":"rate","value":"1.54400"}}]}]}', + ]); + + // create a user + $this->postJson(route('api.account.registration.register', [ + "company_name" => "", + "name" => "user one", + "email" => "user1@mail.com", + "password" => "password", + "password_confirmation" => "password", + "phone" => "0123456789", + "type" => 0 + ])); + + $response = $this->postJson(route('api.account.authentication.authenticate.attempt', [ + 'email' => 'user1@mail.com', + 'password' => 'password' + ])); + + $company = Company::where('name', 'user one')->first(); + + // create recipient bank + DB::table('banks')->insert([ + 'company_id' => $company->id, + 'bank_name' => 'Maybank', + 'holder_name' => 'user one recipient', + 'account_no' => '123456789', + 'country_id' => 2, + 'status' => 2, + 'type' => 2, + ]); + + $token = json_decode($response->getContent(), true)['payload']['access_token']; + + $this->withHeaders([ + 'Accept' => 'application/json', + 'Authorization' => "Bearer $token", + 'Captcha-Token' => "test" + ]); + + } + + public function test_create_booking() + { + $company = Company::where('name', 'user one')->first(); + + $foreign_total = 1000; + + $quotation_response = $this->postJson(route('api.company.currency.convert', [ + 'id' => $company->id, + 'amount' => $foreign_total, + 'currency_id' => 2, + 'service_id' => 1, + 'type' => 1, + ])); + + $recipient_bank = $company->banks->where('type', BankAccountType::EXTERNAL)->first(); + + $response = $this->postJson(route('api.booking.create', ['company_id' => $company->id]), + [ + 'convertible_currency_id' => 2, + 'fix_amount' => json_decode($quotation_response->getContent(), true)['payload']['data']['foreign_total'], + 'service_id' => 1, + 'transferable_bank_id' => $recipient_bank->id, + 'type' => 1, + ]); + + $response->assertStatus(200); + + $this->assertDatabaseHas("bookings", [ + "company_id" => $company->id, + "service_id" => 1, + "bank_id" => $recipient_bank->id, + "fix_amount" => $foreign_total, + "fix_currency_id" => 2, + "convertible_currency_id" => 2, + "conversion_currency_id" => 1, + "status" => 2 + ]); + } +} diff --git a/tests/Feature/Companies/FetchBookingPaymentQuotationControllerTest.php b/tests/Feature/Companies/FetchBookingPaymentQuotationControllerTest.php new file mode 100644 index 00000000..9e83c7f1 --- /dev/null +++ b/tests/Feature/Companies/FetchBookingPaymentQuotationControllerTest.php @@ -0,0 +1,597 @@ +seed(CountriesTableSeeder::class); + $this->seed(CurrenciesTableSeeder::class); + $this->seed(CompaniesTableSeeder::class); + + // create currency rate + DB::table('currency_rates')->insert(array ( + 0 => + array ( + 'id' => 1, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_cash, + 'payment_method_type' => 1, + 'service_id' => 1, + ), + 1 => + array ( + 'id' => 2, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_cheque, + 'payment_method_type' => 2, + 'service_id' => 1, + ), + 2 => + array ( + 'id' => 3, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_wallet, + 'payment_method_type' => 4, + 'service_id' => 1, + ), + 3 => + array ( + 'id' => 4, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_online, + 'payment_method_type' => 5, + 'service_id' => 1, + ) + )); + + // create service + DB::table('service_types')->insert([ + 'id' => 1, + 'name' => 'X1 Transfer', + 'status' => 2, + ]); + + // create standard segment + DB::table('segments')->insert([ + 'id' => 1, + 'name' => 'Standard Segment', + 'type' => SegmentConstants::STANDARD_SEGMENT, + 'status' => 2 + ]); + // create platinum segment + DB::table('segments')->insert([ + 'id' => 2, + 'name' => 'platinum member', + 'type' => SegmentConstants::CUSTOM_SEGMENT, + 'status' => 2, + ]); + // create standard segment constant + DB::table('segment_constants')->insert([ + 'id' => 1, + 'segment_id' => 1, + 'name' => 'Service Type', + 'reference' => 'SERVICE_TYPE', + 'detail' => '{"id":1,"bank_id":1,"service_charge":{"type":"percentage","value":2},"minimum_charge":{"type":"fixed_amount","value":10},"tax":{"type":"percentage","value":0},"po_limit":{"type":"fixed_amount","value":3},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":100},"rates":[]}]}', + ]); + // create platinum segment constant + DB::table('segment_constants')->insert([ + 'id' => 2, + 'segment_id' => 2, + 'name' => 'Custom Service Type', + 'reference' => 'CUSTOM_SERVICE_TYPE', + 'detail' => '{"id":1,"minimum_charge":{"type":"fixed_amount","value":0},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":0.01},"rates":[{"payment_type":1,"payment_method":"cash","selling":{"type":"rate","value":"1.54100"}},{"payment_type":2,"payment_method":"cheque","selling":{"type":"rate","value":"1.53100"}},{"payment_type":4,"payment_method":"wallet","selling":{"type":"rate","value":"1.54700"}},{"payment_type":5,"payment_method":"payment_gateway","selling":{"type":"rate","value":"1.54400"}}]}]}', + ]); + + // create a user + $this->postJson(route('api.account.registration.register', [ + "company_name" => "", + "name" => "user one", + "email" => "user1@mail.com", + "password" => "password", + "password_confirmation" => "password", + "phone" => "0123456789", + "type" => 0 + ])); + + $response = $this->postJson(route('api.account.authentication.authenticate.attempt', [ + 'email' => 'user1@mail.com', + 'password' => 'password' + ])); + + $company = Company::where('name', 'user one')->first(); + + // create recipient bank + DB::table('banks')->insert([ + 'company_id' => $company->id, + 'bank_name' => 'Maybank', + 'holder_name' => 'user one recipient', + 'account_no' => '123456789', + 'country_id' => 2, + 'status' => 2, + 'type' => 2, + ]); + + $token = json_decode($response->getContent(), true)['payload']['access_token']; + + $this->withHeaders([ + 'Accept' => 'application/json', + 'Authorization' => "Bearer $token", + 'Captcha-Token' => "test" + ]); + + $recipient_bank = $company->banks->where('type', BankAccountType::EXTERNAL)->first(); + + // create booking + $this->postJson(route('api.booking.create', ['company_id' => $company->id]), + [ + 'convertible_currency_id' => 2, + 'fix_amount' => 1000, + 'service_id' => 1, + 'transferable_bank_id' => $recipient_bank->id, + 'type' => 1, + ]); + + } + + public function test_standard_customer_fetch_booking_payment_quotation_cash() + { + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_std_cash; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', [ + 'id' => $booking->id, + 'amount' => 1000, + 'payment_method' => 'cash', + 'voucherCode' => '' + ])); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_std_cash, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_standard_customer_fetch_booking_payment_quotation_cheque() + { + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_std_cheque; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]), + [ + 'amount' => 1000, + 'payment_method' => 'cheque', + 'voucherCode' => '' + ]); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_std_cheque, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_standard_customer_fetch_booking_payment_quotation_wallet() + { + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_std_wallet; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]), + [ + 'amount' => 1000, + 'payment_method' => 'wallet', + 'voucherCode' => '' + ]); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_std_wallet, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_standard_customer_fetch_booking_payment_quotation_online() + { + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_std_online; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]), + [ + 'amount' => 1000, + 'payment_method' => 'payment_gateway', + 'voucherCode' => '' + ]); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_std_online, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_platinum_customer_fetch_booking_payment_quotation_cash() + { + $company = Company::where('name', 'user one')->first(); + + DB::table('segment_companies')->insert([ + 'segment_id' => 2, + 'company_id' => $company->id, + ]); + + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_plat_cash; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', [ + 'id' => $booking->id, + 'amount' => 1000, + 'payment_method' => 'cash', + 'voucherCode' => '' + ])); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_plat_cash, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_platinum_customer_fetch_booking_payment_quotation_cheque() + { + $company = Company::where('name', 'user one')->first(); + + DB::table('segment_companies')->insert([ + 'segment_id' => 2, + 'company_id' => $company->id, + ]); + + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_plat_cheque; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]), + [ + 'amount' => 1000, + 'payment_method' => 'cheque', + 'voucherCode' => '' + ]); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_plat_cheque, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_platinum_customer_fetch_booking_payment_quotation_wallet() + { + $company = Company::where('name', 'user one')->first(); + + DB::table('segment_companies')->insert([ + 'segment_id' => 2, + 'company_id' => $company->id, + ]); + + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_plat_wallet; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]), + [ + 'amount' => 1000, + 'payment_method' => 'wallet', + 'voucherCode' => '' + ]); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_plat_wallet, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } + + public function test_platinum_customer_fetch_booking_payment_quotation_online() + { + $company = Company::where('name', 'user one')->first(); + + DB::table('segment_companies')->insert([ + 'segment_id' => 2, + 'company_id' => $company->id, + ]); + + $booking = Booking::first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_plat_online; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + $response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]), + [ + 'amount' => 1000, + 'payment_method' => 'payment_gateway', + 'voucherCode' => '' + ]); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_plat_online, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + } +} diff --git a/tests/Feature/Companies/FetchCompanyBookingQuotationControllerTest.php b/tests/Feature/Companies/FetchCompanyBookingQuotationControllerTest.php new file mode 100644 index 00000000..ed8e147f --- /dev/null +++ b/tests/Feature/Companies/FetchCompanyBookingQuotationControllerTest.php @@ -0,0 +1,189 @@ +seed(CountriesTableSeeder::class); + $this->seed(CurrenciesTableSeeder::class); + $this->seed(CompaniesTableSeeder::class); + + // create currency rate + DB::table('currency_rates')->insert(array ( + 0 => + array ( + 'id' => 1, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_cash, + 'payment_method_type' => 1, + 'service_id' => 1, + ), + 1 => + array ( + 'id' => 2, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_cheque, + 'payment_method_type' => 2, + 'service_id' => 1, + ), + 2 => + array ( + 'id' => 3, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_wallet, + 'payment_method_type' => 4, + 'service_id' => 1, + ), + 3 => + array ( + 'id' => 4, + 'currency_id' => 2, + 'selling' => $this->curr_rate_std_online, + 'payment_method_type' => 5, + 'service_id' => 1, + ) + )); + + // create service + DB::table('service_types')->insert([ + 'id' => 1, + 'name' => 'X1 Transfer', + 'status' => 2, + ]); + + // create standard segment + DB::table('segments')->insert([ + 'id' => 1, + 'name' => 'Standard Segment', + 'type' => SegmentConstants::STANDARD_SEGMENT, + 'status' => 2 + ]); + // create platinum segment + DB::table('segments')->insert([ + 'id' => 2, + 'name' => 'platinum member', + 'type' => SegmentConstants::CUSTOM_SEGMENT, + 'status' => 2, + ]); + // create standard segment constant + DB::table('segment_constants')->insert([ + 'id' => 1, + 'segment_id' => 1, + 'name' => 'Service Type', + 'reference' => 'SERVICE_TYPE', + 'detail' => '{"id":1,"bank_id":1,"service_charge":{"type":"percentage","value":2},"minimum_charge":{"type":"fixed_amount","value":10},"tax":{"type":"percentage","value":0},"po_limit":{"type":"fixed_amount","value":3},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":100},"rates":[]}]}', + ]); + // create platinum segment constant + // Rate + // 1. Cash: + DB::table('segment_constants')->insert([ + 'id' => 2, + 'segment_id' => 2, + 'name' => 'Custom Service Type', + 'reference' => 'CUSTOM_SERVICE_TYPE', + 'detail' => '{"id":1,"minimum_charge":{"type":"fixed_amount","value":0},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":0.01},"rates":[{"payment_type":1,"payment_method":"cash","selling":{"type":"rate","value":"1.54100"}},{"payment_type":2,"payment_method":"cheque","selling":{"type":"rate","value":"1.53100"}},{"payment_type":4,"payment_method":"wallet","selling":{"type":"rate","value":"1.54700"}},{"payment_type":5,"payment_method":"payment_gateway","selling":{"type":"rate","value":"1.54400"}}]}]}', + ]); + + // create a user + $this->postJson(route('api.account.registration.register', [ + "company_name" => "", + "name" => "user one", + "email" => "user1@mail.com", + "password" => "password", + "password_confirmation" => "password", + "phone" => "0123456789", + "type" => 0 + ])); + + $response = $this->postJson(route('api.account.authentication.authenticate.attempt', [ + 'email' => 'user1@mail.com', + 'password' => 'password' + ])); + + $token = json_decode($response->getContent(), true)['payload']['access_token']; + + $this->withHeaders([ + 'Accept' => 'application/json', + 'Authorization' => "Bearer $token", + 'Captcha-Token' => "test" + ]); + + } + + public function test_standard_customer_fetch_booking_quotation_cash() + { + $company = Company::where('name', 'user one')->first(); + + $foreign_total = 1000; + $local_total = 1000 / $this->curr_rate_std_cash; + $conversion_amount = $local_total; + $service_charge = $conversion_amount * 0.02; + $sub_total = $local_total + $service_charge; + + + $response = $this->postJson(route('api.company.currency.convert', [ + 'id' => $company->id, + 'amount' => $foreign_total, + 'currency_id' => 2, + 'service_id' => 1, + 'type' => 1, + ])); + + $response->assertStatus(200)->assertJsonStructure([ + "title", + "message", + "payload" => [ + "data" => [ + "conversion_amount", + "foreign_total", + "local_total", + "rate", + "service_charge", + "sub_total", + "tax", + "tax_total", + "total", + "voucher_code", + "voucher_discount_amount" + ] + ] + ]); + + $data = json_decode($response->getContent(), true)['payload']['data']; + $this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001); + $this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001); + $this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001); + $this->assertEqualsWithDelta($this->curr_rate_std_cash, $data['rate'], 0.0000001); + $this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001); + $this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001); + $this->assertEquals(0, $data['tax']); + $this->assertEquals(0, $data['tax_total']); + $this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001); + $this->assertEquals("", $data['voucher_code']); + $this->assertEquals(0, $data['voucher_discount_amount']); + + } +}