diff --git a/composer.json b/composer.json index b0122b8..91d5e77 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,11 @@ ], "require": { "php": "^8.1", + "ext-curl": "*", "ext-dom": "*", + "ext-simplexml": "*", "fintech/core": "*", + "fintech/transaction": "*", "illuminate/contracts": "^10.0", "owen-it/laravel-auditing": "^13.5" }, diff --git a/config/remit.php b/config/remit.php index 8537d9b..234e84b 100644 --- a/config/remit.php +++ b/config/remit.php @@ -1,6 +1,13 @@ \Fintech\Remit\Models\BankTransfer::class, + 'bank_transfer_model' => BankTransfer::class, /* |-------------------------------------------------------------------------- @@ -40,7 +47,7 @@ | | This value will be used to across system where model is needed */ - 'cash_pickup_model' => \Fintech\Remit\Models\CashPickup::class, + 'cash_pickup_model' => CashPickup::class, /* |-------------------------------------------------------------------------- @@ -49,7 +56,7 @@ | | This value will be used to across system where model is needed */ - 'wallet_transfer_model' => \Fintech\Remit\Models\WalletTransfer::class, + 'wallet_transfer_model' => WalletTransfer::class, //** Model Config Point Do not Remove **// @@ -113,16 +120,12 @@ 'mode' => 'sandbox', 'driver' => Fintech\Remit\Vendors\TransFastApi::class, 'live' => [ - 'endpoint' => 'https://fex.agranibank.org/remapiuat', - 'username' => '7106UAT', - 'password' => '7106@Pass', - 'excode' => '7106', + 'endpoint' => 'https://send.transfast.ws/api/', + 'token' => env('PACKAGE_REMIT_TRANS_FAST_TOKEN'), ], 'sandbox' => [ - 'endpoint' => 'https://fex.agranibank.org/remapiuat', - 'username' => '7086UAT', - 'password' => '7086@Pass', - 'excode' => '7086', + 'endpoint' => 'https://demo-api.transfast.net/api/', + 'token' => env('PACKAGE_REMIT_TRANS_FAST_TOKEN'), ], ], 'valyou' => [ @@ -141,6 +144,20 @@ 'excode' => '7086', ], ], + 'islamibank' => [ + 'mode' => 'sandbox', + 'driver' => Fintech\Remit\Vendors\IslamiBankApi::class, + 'live' => [ + 'endpoint' => 'https://ibblmtws.islamibankbd.com/ibblmtws/services/ImportFTTMsgWS?wsdl', + 'username' => 'clavistestws', + 'password' => 'Clavis@01', + ], + 'sandbox' => [ + 'endpoint' => 'https://ibblmtws.islamibankbd.com/ibblmtws/services/ImportFTTMsgWS?wsdl', + 'username' => 'clavistestws', + 'password' => 'Clavis@01', + ], + ], ], /* |-------------------------------------------------------------------------- @@ -151,11 +168,11 @@ */ 'repositories' => [ - \Fintech\Remit\Interfaces\BankTransferRepository::class => \Fintech\Remit\Repositories\Eloquent\BankTransferRepository::class, + \Fintech\Remit\Interfaces\BankTransferRepository::class => BankTransferRepository::class, - \Fintech\Remit\Interfaces\CashPickupRepository::class => \Fintech\Remit\Repositories\Eloquent\CashPickupRepository::class, + \Fintech\Remit\Interfaces\CashPickupRepository::class => CashPickupRepository::class, - \Fintech\Remit\Interfaces\WalletTransferRepository::class => \Fintech\Remit\Repositories\Eloquent\WalletTransferRepository::class, + \Fintech\Remit\Interfaces\WalletTransferRepository::class => WalletTransferRepository::class, //** Repository Binding Config Point Do not Remove **// ], diff --git a/database/migrations/2023_11_27_233957_create_mony_transfer_table.php b/database/migrations/2023_11_27_233957_create_money_transfer_table.php similarity index 94% rename from database/migrations/2023_11_27_233957_create_mony_transfer_table.php rename to database/migrations/2023_11_27_233957_create_money_transfer_table.php index aef662e..1c3bf1c 100644 --- a/database/migrations/2023_11_27_233957_create_mony_transfer_table.php +++ b/database/migrations/2023_11_27_233957_create_money_transfer_table.php @@ -1,5 +1,6 @@ longText('notes')->nullable(); $table->boolean('is_refunded')->nullable()->default(false)->comment('if money has refunded'); $table->json('order_data')->nullable(); - $table->string('status')->default(\Fintech\Core\Enums\Transaction\OrderStatus::Processing->value); + $table->string('status')->default(OrderStatus::Processing->value); $table->foreignId('creator_id')->nullable(); $table->foreignId('editor_id')->nullable(); $table->foreignId('destroyer_id')->nullable(); diff --git a/resources/img/service/logo_svg/mbs_m_cash.svg b/resources/img/service/logo_svg/mbs_m_cash.svg index 7564dc3..0f51d53 100644 --- a/resources/img/service/logo_svg/mbs_m_cash.svg +++ b/resources/img/service/logo_svg/mbs_m_cash.svg @@ -1,6 +1,7 @@ - + diff --git a/resources/img/service_vendor/logo_png/agrani.png b/resources/img/service_vendor/logo_png/agrani.png new file mode 100644 index 0000000..6a7d90e Binary files /dev/null and b/resources/img/service_vendor/logo_png/agrani.png differ diff --git a/resources/img/service_vendor/logo_png/citybank.png b/resources/img/service_vendor/logo_png/citybank.png new file mode 100644 index 0000000..10685c0 Binary files /dev/null and b/resources/img/service_vendor/logo_png/citybank.png differ diff --git a/resources/img/service_vendor/logo_png/emqapi.png b/resources/img/service_vendor/logo_png/emqapi.png new file mode 100644 index 0000000..07cb8b3 Binary files /dev/null and b/resources/img/service_vendor/logo_png/emqapi.png differ diff --git a/resources/img/service_vendor/logo_png/transfast.png b/resources/img/service_vendor/logo_png/transfast.png new file mode 100644 index 0000000..c03c3e7 Binary files /dev/null and b/resources/img/service_vendor/logo_png/transfast.png differ diff --git a/resources/img/service_vendor/logo_png/valyou.png b/resources/img/service_vendor/logo_png/valyou.png new file mode 100644 index 0000000..2cb4c67 Binary files /dev/null and b/resources/img/service_vendor/logo_png/valyou.png differ diff --git a/resources/img/service_vendor/logo_svg/agrani.svg b/resources/img/service_vendor/logo_svg/agrani.svg new file mode 100644 index 0000000..7730082 --- /dev/null +++ b/resources/img/service_vendor/logo_svg/agrani.svg @@ -0,0 +1,9 @@ + + agrani + + + + + + \ No newline at end of file diff --git a/resources/img/service_vendor/logo_svg/citybank.svg b/resources/img/service_vendor/logo_svg/citybank.svg new file mode 100644 index 0000000..bbf29bc --- /dev/null +++ b/resources/img/service_vendor/logo_svg/citybank.svg @@ -0,0 +1 @@ + diff --git a/resources/img/service_vendor/logo_svg/emqapi.svg b/resources/img/service_vendor/logo_svg/emqapi.svg new file mode 100644 index 0000000..20b423c --- /dev/null +++ b/resources/img/service_vendor/logo_svg/emqapi.svg @@ -0,0 +1,9 @@ + + emqapi + + + + + + \ No newline at end of file diff --git a/resources/img/service_vendor/logo_svg/transfast.svg b/resources/img/service_vendor/logo_svg/transfast.svg new file mode 100644 index 0000000..532a946 --- /dev/null +++ b/resources/img/service_vendor/logo_svg/transfast.svg @@ -0,0 +1,9 @@ + + transfast + + + + + + \ No newline at end of file diff --git a/resources/img/service_vendor/logo_svg/valyou.svg b/resources/img/service_vendor/logo_svg/valyou.svg new file mode 100644 index 0000000..4457956 --- /dev/null +++ b/resources/img/service_vendor/logo_svg/valyou.svg @@ -0,0 +1,9 @@ + + Logo + + + + + + \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index b60739a..c9b4616 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,11 @@ name('remit.') - ->middleware(config('fintech.auth.middleware')) - ->group(function () { - - Route::apiResource('bank-transfers', \Fintech\Remit\Http\Controllers\BankTransferController::class)->except('update', 'destroy'); - //Route::post('bank-transfers/{bank_transfer}/restore', [\Fintech\Remit\Http\Controllers\BankTransferController::class, 'restore'])->name('bank-transfers.restore'); - - Route::apiResource('cash-pickups', \Fintech\Remit\Http\Controllers\CashPickupController::class)->except('update', 'destroy'); - //Route::post('cash-pickups/{cash_pickup}/restore', [\Fintech\Remit\Http\Controllers\CashPickupController::class, 'restore'])->name('cash-pickups.restore'); - - Route::apiResource('wallet-transfers', \Fintech\Remit\Http\Controllers\WalletTransferController::class)->except('update', 'destroy'); - //Route::post('wallet-transfers/{wallet_transfer}/restore', [\Fintech\Remit\Http\Controllers\WalletTransferController::class, 'restore'])->name('wallet-transfers.restore'); - - Route::post('wallet-verification', \Fintech\Remit\Http\Controllers\WalletVerificationController::class)->name('wallet-verification'); + ->middleware(config('fintech.auth.middleware'))->group(function () { + if (Core::packageExists('Transaction')) { + Route::get('assignable-vendors/{order_id}', [AssignVendorController::class, 'available']) + ->name('assignable-vendors.available'); + } + Route::apiResource('bank-transfers', BankTransferController::class)->except('update', 'destroy'); + Route::apiResource('cash-pickups', CashPickupController::class)->except('update', 'destroy'); + Route::apiResource('wallet-transfers', WalletTransferController::class)->except('update', 'destroy'); + Route::post('wallet-verification', WalletVerificationController::class)->name('wallet-verification'); //DO NOT REMOVE THIS LINE// }); diff --git a/src/Abstracts/Wrapper.php b/src/Abstracts/Wrapper.php new file mode 100644 index 0000000..4a5b006 --- /dev/null +++ b/src/Abstracts/Wrapper.php @@ -0,0 +1,166 @@ +raw = $raw; + } + + public function __toString() + { + return $this->toJson(); + } + + public function toJson($options = 0): bool|string + { + $json = json_encode($this->attributes, $options); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new JsonException(json_last_error_msg()); + } + + return $json; + } + + public function __isset($name) + { + return $this->offsetExists($name); + } + + public function offsetExists($offset): bool + { + return isset($this->attributes[$offset]) || isset($this->extra[$offset]); + } + + public function __get($name) + { + return $this->offsetGet($name); + } + + public function __set($name, $value) + { + $this->offsetSet($name, $value); + } + + public function offsetGet($offset) + { + if (array_key_exists($offset, $this->attributes)) { + return $this->attributes[$offset]; + } elseif (array_key_exists($offset, $this->extra)) { + return $this->extra[$offset]; + } else { + return null; + } + } + + public function offsetSet($offset, $value): void + { + (array_key_exists($offset, $this->attributes)) + ? $this->attributes[$offset] = $value + : $this->extra[$offset] = $value; + + $this->resolveCasts(); + } + + public function resolveCasts(): void + { + foreach ($this->casts as $field => $cast) { + + if (array_key_exists($field, $this->attributes)) { + $this->attributes[$field] = $this->convertValue($cast, $this->attributes[$field]); + } + + if (array_key_exists($field, $this->extra)) { + $this->extra[$field] = $this->convertValue($cast, $this->extra[$field]); + } + } + + } + + private function convertValue($type, $value): mixed + { + if ($value == null) { + return null; + } + + switch ($type) { + case 'boolean': + case 'bool' : + if (is_string($value)) { + return $value == 'true'; + } + + return (bool) $value; + + case 'float' : + case 'double' : + case 'decimal' : + return (float) $value; + + case 'integer' : + return (int) $value; + + case 'array' : + return Arr::wrap($value); + + case 'datetime' : + case 'date': + return Carbon::parse($value); + + // case 'money' : + // return Money::parse($value); + + case 'string' : + return (string) $value; + + default: + return $value; + } + } + + public function __unset($name) + { + $this->offsetUnset($name); + } + + public function offsetUnset($offset): void + { + if (array_key_exists($offset, $this->attributes)) { + unset($this->attributes[$offset]); + } + + if (array_key_exists($offset, $this->extra)) { + unset($this->extra[$offset]); + } + } + + public function toRaw() + { + return $this->raw; + } + + public function toArray(): array + { + return array_merge($this->attributes, $this->extra); + } +} diff --git a/src/Commands/AgraniInstallCommand.php b/src/Commands/AgraniInstallCommand.php index 2df1c01..2927081 100644 --- a/src/Commands/AgraniInstallCommand.php +++ b/src/Commands/AgraniInstallCommand.php @@ -3,6 +3,7 @@ namespace Fintech\Remit\Commands; use Fintech\Core\Facades\Core; +use Fintech\MetaData\Facades\MetaData; use Illuminate\Console\Command; class AgraniInstallCommand extends Command @@ -255,12 +256,12 @@ public function handle(): int public function addCountryCodeToCountries(): void { if (Core::packageExists('MetaData')) { - \Fintech\MetaData\Facades\MetaData::country() + MetaData::country() ->list(['paginate' => false]) ->each(function ($country) { $countryData = $country->country_data; $countryData['vendor_code']['agrani_code'] = self::AGRANI_CODES[$country->iso3]['agrani_code'] ?? null; - \Fintech\MetaData\Facades\MetaData::country()->update($country->getKey(), ['country_data' => $countryData]); + MetaData::country()->update($country->getKey(), ['country_data' => $countryData]); $this->info("Country ID: {$country->getKey()} successful."); }); } diff --git a/src/Contracts/BankTransfer.php b/src/Contracts/BankTransfer.php index 76c312a..8468ba9 100644 --- a/src/Contracts/BankTransfer.php +++ b/src/Contracts/BankTransfer.php @@ -7,13 +7,13 @@ interface BankTransfer /** * Execute the transfer operation */ - public function makeTransfer(array $orderInfo): mixed; + public function makeTransfer(array $orderInfo = []): mixed; - public function transferStatus(array $orderInfo): mixed; + public function transferStatus(array $orderInfo = []): mixed; - public function cancelTransfer(array $orderInfo): mixed; + public function cancelTransfer(array $orderInfo = []): mixed; - public function verifyAccount(array $accountInfo): mixed; + public function verifyAccount(array $accountInfo = []): mixed; - public function vendorBalance(array $accountInfo): mixed; + public function vendorBalance(array $accountInfo = []): mixed; } diff --git a/src/Contracts/OrderQuotation.php b/src/Contracts/OrderQuotation.php new file mode 100644 index 0000000..fa7629d --- /dev/null +++ b/src/Contracts/OrderQuotation.php @@ -0,0 +1,13 @@ + + * @return array */ public function broadcastOn(): array { diff --git a/src/Events/RemitTransferRejected.php b/src/Events/RemitTransferRejected.php index 3554b47..4aa7f03 100644 --- a/src/Events/RemitTransferRejected.php +++ b/src/Events/RemitTransferRejected.php @@ -2,6 +2,10 @@ namespace Fintech\Remit\Events; +use Fintech\Remit\Models\BankTransfer; +use Fintech\Remit\Models\CashPickup; +use Fintech\Remit\Models\WalletTransfer; +use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Foundation\Events\Dispatchable; @@ -16,7 +20,7 @@ class RemitTransferRejected /** * Create a new event instance. * - * @param \Fintech\Remit\Models\BankTransfer|\Fintech\Remit\Models\CashPickup|\Fintech\Remit\Models\WalletTransfer + * @param BankTransfer|CashPickup|WalletTransfer */ public function __construct($transfer) { @@ -26,7 +30,7 @@ public function __construct($transfer) /** * Get the channels the event should broadcast on. * - * @return array + * @return array */ public function broadcastOn(): array { diff --git a/src/Events/RemitTransferRequested.php b/src/Events/RemitTransferRequested.php index 1a3a33b..8d2947c 100644 --- a/src/Events/RemitTransferRequested.php +++ b/src/Events/RemitTransferRequested.php @@ -2,6 +2,10 @@ namespace Fintech\Remit\Events; +use Fintech\Remit\Models\BankTransfer; +use Fintech\Remit\Models\CashPickup; +use Fintech\Remit\Models\WalletTransfer; +use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Foundation\Events\Dispatchable; @@ -16,7 +20,7 @@ class RemitTransferRequested /** * Create a new event instance. * - * @param \Fintech\Remit\Models\BankTransfer|\Fintech\Remit\Models\CashPickup|\Fintech\Remit\Models\WalletTransfer + * @param BankTransfer|CashPickup|WalletTransfer */ public function __construct($transfer) { @@ -26,7 +30,7 @@ public function __construct($transfer) /** * Get the channels the event should broadcast on. * - * @return array + * @return array */ public function broadcastOn(): array { diff --git a/src/Events/RemitTransferVendorAssigned.php b/src/Events/RemitTransferVendorAssigned.php index ba8e715..bd6188c 100644 --- a/src/Events/RemitTransferVendorAssigned.php +++ b/src/Events/RemitTransferVendorAssigned.php @@ -2,6 +2,10 @@ namespace Fintech\Remit\Events; +use Fintech\Remit\Models\BankTransfer; +use Fintech\Remit\Models\CashPickup; +use Fintech\Remit\Models\WalletTransfer; +use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Foundation\Events\Dispatchable; @@ -16,7 +20,7 @@ class RemitTransferVendorAssigned /** * Create a new event instance. * - * @param \Fintech\Remit\Models\BankTransfer|\Fintech\Remit\Models\CashPickup|\Fintech\Remit\Models\WalletTransfer + * @param BankTransfer|CashPickup|WalletTransfer */ public function __construct($transfer) { @@ -26,7 +30,7 @@ public function __construct($transfer) /** * Get the channels the event should broadcast on. * - * @return array + * @return array */ public function broadcastOn(): array { diff --git a/src/Facades/Remit.php b/src/Facades/Remit.php index 249dc74..21eb289 100644 --- a/src/Facades/Remit.php +++ b/src/Facades/Remit.php @@ -2,13 +2,17 @@ namespace Fintech\Remit\Facades; +use Fintech\Remit\Services\BankTransferService; +use Fintech\Remit\Services\CashPickupService; +use Fintech\Remit\Services\WalletTransferService; use Illuminate\Support\Facades\Facade; /** - * @method static \Fintech\Remit\Services\BankTransferService bankTransfer() - * @method static \Fintech\Remit\Services\CashPickupService cashPickup() - * @method static \Fintech\Remit\Services\WalletTransferService walletTransfer() - * // Crud Service Method Point Do not Remove // + * @method static BankTransferService bankTransfer() + * @method static CashPickupService cashPickup() + * @method static WalletTransferService walletTransfer() + * + * // Crud Service Method Point Do not Remove // * * @see \Fintech\Remit\Remit */ diff --git a/src/Http/Controllers/AssignVendorController.php b/src/Http/Controllers/AssignVendorController.php new file mode 100644 index 0000000..6507752 --- /dev/null +++ b/src/Http/Controllers/AssignVendorController.php @@ -0,0 +1,135 @@ +find($id); + + if (! $order) { + throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $id); + } + + $serviceVendors = Business::serviceVendor()->list([ + 'service_id_array' => [$order->service_id], + 'enabled' => true, + 'paginate' => false, + ]); + + return new AssignableVendorCollection($serviceVendors); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * Display the specified resource. + */ + public function vendor(AssignableVendorInfoRequest $request): JsonResponse + { + $order_id = $request->input('order_id'); + + $service_vendor_slug = $request->input('vendor_slug'); + + try { + $order = Transaction::order()->find($order_id); + + if (! $order) { + throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $order_id); + } + + $availableVendors = config('fintech.remit.providers'); + + if (! isset($availableVendors[$service_vendor_slug])) { + throw new ErrorException('Service Vendor is not available on the configuration.'); + } + + $vendor = $availableVendors[$service_vendor_slug]; + + $driverClass = $vendor['driver']; + + $instance = App::make($driverClass); + + if (! $instance instanceof OrderQuotation) { + throw new ErrorException('Service Vendor Class is not instance of `Fintech\Remit\Contracts\OrderQuotation` interface.'); + } + + $jsonResponse = $instance->requestQuotation($order); + + return $this->success($jsonResponse); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } + + private function defaultVendorData(): array + { + return [ + 'balance' => 'test', + 'approved' => true, + ]; + } + + private function cityBankVendorData(): array + { + + } +} diff --git a/src/Http/Controllers/BankTransferController.php b/src/Http/Controllers/BankTransferController.php index 8092af6..eedd20b 100644 --- a/src/Http/Controllers/BankTransferController.php +++ b/src/Http/Controllers/BankTransferController.php @@ -3,6 +3,7 @@ namespace Fintech\Remit\Http\Controllers; use Exception; +use Fintech\Auth\Facades\Auth; use Fintech\Banco\Facades\Banco; use Fintech\Business\Facades\Business; use Fintech\Core\Enums\Auth\RiskProfile; @@ -80,7 +81,7 @@ public function store(StoreBankTransferRequest $request): JsonResponse } $depositor = $request->user('sanctum'); if (Transaction::orderQueue()->addToQueueUserWise(($user_id ?? $depositor->getKey())) > 0) { - $depositAccount = \Fintech\Transaction\Facades\Transaction::userAccount()->list([ + $depositAccount = Transaction::userAccount()->list([ 'user_id' => $user_id ?? $depositor->getKey(), 'country_id' => $request->input('source_country_id', $depositor->profile?->country_id), ])->first(); @@ -89,7 +90,7 @@ public function store(StoreBankTransferRequest $request): JsonResponse throw new Exception("User don't have account deposit balance"); } - $masterUser = \Fintech\Auth\Facades\Auth::user()->list([ + $masterUser = Auth::user()->list([ 'role_name' => SystemRole::MasterUser->value, 'country_id' => $request->input('source_country_id', $depositor->profile?->country_id), ])->first(); @@ -135,7 +136,7 @@ public function store(StoreBankTransferRequest $request): JsonResponse $order_data['user_name'] = $bankTransfer->user->name; $bankTransfer->order_data = $order_data; $userUpdatedBalance = Remit::bankTransfer()->debitTransaction($bankTransfer); - $depositedAccount = \Fintech\Transaction\Facades\Transaction::userAccount()->list([ + $depositedAccount = Transaction::userAccount()->list([ 'user_id' => $depositor->getKey(), 'country_id' => $bankTransfer->source_country_id, ])->first(); @@ -181,13 +182,11 @@ public function store(StoreBankTransferRequest $request): JsonResponse /** * @lrd:start - * Return a specified *BankTransfer* resource found by id. + * Update a specified *BankTransfer* resource using id. * * @lrd:end - * - * @throws ModelNotFoundException */ - public function show(string|int $id): BankTransferResource|JsonResponse + public function update(UpdateBankTransferRequest $request, string|int $id): JsonResponse { try { @@ -197,7 +196,14 @@ public function show(string|int $id): BankTransferResource|JsonResponse throw (new ModelNotFoundException)->setModel(config('fintech.remit.bank_transfer_model'), $id); } - return new BankTransferResource($bankTransfer); + $inputs = $request->validated(); + + if (! Remit::bankTransfer()->update($id, $inputs)) { + + throw (new UpdateOperationException)->setModel(config('fintech.remit.bank_transfer_model'), $id); + } + + return $this->updated(__('core::messages.resource.updated', ['model' => 'Bank Transfer'])); } catch (ModelNotFoundException $exception) { @@ -211,11 +217,13 @@ public function show(string|int $id): BankTransferResource|JsonResponse /** * @lrd:start - * Update a specified *BankTransfer* resource using id. + * Return a specified *BankTransfer* resource found by id. * * @lrd:end + * + * @throws ModelNotFoundException */ - public function update(UpdateBankTransferRequest $request, string|int $id): JsonResponse + public function show(string|int $id): BankTransferResource|JsonResponse { try { @@ -225,14 +233,7 @@ public function update(UpdateBankTransferRequest $request, string|int $id): Json throw (new ModelNotFoundException)->setModel(config('fintech.remit.bank_transfer_model'), $id); } - $inputs = $request->validated(); - - if (! Remit::bankTransfer()->update($id, $inputs)) { - - throw (new UpdateOperationException)->setModel(config('fintech.remit.bank_transfer_model'), $id); - } - - return $this->updated(__('core::messages.resource.updated', ['model' => 'Bank Transfer'])); + return new BankTransferResource($bankTransfer); } catch (ModelNotFoundException $exception) { @@ -282,12 +283,55 @@ public function destroy(string|int $id): JsonResponse /** * @lrd:start - * Restore the specified *BankTransfer* resource from trash. - * ** ```Soft Delete``` needs to enabled to use this feature** + * Create an exportable list of the *BankTransfer* resource as document. + * After export job is done system will fire export completed event * * @lrd:end */ - public function restore(string|int $id): JsonResponse + public function export(IndexBankTransferRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $bankTransferPaginate = Remit::bankTransfer()->export($inputs); + + return $this->exported(__('core::messages.resource.exported', ['model' => 'Bank Transfer'])); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create an exportable list of the *BankTransfer* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + */ + public function import(ImportBankTransferRequest $request): JsonResponse|BankTransferCollection + { + try { + $inputs = $request->validated(); + + $bankTransferPaginate = Remit::bankTransfer()->list($inputs); + + return new BankTransferCollection($bankTransferPaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Assign vendor to a specified *BankTransfer* resource from systems. + * + * @lrd:end + */ + public function fetchAssignableVendors(string|int $id): JsonResponse { try { @@ -316,19 +360,31 @@ public function restore(string|int $id): JsonResponse /** * @lrd:start - * Create an exportable list of the *BankTransfer* resource as document. - * After export job is done system will fire export completed event + * Restore the specified *BankTransfer* resource from trash. + * ** ```Soft Delete``` needs to enabled to use this feature** * * @lrd:end */ - public function export(IndexBankTransferRequest $request): JsonResponse + public function restore(string|int $id): JsonResponse { try { - $inputs = $request->validated(); - $bankTransferPaginate = Remit::bankTransfer()->export($inputs); + $bankTransfer = Remit::bankTransfer()->find($id, true); - return $this->exported(__('core::messages.resource.exported', ['model' => 'Bank Transfer'])); + if (! $bankTransfer) { + throw (new ModelNotFoundException)->setModel(config('fintech.remit.bank_transfer_model'), $id); + } + + if (! Remit::bankTransfer()->restore($id)) { + + throw (new RestoreOperationException())->setModel(config('fintech.remit.bank_transfer_model'), $id); + } + + return $this->restored(__('core::messages.resource.restored', ['model' => 'Bank Transfer'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); } catch (Exception $exception) { @@ -338,19 +394,30 @@ public function export(IndexBankTransferRequest $request): JsonResponse /** * @lrd:start - * Create an exportable list of the *BankTransfer* resource as document. - * After export job is done system will fire export completed event + * Assign vendor to a specified *BankTransfer* resource from systems. * * @lrd:end */ - public function import(ImportBankTransferRequest $request): JsonResponse|BankTransferCollection + public function assignVendor(string|int $id): JsonResponse { try { - $inputs = $request->validated(); - $bankTransferPaginate = Remit::bankTransfer()->list($inputs); + $bankTransfer = Remit::bankTransfer()->find($id, true); - return new BankTransferCollection($bankTransferPaginate); + if (! $bankTransfer) { + throw (new ModelNotFoundException)->setModel(config('fintech.remit.bank_transfer_model'), $id); + } + + if (! Remit::bankTransfer()->restore($id)) { + + throw (new RestoreOperationException())->setModel(config('fintech.remit.bank_transfer_model'), $id); + } + + return $this->restored(__('core::messages.resource.restored', ['model' => 'Bank Transfer'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); } catch (Exception $exception) { diff --git a/src/Http/Controllers/CashPickupController.php b/src/Http/Controllers/CashPickupController.php index 386fe74..018182e 100644 --- a/src/Http/Controllers/CashPickupController.php +++ b/src/Http/Controllers/CashPickupController.php @@ -3,6 +3,7 @@ namespace Fintech\Remit\Http\Controllers; use Exception; +use Fintech\Auth\Facades\Auth; use Fintech\Banco\Facades\Banco; use Fintech\Business\Facades\Business; use Fintech\Core\Enums\Auth\RiskProfile; @@ -82,7 +83,7 @@ public function store(StoreCashPickupRequest $request): JsonResponse } $depositor = $request->user('sanctum'); if (Transaction::orderQueue()->addToQueueUserWise(($user_id ?? $depositor->getKey())) > 0) { - $depositAccount = \Fintech\Transaction\Facades\Transaction::userAccount()->list([ + $depositAccount = Transaction::userAccount()->list([ 'user_id' => $user_id ?? $depositor->getKey(), 'country_id' => $request->input('source_country_id', $depositor->profile?->country_id), ])->first(); @@ -91,7 +92,7 @@ public function store(StoreCashPickupRequest $request): JsonResponse throw new Exception("User don't have account deposit balance"); } - $masterUser = \Fintech\Auth\Facades\Auth::user()->list([ + $masterUser = Auth::user()->list([ 'role_name' => SystemRole::MasterUser->value, 'country_id' => $request->input('source_country_id', $depositor->profile?->country_id), ])->first(); @@ -138,7 +139,7 @@ public function store(StoreCashPickupRequest $request): JsonResponse $order_data['user_name'] = $cashPickup->user->name; $cashPickup->order_data = $order_data; $userUpdatedBalance = Remit::cashPickup()->debitTransaction($cashPickup); - $depositedAccount = \Fintech\Transaction\Facades\Transaction::userAccount()->list([ + $depositedAccount = Transaction::userAccount()->list([ 'user_id' => $depositor->getKey(), 'country_id' => $cashPickup->source_country_id, ])->first(); @@ -181,13 +182,14 @@ public function store(StoreCashPickupRequest $request): JsonResponse /** * @lrd:start - * Return a specified *CashPickup* resource found by id. + * Update a specified *CashPickup* resource using id. * * @lrd:end * * @throws ModelNotFoundException + * @throws UpdateOperationException */ - public function show(string|int $id): CashPickupResource|JsonResponse + public function update(UpdateCashPickupRequest $request, string|int $id): JsonResponse { try { @@ -197,7 +199,14 @@ public function show(string|int $id): CashPickupResource|JsonResponse throw (new ModelNotFoundException)->setModel(config('fintech.remit.cash_pickup_model'), $id); } - return new CashPickupResource($cashPickup); + $inputs = $request->validated(); + + if (! Remit::cashPickup()->update($id, $inputs)) { + + throw (new UpdateOperationException)->setModel(config('fintech.remit.cash_pickup_model'), $id); + } + + return $this->updated(__('core::messages.resource.updated', ['model' => 'Cash Pickup'])); } catch (ModelNotFoundException $exception) { @@ -211,14 +220,13 @@ public function show(string|int $id): CashPickupResource|JsonResponse /** * @lrd:start - * Update a specified *CashPickup* resource using id. + * Return a specified *CashPickup* resource found by id. * * @lrd:end * * @throws ModelNotFoundException - * @throws UpdateOperationException */ - public function update(UpdateCashPickupRequest $request, string|int $id): JsonResponse + public function show(string|int $id): CashPickupResource|JsonResponse { try { @@ -228,14 +236,7 @@ public function update(UpdateCashPickupRequest $request, string|int $id): JsonRe throw (new ModelNotFoundException)->setModel(config('fintech.remit.cash_pickup_model'), $id); } - $inputs = $request->validated(); - - if (! Remit::cashPickup()->update($id, $inputs)) { - - throw (new UpdateOperationException)->setModel(config('fintech.remit.cash_pickup_model'), $id); - } - - return $this->updated(__('core::messages.resource.updated', ['model' => 'Cash Pickup'])); + return new CashPickupResource($cashPickup); } catch (ModelNotFoundException $exception) { diff --git a/src/Http/Controllers/WalletTransferController.php b/src/Http/Controllers/WalletTransferController.php index f00a530..d519525 100644 --- a/src/Http/Controllers/WalletTransferController.php +++ b/src/Http/Controllers/WalletTransferController.php @@ -3,6 +3,7 @@ namespace Fintech\Remit\Http\Controllers; use Exception; +use Fintech\Auth\Facades\Auth; use Fintech\Banco\Facades\Banco; use Fintech\Business\Facades\Business; use Fintech\Core\Enums\Auth\RiskProfile; @@ -82,7 +83,7 @@ public function store(StoreWalletTransferRequest $request): JsonResponse $depositor = $request->user('sanctum'); if (Transaction::orderQueue()->addToQueueUserWise(($user_id ?? $depositor->getKey())) > 0) { - $depositAccount = \Fintech\Transaction\Facades\Transaction::userAccount()->list([ + $depositAccount = Transaction::userAccount()->list([ 'user_id' => $user_id ?? $depositor->getKey(), 'country_id' => $request->input('source_country_id', $depositor->profile?->country_id), ])->first(); @@ -91,7 +92,7 @@ public function store(StoreWalletTransferRequest $request): JsonResponse throw new Exception("User don't have account deposit balance"); } - $masterUser = \Fintech\Auth\Facades\Auth::user()->list([ + $masterUser = Auth::user()->list([ 'role_name' => SystemRole::MasterUser->value, 'country_id' => $request->input('source_country_id', $depositor->profile?->country_id), ])->first(); @@ -138,7 +139,7 @@ public function store(StoreWalletTransferRequest $request): JsonResponse $order_data['user_name'] = $walletTransfer->user->name; $walletTransfer->order_data = $order_data; $userUpdatedBalance = Remit::walletTransfer()->debitTransaction($walletTransfer); - $depositedAccount = \Fintech\Transaction\Facades\Transaction::userAccount()->list([ + $depositedAccount = Transaction::userAccount()->list([ 'user_id' => $depositor->getKey(), 'country_id' => $walletTransfer->source_country_id, ])->first(); @@ -181,13 +182,14 @@ public function store(StoreWalletTransferRequest $request): JsonResponse /** * @lrd:start - * Return a specified *WalletTransfer* resource found by id. + * Update a specified *WalletTransfer* resource using id. * * @lrd:end * * @throws ModelNotFoundException + * @throws UpdateOperationException */ - public function show(string|int $id): WalletTransferResource|JsonResponse + public function update(UpdateWalletTransferRequest $request, string|int $id): JsonResponse { try { @@ -197,7 +199,14 @@ public function show(string|int $id): WalletTransferResource|JsonResponse throw (new ModelNotFoundException)->setModel(config('fintech.remit.wallet_transfer_model'), $id); } - return new WalletTransferResource($walletTransfer); + $inputs = $request->validated(); + + if (! Remit::walletTransfer()->update($id, $inputs)) { + + throw (new UpdateOperationException)->setModel(config('fintech.remit.wallet_transfer_model'), $id); + } + + return $this->updated(__('core::messages.resource.updated', ['model' => 'Wallet Transfer'])); } catch (ModelNotFoundException $exception) { @@ -211,14 +220,13 @@ public function show(string|int $id): WalletTransferResource|JsonResponse /** * @lrd:start - * Update a specified *WalletTransfer* resource using id. + * Return a specified *WalletTransfer* resource found by id. * * @lrd:end * * @throws ModelNotFoundException - * @throws UpdateOperationException */ - public function update(UpdateWalletTransferRequest $request, string|int $id): JsonResponse + public function show(string|int $id): WalletTransferResource|JsonResponse { try { @@ -228,14 +236,7 @@ public function update(UpdateWalletTransferRequest $request, string|int $id): Js throw (new ModelNotFoundException)->setModel(config('fintech.remit.wallet_transfer_model'), $id); } - $inputs = $request->validated(); - - if (! Remit::walletTransfer()->update($id, $inputs)) { - - throw (new UpdateOperationException)->setModel(config('fintech.remit.wallet_transfer_model'), $id); - } - - return $this->updated(__('core::messages.resource.updated', ['model' => 'Wallet Transfer'])); + return new WalletTransferResource($walletTransfer); } catch (ModelNotFoundException $exception) { diff --git a/src/Http/Controllers/WalletVerificationController.php b/src/Http/Controllers/WalletVerificationController.php index cf59b3b..2905373 100644 --- a/src/Http/Controllers/WalletVerificationController.php +++ b/src/Http/Controllers/WalletVerificationController.php @@ -2,9 +2,11 @@ namespace Fintech\Remit\Http\Controllers; +use Exception; use Fintech\Core\Traits\ApiResponseTrait; use Fintech\Remit\Http\Requests\WalletVerificationRequest; use Fintech\Remit\Http\Resources\WalletVerificationResource; +use Illuminate\Http\JsonResponse; use Illuminate\Routing\Controller; class WalletVerificationController extends Controller @@ -14,13 +16,13 @@ class WalletVerificationController extends Controller /** * Handle the incoming request. */ - public function __invoke(WalletVerificationRequest $request): \Illuminate\Http\JsonResponse|WalletVerificationResource + public function __invoke(WalletVerificationRequest $request): JsonResponse|WalletVerificationResource { try { if (strlen($request->input('wallet_no')) < 10) { - throw new \Exception('Invalid Bkash Wallet Number.'); + throw new Exception('Invalid Bkash Wallet Number.'); } $data = [ @@ -31,7 +33,7 @@ public function __invoke(WalletVerificationRequest $request): \Illuminate\Http\J return new WalletVerificationResource($data); - } catch (\Exception $exception) { + } catch (Exception $exception) { return $this->failed($exception->getMessage()); } diff --git a/src/Http/Requests/AssignableVendorInfoRequest.php b/src/Http/Requests/AssignableVendorInfoRequest.php new file mode 100644 index 0000000..22ffaeb --- /dev/null +++ b/src/Http/Requests/AssignableVendorInfoRequest.php @@ -0,0 +1,30 @@ +|string> + */ + public function rules(): array + { + return [ + 'order_id' => ['required', 'min:1', 'integer'], + 'vendor_slug' => ['required', 'string', 'min:1'], + ]; + } +} diff --git a/src/Http/Requests/ImportBankTransferRequest.php b/src/Http/Requests/ImportBankTransferRequest.php index afeeeaa..a27878d 100644 --- a/src/Http/Requests/ImportBankTransferRequest.php +++ b/src/Http/Requests/ImportBankTransferRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class ImportBankTransferRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/ImportCashPickupRequest.php b/src/Http/Requests/ImportCashPickupRequest.php index 096cde5..ec6d6b7 100644 --- a/src/Http/Requests/ImportCashPickupRequest.php +++ b/src/Http/Requests/ImportCashPickupRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class ImportCashPickupRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/ImportWalletTransferRequest.php b/src/Http/Requests/ImportWalletTransferRequest.php index 5f2c568..de1064b 100644 --- a/src/Http/Requests/ImportWalletTransferRequest.php +++ b/src/Http/Requests/ImportWalletTransferRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class ImportWalletTransferRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/IndexBankTransferRequest.php b/src/Http/Requests/IndexBankTransferRequest.php index ec9084c..d0c7401 100644 --- a/src/Http/Requests/IndexBankTransferRequest.php +++ b/src/Http/Requests/IndexBankTransferRequest.php @@ -2,11 +2,13 @@ namespace Fintech\Remit\Http\Requests; +use Fintech\Core\Traits\HasPaginateQuery; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class IndexBankTransferRequest extends FormRequest { - use \Fintech\Core\Traits\HasPaginateQuery; + use HasPaginateQuery; /** * Determine if the user is authorized to make this request. @@ -19,7 +21,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/IndexCashPickupRequest.php b/src/Http/Requests/IndexCashPickupRequest.php index 0d49dd2..57c345f 100644 --- a/src/Http/Requests/IndexCashPickupRequest.php +++ b/src/Http/Requests/IndexCashPickupRequest.php @@ -2,11 +2,13 @@ namespace Fintech\Remit\Http\Requests; +use Fintech\Core\Traits\HasPaginateQuery; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class IndexCashPickupRequest extends FormRequest { - use \Fintech\Core\Traits\HasPaginateQuery; + use HasPaginateQuery; /** * Determine if the user is authorized to make this request. @@ -19,7 +21,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/IndexWalletTransferRequest.php b/src/Http/Requests/IndexWalletTransferRequest.php index dbd7cc5..cd150f1 100644 --- a/src/Http/Requests/IndexWalletTransferRequest.php +++ b/src/Http/Requests/IndexWalletTransferRequest.php @@ -2,11 +2,13 @@ namespace Fintech\Remit\Http\Requests; +use Fintech\Core\Traits\HasPaginateQuery; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class IndexWalletTransferRequest extends FormRequest { - use \Fintech\Core\Traits\HasPaginateQuery; + use HasPaginateQuery; /** * Determine if the user is authorized to make this request. @@ -19,7 +21,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/StoreCashPickupRequest.php b/src/Http/Requests/StoreCashPickupRequest.php index 5ac2f36..1a42e65 100644 --- a/src/Http/Requests/StoreCashPickupRequest.php +++ b/src/Http/Requests/StoreCashPickupRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class StoreCashPickupRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { @@ -37,7 +38,7 @@ public function rules(): array 'order_data.cash_id' => ['integer', 'nullable'], 'order_data.cash_account_number' => ['string', 'nullable'], 'order_data.fund_source' => ['string', 'nullable'], - 'order_data.remittance_purpose' => ['string', 'nullable'], ]; + 'order_data.remittance_purpose' => ['string', 'nullable'], ]; } /** diff --git a/src/Http/Requests/StoreWalletTransferRequest.php b/src/Http/Requests/StoreWalletTransferRequest.php index ded6831..1ee07ca 100644 --- a/src/Http/Requests/StoreWalletTransferRequest.php +++ b/src/Http/Requests/StoreWalletTransferRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class StoreWalletTransferRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/UpdateBankTransferRequest.php b/src/Http/Requests/UpdateBankTransferRequest.php index e4d888b..0fa2a48 100644 --- a/src/Http/Requests/UpdateBankTransferRequest.php +++ b/src/Http/Requests/UpdateBankTransferRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class UpdateBankTransferRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/UpdateCashPickupRequest.php b/src/Http/Requests/UpdateCashPickupRequest.php index 74de0bc..4c7c1c6 100644 --- a/src/Http/Requests/UpdateCashPickupRequest.php +++ b/src/Http/Requests/UpdateCashPickupRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class UpdateCashPickupRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/UpdateWalletTransferRequest.php b/src/Http/Requests/UpdateWalletTransferRequest.php index 74660e9..c4b509d 100644 --- a/src/Http/Requests/UpdateWalletTransferRequest.php +++ b/src/Http/Requests/UpdateWalletTransferRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class UpdateWalletTransferRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ public function rules(): array { diff --git a/src/Http/Requests/WalletVerificationRequest.php b/src/Http/Requests/WalletVerificationRequest.php index b9e5c43..9870107 100644 --- a/src/Http/Requests/WalletVerificationRequest.php +++ b/src/Http/Requests/WalletVerificationRequest.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class WalletVerificationRequest extends FormRequest @@ -17,7 +18,7 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array|string> + * @return array|string> */ public function rules(): array { diff --git a/src/Http/Resources/AssignableVendorCollection.php b/src/Http/Resources/AssignableVendorCollection.php new file mode 100644 index 0000000..bca8192 --- /dev/null +++ b/src/Http/Resources/AssignableVendorCollection.php @@ -0,0 +1,48 @@ +collection->map(function ($vendor) { + return [ + 'id' => $vendor->getKey() ?? null, + 'service_vendor_name' => $vendor->service_vendor_name ?? null, + 'service_vendor_slug' => $vendor->service_vendor_slug ?? null, + 'service_vendor_data' => $vendor->service_vendor_data ?? null, + 'service_vendor_logo_svg' => $vendor->getFirstMediaUrl('logo_svg') ?? null, + 'service_vendor_logo_png' => $vendor->getFirstMediaUrl('logo_png') ?? null, + 'enabled' => $vendor->enabled ?? null, + ]; + })->toArray(); + } + + /** + * Get additional data that should be returned with the resource array. + * + * @return array + */ + public function with(Request $request): array + { + return [ + 'options' => [ + 'dir' => Constant::SORT_DIRECTIONS, + 'per_page' => Constant::PAGINATE_LENGTHS, + 'sort' => ['id', 'name', 'created_at', 'updated_at'], + ], + 'query' => $request->all(), + ]; + } +} diff --git a/src/Interfaces/BankTransferRepository.php b/src/Interfaces/BankTransferRepository.php index 07142a2..8e03f45 100644 --- a/src/Interfaces/BankTransferRepository.php +++ b/src/Interfaces/BankTransferRepository.php @@ -2,10 +2,10 @@ namespace Fintech\Remit\Interfaces; +use Fintech\Core\Abstracts\BaseModel; use Illuminate\Contracts\Pagination\Paginator; -use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Support\Collection; -use MongoDB\Laravel\Eloquent\Model as MongodbModel; +use InvalidArgumentException; /** * Interface BankTransferRepository @@ -23,14 +23,14 @@ public function list(array $filters = []); /** * Create a new entry resource * - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function create(array $attributes = []); /** * find and update a resource attributes * - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function update(int|string $id, array $attributes = []); @@ -38,7 +38,7 @@ public function update(int|string $id, array $attributes = []); * find and delete a entry from records * * @param bool $onlyTrashed - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function find(int|string $id, $onlyTrashed = false); @@ -50,7 +50,7 @@ public function delete(int|string $id); /** * find and restore a entry from records * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function restore(int|string $id); } diff --git a/src/Interfaces/CashPickupRepository.php b/src/Interfaces/CashPickupRepository.php index 144f551..b2c4634 100644 --- a/src/Interfaces/CashPickupRepository.php +++ b/src/Interfaces/CashPickupRepository.php @@ -2,10 +2,10 @@ namespace Fintech\Remit\Interfaces; +use Fintech\Core\Abstracts\BaseModel; use Illuminate\Contracts\Pagination\Paginator; -use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Support\Collection; -use MongoDB\Laravel\Eloquent\Model as MongodbModel; +use InvalidArgumentException; /** * Interface CashPickupRepository @@ -23,14 +23,14 @@ public function list(array $filters = []); /** * Create a new entry resource * - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function create(array $attributes = []); /** * find and update a resource attributes * - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function update(int|string $id, array $attributes = []); @@ -38,7 +38,7 @@ public function update(int|string $id, array $attributes = []); * find and delete a entry from records * * @param bool $onlyTrashed - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function find(int|string $id, $onlyTrashed = false); @@ -50,7 +50,7 @@ public function delete(int|string $id); /** * find and restore a entry from records * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function restore(int|string $id); } diff --git a/src/Interfaces/WalletTransferRepository.php b/src/Interfaces/WalletTransferRepository.php index 22c133d..24c53a6 100644 --- a/src/Interfaces/WalletTransferRepository.php +++ b/src/Interfaces/WalletTransferRepository.php @@ -2,10 +2,10 @@ namespace Fintech\Remit\Interfaces; +use Fintech\Core\Abstracts\BaseModel; use Illuminate\Contracts\Pagination\Paginator; -use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Support\Collection; -use MongoDB\Laravel\Eloquent\Model as MongodbModel; +use InvalidArgumentException; /** * Interface WalletTransferRepository @@ -23,14 +23,14 @@ public function list(array $filters = []); /** * Create a new entry resource * - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function create(array $attributes = []); /** * find and update a resource attributes * - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function update(int|string $id, array $attributes = []); @@ -38,7 +38,7 @@ public function update(int|string $id, array $attributes = []); * find and delete a entry from records * * @param bool $onlyTrashed - * @return EloquentModel|MongodbModel|null + * @return BaseModel */ public function find(int|string $id, $onlyTrashed = false); @@ -50,7 +50,7 @@ public function delete(int|string $id); /** * find and restore a entry from records * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function restore(int|string $id); } diff --git a/src/EventServiceProvider.php b/src/Providers/EventServiceProvider.php similarity index 95% rename from src/EventServiceProvider.php rename to src/Providers/EventServiceProvider.php index 0634424..2939b78 100644 --- a/src/EventServiceProvider.php +++ b/src/Providers/EventServiceProvider.php @@ -1,6 +1,6 @@ middleware('api') ->namespace($this->namespace) - ->group(__DIR__.'/../routes/api.php'); + ->group(__DIR__.'/../../routes/api.php'); }); } diff --git a/src/Remit.php b/src/Remit.php index 2e04ed1..541d8cc 100644 --- a/src/Remit.php +++ b/src/Remit.php @@ -2,30 +2,34 @@ namespace Fintech\Remit; +use Fintech\Remit\Services\BankTransferService; +use Fintech\Remit\Services\CashPickupService; +use Fintech\Remit\Services\WalletTransferService; + class Remit { /** - * @return \Fintech\Remit\Services\BankTransferService + * @return BankTransferService */ public function bankTransfer() { - return app(\Fintech\Remit\Services\BankTransferService::class); + return app(BankTransferService::class); } /** - * @return \Fintech\Remit\Services\CashPickupService + * @return CashPickupService */ public function cashPickup() { - return app(\Fintech\Remit\Services\CashPickupService::class); + return app(CashPickupService::class); } /** - * @return \Fintech\Remit\Services\WalletTransferService + * @return WalletTransferService */ public function walletTransfer() { - return app(\Fintech\Remit\Services\WalletTransferService::class); + return app(WalletTransferService::class); } //** Crud Service Method Point Do not Remove **// diff --git a/src/RemitServiceProvider.php b/src/RemitServiceProvider.php index 71e5275..1c7e71c 100644 --- a/src/RemitServiceProvider.php +++ b/src/RemitServiceProvider.php @@ -2,6 +2,7 @@ namespace Fintech\Remit; +use Fintech\Core\Traits\RegisterPackageTrait; use Fintech\Remit\Commands\AgraniInstallCommand; use Fintech\Remit\Commands\InstallCommand; use Fintech\Remit\Commands\RemitCommand; @@ -9,6 +10,8 @@ class RemitServiceProvider extends ServiceProvider { + use RegisterPackageTrait; + /** * Register any application services. * @@ -16,13 +19,15 @@ class RemitServiceProvider extends ServiceProvider */ public function register() { + $this->packageCode = 'remit'; + $this->mergeConfigFrom( __DIR__.'/../config/remit.php', 'fintech.remit' ); - $this->app->register(RouteServiceProvider::class); - $this->app->register(RepositoryServiceProvider::class); - $this->app->register(EventServiceProvider::class); + $this->app->register(\Fintech\Remit\Providers\EventServiceProvider::class); + $this->app->register(\Fintech\Remit\Providers\RepositoryServiceProvider::class); + $this->app->register(\Fintech\Remit\Providers\RouteServiceProvider::class); } /** @@ -30,6 +35,8 @@ public function register() */ public function boot(): void { + $this->injectOnConfig(); + $this->publishes([ __DIR__.'/../config/remit.php' => config_path('fintech/remit.php'), ]); diff --git a/src/Repositories/Eloquent/BankTransferRepository.php b/src/Repositories/Eloquent/BankTransferRepository.php index 2b9a03b..9056219 100644 --- a/src/Repositories/Eloquent/BankTransferRepository.php +++ b/src/Repositories/Eloquent/BankTransferRepository.php @@ -3,6 +3,7 @@ namespace Fintech\Remit\Repositories\Eloquent; use Fintech\Remit\Interfaces\BankTransferRepository as InterfacesBankTransferRepository; +use Fintech\Remit\Models\BankTransfer; use Fintech\Transaction\Repositories\Eloquent\OrderRepository; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Pagination\Paginator; @@ -17,7 +18,7 @@ class BankTransferRepository extends OrderRepository implements InterfacesBankTr { public function __construct() { - $model = app(config('fintech.remit.bank_transfer_model', \Fintech\Remit\Models\BankTransfer::class)); + $model = app(config('fintech.remit.bank_transfer_model', BankTransfer::class)); if (! $model instanceof Model) { throw new InvalidArgumentException("Eloquent repository require model class to be `Illuminate\Database\Eloquent\Model` instance."); diff --git a/src/Repositories/Eloquent/CashPickupRepository.php b/src/Repositories/Eloquent/CashPickupRepository.php index c975696..cda3da4 100644 --- a/src/Repositories/Eloquent/CashPickupRepository.php +++ b/src/Repositories/Eloquent/CashPickupRepository.php @@ -3,11 +3,11 @@ namespace Fintech\Remit\Repositories\Eloquent; use Fintech\Remit\Interfaces\CashPickupRepository as InterfacesCashPickupRepository; +use Fintech\Remit\Models\CashPickup; use Fintech\Transaction\Repositories\Eloquent\OrderRepository; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Model; use InvalidArgumentException; /** @@ -17,7 +17,7 @@ class CashPickupRepository extends OrderRepository implements InterfacesCashPick { public function __construct() { - $model = app(config('fintech.remit.cash_pickup_model', \Fintech\Remit\Models\CashPickup::class)); + $model = app(config('fintech.remit.cash_pickup_model', CashPickup::class)); if (! $model instanceof Model) { throw new InvalidArgumentException("Eloquent repository require model class to be `Illuminate\Database\Eloquent\Model` instance."); diff --git a/src/Repositories/Eloquent/WalletTransferRepository.php b/src/Repositories/Eloquent/WalletTransferRepository.php index cfb2a7f..1bf2c63 100644 --- a/src/Repositories/Eloquent/WalletTransferRepository.php +++ b/src/Repositories/Eloquent/WalletTransferRepository.php @@ -3,11 +3,11 @@ namespace Fintech\Remit\Repositories\Eloquent; use Fintech\Remit\Interfaces\WalletTransferRepository as InterfacesWalletTransferRepository; +use Fintech\Remit\Models\WalletTransfer; use Fintech\Transaction\Repositories\Eloquent\OrderRepository; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Model; use InvalidArgumentException; /** @@ -17,7 +17,7 @@ class WalletTransferRepository extends OrderRepository implements InterfacesWall { public function __construct() { - $model = app(config('fintech.remit.wallet_transfer_model', \Fintech\Remit\Models\WalletTransfer::class)); + $model = app(config('fintech.remit.wallet_transfer_model', WalletTransfer::class)); if (! $model instanceof Model) { throw new InvalidArgumentException("Eloquent repository require model class to be `Illuminate\Database\Eloquent\Model` instance."); diff --git a/src/Repositories/Mongodb/BankTransferRepository.php b/src/Repositories/Mongodb/BankTransferRepository.php index a77cc22..22465a2 100644 --- a/src/Repositories/Mongodb/BankTransferRepository.php +++ b/src/Repositories/Mongodb/BankTransferRepository.php @@ -4,6 +4,7 @@ use Fintech\Core\Repositories\MongodbRepository; use Fintech\Remit\Interfaces\BankTransferRepository as InterfacesBankTransferRepository; +use Fintech\Remit\Models\BankTransfer; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Collection; use InvalidArgumentException; @@ -16,7 +17,7 @@ class BankTransferRepository extends MongodbRepository implements InterfacesBank { public function __construct() { - $model = app(config('fintech.remit.bank_transfer_model', \Fintech\Remit\Models\BankTransfer::class)); + $model = app(config('fintech.remit.bank_transfer_model', BankTransfer::class)); if (! $model instanceof Model) { throw new InvalidArgumentException("Mongodb repository require model class to be `MongoDB\Laravel\Eloquent\Model` instance."); diff --git a/src/Repositories/Mongodb/CashPickupRepository.php b/src/Repositories/Mongodb/CashPickupRepository.php index aa33ded..d60ba1e 100644 --- a/src/Repositories/Mongodb/CashPickupRepository.php +++ b/src/Repositories/Mongodb/CashPickupRepository.php @@ -4,6 +4,7 @@ use Fintech\Core\Repositories\MongodbRepository; use Fintech\Remit\Interfaces\CashPickupRepository as InterfacesCashPickupRepository; +use Fintech\Remit\Models\CashPickup; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Collection; use InvalidArgumentException; @@ -16,7 +17,7 @@ class CashPickupRepository extends MongodbRepository implements InterfacesCashPi { public function __construct() { - $model = app(config('fintech.remit.cash_pickup_model', \Fintech\Remit\Models\CashPickup::class)); + $model = app(config('fintech.remit.cash_pickup_model', CashPickup::class)); if (! $model instanceof Model) { throw new InvalidArgumentException("Mongodb repository require model class to be `MongoDB\Laravel\Eloquent\Model` instance."); diff --git a/src/Repositories/Mongodb/WalletTransferRepository.php b/src/Repositories/Mongodb/WalletTransferRepository.php index b1f3915..0e0f37a 100644 --- a/src/Repositories/Mongodb/WalletTransferRepository.php +++ b/src/Repositories/Mongodb/WalletTransferRepository.php @@ -4,6 +4,7 @@ use Fintech\Core\Repositories\MongodbRepository; use Fintech\Remit\Interfaces\WalletTransferRepository as InterfacesWalletTransferRepository; +use Fintech\Remit\Models\WalletTransfer; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Collection; use InvalidArgumentException; @@ -16,7 +17,7 @@ class WalletTransferRepository extends MongodbRepository implements InterfacesWa { public function __construct() { - $model = app(config('fintech.remit.wallet_transfer_model', \Fintech\Remit\Models\WalletTransfer::class)); + $model = app(config('fintech.remit.wallet_transfer_model', WalletTransfer::class)); if (! $model instanceof Model) { throw new InvalidArgumentException("Mongodb repository require model class to be `MongoDB\Laravel\Eloquent\Model` instance."); diff --git a/src/Seeders/Bangladesh/BankTransferVendorSeeder.php b/src/Seeders/Bangladesh/BankTransferVendorSeeder.php new file mode 100644 index 0000000..a7426cb --- /dev/null +++ b/src/Seeders/Bangladesh/BankTransferVendorSeeder.php @@ -0,0 +1,74 @@ +data() as $entry) { + $entry['logo_svg'] = 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'/'.$entry['logo_svg'])); + $entry['logo_png'] = 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'/'.$entry['logo_png'])); + Business::serviceVendor()->create($entry); + } + } + } + + private function data(): array + { + return [ + [ + 'service_vendor_name' => 'City Bank', + 'service_vendor_slug' => 'citybank', + 'service_vendor_data' => [], + 'enabled' => false, + 'logo_png' => 'citybank.png', + 'logo_svg' => 'citybank.svg', + ], + [ + 'service_vendor_name' => 'Agrani Bank', + 'service_vendor_slug' => 'agrani', + 'service_vendor_data' => [], + 'enabled' => false, + 'logo_png' => 'agrani.png', + 'logo_svg' => 'agrani.svg', + ], + [ + 'service_vendor_name' => 'EMQ', + 'service_vendor_slug' => 'emqapi', + 'service_vendor_data' => [], + 'enabled' => false, + 'logo_png' => 'emqapi.png', + 'logo_svg' => 'emqapi.svg', + ], + [ + 'service_vendor_name' => 'Transfast', + 'service_vendor_slug' => 'transfast', + 'service_vendor_data' => [], + 'enabled' => false, + 'logo_png' => 'transfast.png', + 'logo_svg' => 'transfast.svg', + ], + [ + 'service_vendor_name' => 'Value You', + 'service_vendor_slug' => 'valyou', + 'service_vendor_data' => [], + 'enabled' => false, + 'logo_png' => 'valyou.png', + 'logo_svg' => 'valyou.svg', + ], + + ]; + } +} diff --git a/src/Seeders/Bangladesh/WalletTransferSeeder.php b/src/Seeders/Bangladesh/WalletTransferSeeder.php index 88c3629..52a0728 100644 --- a/src/Seeders/Bangladesh/WalletTransferSeeder.php +++ b/src/Seeders/Bangladesh/WalletTransferSeeder.php @@ -2,7 +2,10 @@ namespace Fintech\Remit\Seeders\Bangladesh; +use Fintech\Auth\Facades\Auth; +use Fintech\Business\Facades\Business; use Fintech\Core\Facades\Core; +use Fintech\MetaData\Facades\MetaData; use Illuminate\Database\Seeder; class WalletTransferSeeder extends Seeder @@ -21,17 +24,17 @@ public function run(): void unset($entry['serviceTypeChild']); } - $findServiceTypeModel = \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => $entry['service_type_slug']])->first(); + $findServiceTypeModel = Business::serviceType()->list(['service_type_slug' => $entry['service_type_slug']])->first(); if ($findServiceTypeModel) { - $serviceTypeModel = \Fintech\Business\Facades\Business::serviceType()->update($findServiceTypeModel->id, $entry); + $serviceTypeModel = Business::serviceType()->update($findServiceTypeModel->id, $entry); } else { - $serviceTypeModel = \Fintech\Business\Facades\Business::serviceType()->create($entry); + $serviceTypeModel = Business::serviceType()->create($entry); } if (! empty($serviceTypeChild)) { array_walk($serviceTypeChild, function ($item) use (&$serviceTypeModel) { $item['service_type_parent_id'] = $serviceTypeModel->id; - \Fintech\Business\Facades\Business::serviceType()->create($item); + Business::serviceType()->create($item); }); } } @@ -41,7 +44,7 @@ public function run(): void foreach (array_chunk($serviceData, 200) as $block) { set_time_limit(2100); foreach ($block as $entry) { - \Fintech\Business\Facades\Business::service()->create($entry); + Business::service()->create($entry); } } @@ -49,7 +52,7 @@ public function run(): void foreach (array_chunk($serviceStatData, 200) as $block) { set_time_limit(2100); foreach ($block as $entry) { - \Fintech\Business\Facades\Business::serviceStat()->customStore($entry); + Business::serviceStat()->customStore($entry); } } } @@ -62,7 +65,7 @@ private function serviceType(): array return [ [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'bKash', 'service_type_slug' => 'mfs_bkash', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mfs_bkash.svg')), @@ -72,7 +75,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'Nagad', 'service_type_slug' => 'mfs_nagad', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mfs_nagad.svg')), @@ -82,7 +85,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'Rocket', 'service_type_slug' => 'mbs_rocket', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_rocket.svg')), @@ -92,7 +95,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'MCash', 'service_type_slug' => 'mbs_m_cash', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_m_cash.svg')), @@ -102,7 +105,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'SureCash', 'service_type_slug' => 'mbs_sure_cash', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_sure_cash.svg')), @@ -112,7 +115,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'Upay', 'service_type_slug' => 'mbs_u_pay', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_u_pay.svg')), @@ -121,7 +124,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'Ipay', 'service_type_slug' => 'mbs_i_pay', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_i_pay.svg')), @@ -130,7 +133,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'Trust Axiata Pay (Tap)', 'service_type_slug' => 'mbs_trust_axiata_pay_tap', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_trust_axiata_pay_tap.svg')), @@ -139,7 +142,7 @@ private function serviceType(): array 'service_type_step' => '3', 'enabled' => true], [ - 'service_type_parent_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, + 'service_type_parent_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_type_name' => 'OK Wallet', 'service_type_slug' => 'mbs_ok_wallet', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_ok_wallet.svg')), @@ -156,114 +159,150 @@ private function service(): array $image_png = __DIR__.'/../../../resources/img/service/logo_png/'; return [ - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mfs_bkash'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'bKash', + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mfs_bkash'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'bKash', 'service_slug' => 'mfs_bkash', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mfs_bkash.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mfs_bkash.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 1, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mfs_nagad'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Nagad', + 'beneficiary_type_id' => 1, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mfs_nagad'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Nagad', 'service_slug' => 'mfs_nagad', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mfs_nagad.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mfs_nagad.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 3, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_rocket'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Rocket', + 'beneficiary_type_id' => 3, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_rocket'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Rocket', 'service_slug' => 'mbs_rocket', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_rocket.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_rocket.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_m_cash'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'MCash', + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_m_cash'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'MCash', 'service_slug' => 'mbs_m_cash', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_m_cash.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_m_cash.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_sure_cash'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'SureCash', + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_sure_cash'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'SureCash', 'service_slug' => 'mbs_sure_cash', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_sure_cash.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_sure_cash.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_u_pay'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Upay', + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_u_pay'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Upay', 'service_slug' => 'mbs_u_pay', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_u_pay.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_u_pay.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_i_pay'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Ipay', + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_i_pay'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Ipay', 'service_slug' => 'mbs_i_pay', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_i_pay.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_i_pay.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_trust_axiata_pay_tap'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Trust Axiata Pay (Tap)', + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_trust_axiata_pay_tap'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Trust Axiata Pay (Tap)', 'service_slug' => 'mbs_trust_axiata_pay_tap', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_trust_axiata_pay_tap.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_trust_axiata_pay_tap.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'mbs_ok_wallet'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'OK Wallet', + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], + [ + 'service_type_id' => Business::serviceType()->list(['service_type_slug' => 'mbs_ok_wallet'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'OK Wallet', 'service_slug' => 'mbs_ok_wallet', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'mbs_ok_wallet.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'mbs_ok_wallet.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', - 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', + 'service_serial' => 1, + 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', - 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], + 'beneficiary_type_id' => 5, 'operator_short_code' => null], + 'enabled' => true, + ], ]; } @@ -272,11 +311,11 @@ private function serviceStat(): array { $serviceLists = $this->service(); $serviceStats = []; - $roles = \Fintech\Auth\Facades\Auth::role()->list(['id_not_in_array' => [1]])->pluck('id')->toArray(); - $source_countries = \Fintech\MetaData\Facades\MetaData::country()->list(['is_serving' => true])->pluck('id')->toArray(); + $roles = Auth::role()->list(['id_not_in_array' => [1]])->pluck('id')->toArray(); + $source_countries = MetaData::country()->list(['is_serving' => true])->pluck('id')->toArray(); if (! empty($roles) && ! empty($source_countries)) { foreach ($serviceLists as $serviceList) { - $service = \Fintech\Business\Facades\Business::service()->list(['service_slug' => $serviceList['service_slug']])->first(); + $service = Business::service()->list(['service_slug' => $serviceList['service_slug']])->first(); $serviceStats[] = [ 'role_id' => $roles, 'service_id' => $service->getKey(), diff --git a/src/Seeders/RemitSeeder.php b/src/Seeders/RemitSeeder.php index e3e895b..c92b746 100644 --- a/src/Seeders/RemitSeeder.php +++ b/src/Seeders/RemitSeeder.php @@ -2,7 +2,10 @@ namespace Fintech\Remit\Seeders; +use Fintech\Auth\Facades\Auth; +use Fintech\Business\Facades\Business; use Fintech\Core\Facades\Core; +use Fintech\MetaData\Facades\MetaData; use Illuminate\Database\Seeder; class RemitSeeder extends Seeder @@ -21,17 +24,17 @@ public function run(): void unset($entry['serviceTypeChild']); } - $findServiceTypeModel = \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => $entry['service_type_slug']])->first(); + $findServiceTypeModel = Business::serviceType()->list(['service_type_slug' => $entry['service_type_slug']])->first(); if ($findServiceTypeModel) { - $serviceTypeModel = \Fintech\Business\Facades\Business::serviceType()->update($findServiceTypeModel->id, $entry); + $serviceTypeModel = Business::serviceType()->update($findServiceTypeModel->id, $entry); } else { - $serviceTypeModel = \Fintech\Business\Facades\Business::serviceType()->create($entry); + $serviceTypeModel = Business::serviceType()->create($entry); } if (! empty($serviceTypeChild)) { array_walk($serviceTypeChild, function ($item) use (&$serviceTypeModel) { - $item['service_type_parent_id'] = $serviceTypeModel->id; - \Fintech\Business\Facades\Business::serviceType()->create($item); + $item['service_type_parent_id'] = $serviceTypeModel->getKey(); + Business::serviceType()->create($item); }); } } @@ -41,7 +44,7 @@ public function run(): void foreach (array_chunk($serviceData, 200) as $block) { set_time_limit(2100); foreach ($block as $entry) { - \Fintech\Business\Facades\Business::service()->create($entry); + Business::service()->create($entry); } } @@ -49,7 +52,7 @@ public function run(): void foreach (array_chunk($serviceStatData, 200) as $block) { set_time_limit(2100); foreach ($block as $entry) { - \Fintech\Business\Facades\Business::serviceStat()->customStore($entry); + Business::serviceStat()->customStore($entry); } } } @@ -86,9 +89,9 @@ private function service(): array $image_png = __DIR__.'/../../resources/img/service/logo_png/'; return [ - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'bank_transfer'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Bank Transfer', 'service_slug' => 'bank_transfer', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'bank_transfer.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'bank_transfer.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', 'beneficiary_type_id' => 1, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'cash_pickup'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Cash Pickup', 'service_slug' => 'cash_pickup', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'cash_pickup.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'cash_pickup.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', 'beneficiary_type_id' => 3, 'operator_short_code' => null], 'enabled' => true], - ['service_type_id' => \Fintech\Business\Facades\Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Wallet Transfer', 'service_slug' => 'wallet_transfer', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'wallet_transfer.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'wallet_transfer.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], + ['service_type_id' => Business::serviceType()->list(['service_type_slug' => 'bank_transfer'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Bank Transfer', 'service_slug' => 'bank_transfer', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'bank_transfer.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'bank_transfer.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', 'beneficiary_type_id' => 1, 'operator_short_code' => null], 'enabled' => true], + ['service_type_id' => Business::serviceType()->list(['service_type_slug' => 'cash_pickup'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Cash Pickup', 'service_slug' => 'cash_pickup', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'cash_pickup.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'cash_pickup.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', 'beneficiary_type_id' => 3, 'operator_short_code' => null], 'enabled' => true], + ['service_type_id' => Business::serviceType()->list(['service_type_slug' => 'wallet_transfer'])->first()->id, 'service_vendor_id' => 1, 'service_name' => 'Wallet Transfer', 'service_slug' => 'wallet_transfer', 'logo_svg' => 'data:image/svg+xml;base64,'.base64_encode(file_get_contents($image_svg.'wallet_transfer.svg')), 'logo_png' => 'data:image/png;base64,'.base64_encode(file_get_contents($image_png.'wallet_transfer.png')), 'service_notification' => 'yes', 'service_delay' => 'yes', 'service_stat_policy' => 'yes', 'service_serial' => 1, 'service_data' => ['visible_website' => 'yes', 'visible_android_app' => 'yes', 'visible_ios_app' => 'yes', 'account_name' => '', 'account_number' => '', 'transactional_currency' => '', 'beneficiary_type_id' => 5, 'operator_short_code' => null], 'enabled' => true], ]; } @@ -97,11 +100,11 @@ private function serviceStat(): array { $serviceLists = $this->service(); $serviceStats = []; - $roles = \Fintech\Auth\Facades\Auth::role()->list(['id_not_in_array' => [1]])->pluck('id')->toArray(); - $source_countries = \Fintech\MetaData\Facades\MetaData::country()->list(['is_serving' => true])->pluck('id')->toArray(); + $roles = Auth::role()->list(['id_not_in_array' => [1]])->pluck('id')->toArray(); + $source_countries = MetaData::country()->list(['is_serving' => true])->pluck('id')->toArray(); if (! empty($roles) && ! empty($source_countries)) { foreach ($serviceLists as $serviceList) { - $service = \Fintech\Business\Facades\Business::service()->list(['service_slug' => $serviceList['service_slug']])->first(); + $service = Business::service()->list(['service_slug' => $serviceList['service_slug']])->first(); $serviceStats[] = [ 'role_id' => $roles, 'service_id' => $service->getKey(), diff --git a/src/Services/BankTransferService.php b/src/Services/BankTransferService.php index eefa531..f1bf759 100644 --- a/src/Services/BankTransferService.php +++ b/src/Services/BankTransferService.php @@ -2,10 +2,10 @@ namespace Fintech\Remit\Services; +use Fintech\Core\Abstracts\BaseModel; use Fintech\Remit\Interfaces\BankTransferRepository; use Fintech\Transaction\Facades\Transaction; use Illuminate\Contracts\Pagination\Paginator; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; /** @@ -23,23 +23,12 @@ public function __construct(BankTransferRepository $bankTransferRepository) $this->bankTransferRepository = $bankTransferRepository; } - public function list(array $filters = []): Collection|Paginator - { - return $this->bankTransferRepository->list($filters); - - } - - public function create(array $inputs = []): Model|\MongoDB\Laravel\Eloquent\Model|null - { - return $this->bankTransferRepository->create($inputs); - } - - public function find($id, bool $onlyTrashed = false): Model|\MongoDB\Laravel\Eloquent\Model|null + public function find($id, bool $onlyTrashed = false): ?BaseModel { return $this->bankTransferRepository->find($id, $onlyTrashed); } - public function update($id, array $inputs = []): Model|\MongoDB\Laravel\Eloquent\Model|null + public function update($id, array $inputs = []): ?BaseModel { return $this->bankTransferRepository->update($id, $inputs); } @@ -65,11 +54,22 @@ public function export(array $filters): Paginator|Collection return $this->bankTransferRepository->list($filters); } - public function import(array $filters): Model|\MongoDB\Laravel\Eloquent\Model|null + public function list(array $filters = []): Collection|Paginator + { + return $this->bankTransferRepository->list($filters); + + } + + public function import(array $filters): ?BaseModel { return $this->bankTransferRepository->create($filters); } + public function create(array $inputs = []): ?BaseModel + { + return $this->bankTransferRepository->create($inputs); + } + /** * @return int[] */ diff --git a/src/Services/CashPickupService.php b/src/Services/CashPickupService.php index db273cf..15bf4eb 100644 --- a/src/Services/CashPickupService.php +++ b/src/Services/CashPickupService.php @@ -2,10 +2,10 @@ namespace Fintech\Remit\Services; +use Fintech\Core\Abstracts\BaseModel; use Fintech\Remit\Interfaces\CashPickupRepository; use Fintech\Transaction\Facades\Transaction; use Illuminate\Contracts\Pagination\Paginator; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; /** @@ -23,23 +23,12 @@ public function __construct(CashPickupRepository $cashPickupRepository) $this->cashPickupRepository = $cashPickupRepository; } - public function list(array $filters = []): Collection|Paginator - { - return $this->cashPickupRepository->list($filters); - - } - - public function create(array $inputs = []): Model|\MongoDB\Laravel\Eloquent\Model|null - { - return $this->cashPickupRepository->create($inputs); - } - - public function find($id, bool $onlyTrashed = false): Model|\MongoDB\Laravel\Eloquent\Model|null + public function find($id, bool $onlyTrashed = false): ?BaseModel { return $this->cashPickupRepository->find($id, $onlyTrashed); } - public function update($id, array $inputs = []): Model|\MongoDB\Laravel\Eloquent\Model|null + public function update($id, array $inputs = []): ?BaseModel { return $this->cashPickupRepository->update($id, $inputs); } @@ -59,11 +48,22 @@ public function export(array $filters): Paginator|Collection return $this->cashPickupRepository->list($filters); } - public function import(array $filters): Model|\MongoDB\Laravel\Eloquent\Model|null + public function list(array $filters = []): Collection|Paginator + { + return $this->cashPickupRepository->list($filters); + + } + + public function import(array $filters): ?BaseModel { return $this->cashPickupRepository->create($filters); } + public function create(array $inputs = []): ?BaseModel + { + return $this->cashPickupRepository->create($inputs); + } + /** * @return int[] */ diff --git a/src/Services/WalletTransferService.php b/src/Services/WalletTransferService.php index 937f3d3..a44a10b 100644 --- a/src/Services/WalletTransferService.php +++ b/src/Services/WalletTransferService.php @@ -2,10 +2,10 @@ namespace Fintech\Remit\Services; +use Fintech\Core\Abstracts\BaseModel; use Fintech\Remit\Interfaces\WalletTransferRepository; use Fintech\Transaction\Facades\Transaction; use Illuminate\Contracts\Pagination\Paginator; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; /** @@ -23,23 +23,12 @@ public function __construct(WalletTransferRepository $walletTransferRepository) $this->walletTransferRepository = $walletTransferRepository; } - public function list(array $filters = []): Collection|Paginator - { - return $this->walletTransferRepository->list($filters); - - } - - public function create(array $inputs = []): Model|\MongoDB\Laravel\Eloquent\Model|null - { - return $this->walletTransferRepository->create($inputs); - } - - public function find($id, bool $onlyTrashed = false): Model|\MongoDB\Laravel\Eloquent\Model|null + public function find($id, bool $onlyTrashed = false): ?BaseModel { return $this->walletTransferRepository->find($id, $onlyTrashed); } - public function update($id, array $inputs = []): Model|\MongoDB\Laravel\Eloquent\Model|null + public function update($id, array $inputs = []): ?BaseModel { return $this->walletTransferRepository->update($id, $inputs); } @@ -59,11 +48,22 @@ public function export(array $filters): Paginator|Collection return $this->walletTransferRepository->list($filters); } - public function import(array $filters): Model|\MongoDB\Laravel\Eloquent\Model|null + public function list(array $filters = []): Collection|Paginator + { + return $this->walletTransferRepository->list($filters); + + } + + public function import(array $filters): ?BaseModel { return $this->walletTransferRepository->create($filters); } + public function create(array $inputs = []): ?BaseModel + { + return $this->walletTransferRepository->create($inputs); + } + /** * @return int[] */ diff --git a/src/Traits/AuthRelations.php b/src/Traits/AuthRelations.php index ff7710d..c414007 100644 --- a/src/Traits/AuthRelations.php +++ b/src/Traits/AuthRelations.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Traits; +use Fintech\Auth\Models\User; use Fintech\Core\Facades\Core; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -11,14 +12,14 @@ trait AuthRelations public function senderReceiver(): BelongsTo { return $this->belongsTo( - config('fintech.auth.user_model', \Fintech\Auth\Models\User::class), + config('fintech.auth.user_model', User::class), 'sender_receiver_id'); } public function user(): BelongsTo { return $this->belongsTo( - config('fintech.auth.user_model', \Fintech\Auth\Models\User::class), + config('fintech.auth.user_model', User::class), 'user_id'); } } diff --git a/src/Traits/BusinessRelations.php b/src/Traits/BusinessRelations.php index 8180408..af528bd 100644 --- a/src/Traits/BusinessRelations.php +++ b/src/Traits/BusinessRelations.php @@ -2,6 +2,7 @@ namespace Fintech\Remit\Traits; +use Fintech\Business\Models\Service; use Fintech\Core\Facades\Core; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -10,7 +11,7 @@ trait BusinessRelations { public function service(): BelongsTo { - return $this->belongsTo(config('fintech.business.service_model', \Fintech\Business\Models\Service::class)); + return $this->belongsTo(config('fintech.business.service_model', Service::class)); } } } else { diff --git a/src/Traits/MetaDataRelations.php b/src/Traits/MetaDataRelations.php index 22389cf..9ef5792 100644 --- a/src/Traits/MetaDataRelations.php +++ b/src/Traits/MetaDataRelations.php @@ -3,6 +3,7 @@ namespace Fintech\Remit\Traits; use Fintech\Core\Facades\Core; +use Fintech\MetaData\Models\Country; use Illuminate\Database\Eloquent\Relations\BelongsTo; if (Core::packageExists('MetaData')) { @@ -11,14 +12,14 @@ trait MetaDataRelations public function sourceCountry(): BelongsTo { return $this->belongsTo( - config('fintech.metadata.country_model', \Fintech\MetaData\Models\Country::class), + config('fintech.metadata.country_model', Country::class), 'source_country_id'); } public function destinationCountry(): BelongsTo { return $this->belongsTo( - config('fintech.metadata.country_model', \Fintech\MetaData\Models\Country::class), + config('fintech.metadata.country_model', Country::class), 'destination_country_id'); } } diff --git a/src/Vendors/AgraniBankApi.php b/src/Vendors/AgraniBankApi.php index 3f7988a..95a757e 100644 --- a/src/Vendors/AgraniBankApi.php +++ b/src/Vendors/AgraniBankApi.php @@ -5,8 +5,11 @@ use App\Services\Backend\Setting\CatalogListService; use App\Services\Backend\Setting\CountryService; use Carbon\Carbon; +use DOMDocument; +use DOMException; use Exception; use Illuminate\Support\Facades\Log; +use stdClass; class AgraniBankApi { @@ -30,6 +33,16 @@ class AgraniBankApi */ public $currency = null; + /** + * @var DOMDocument + */ + public $xmlBody; + + /** + * @var array + */ + public $transactionBody; //base64 encode of auth + /** * EMQ API configuration. * @@ -40,7 +53,7 @@ class AgraniBankApi /** * @var mixed|string */ - private $apiUrl; //base64 encode of auth + private $apiUrl; /** * @var string @@ -62,23 +75,13 @@ class AgraniBankApi */ private $countryService; - /** - * @var \DOMDocument - */ - public $xmlBody; - - /** - * @var array - */ - public $transactionBody; - /** * EMQApiService constructor. * * @param CatalogListService $catalogListService * @param CountryService $countryService * - * @throws \DOMException + * @throws DOMException */ public function __construct() { @@ -87,7 +90,7 @@ public function __construct() $this->apiUrl = $this->config[$this->status]['endpoint']; $this->encodeCredential(); - $this->xmlBody = new \DOMDocument('1.0', 'utf-8'); + $this->xmlBody = new DOMDocument('1.0', 'utf-8'); $this->xmlBody->preserveWhiteSpace = false; $this->xmlBody->formatOutput = true; $this->xmlBody->xmlStandalone = true; @@ -96,16 +99,27 @@ public function __construct() } + /** + * Encode Auth info to base64 and store on $basicAuthHash + * + * @return void + */ + protected function encodeCredential() + { + $asciString = '{ "Username=7106UAT", "Expassword=7106@Pass" }'; + $this->basicAuthHash = $asciString; + } + /** * Agrani Transfer TopUp * - * @return \stdClass + * @return stdClass * * @throws Exception */ public function topUp($data) { - $returnData = new \stdClass(); + $returnData = new stdClass(); $reference = $data->reference_no; @@ -182,165 +196,198 @@ public function topUp($data) } /** - * Agrani Transfer TopUp + * Create bank transfers to for All * - * @return \stdClass + * @return array * * @throws Exception */ - public function oldTopUp($data) + public function postCreateTransaction($data) { - $returnData = new \stdClass(); - - $reference = $data->reference_no; - - $transactionCreateResponse = $this->postCreateTransaction($data); - - Log::info('Unconfirmed APi Request:', $transactionCreateResponse); - - $returnData->emq_create_response = json_encode($transactionCreateResponse); - - switch ($transactionCreateResponse['status']) { - case 200: - case 201: - - //send confirmation request - $transConfirmResponse = $this->postTransactionConfirm($reference); - $returnData->emq_confirm_response = json_encode($transConfirmResponse); - - Log::info('Confirmed APi Request:', $transConfirmResponse); - - switch ($transConfirmResponse['status']) { - case 200: - case 201: - - $this->renderApiResponse($transConfirmResponse['response'], $returnData); - break; - - case 400: - - $returnData->message = $this->errorHandler($transConfirmResponse['response']); - $returnData->status = 'failed'; - break; - - case 500: - - $returnData->message = $transactionCreateResponse['response']['message']; - $returnData->status = 'failed'; - break; - - default: + $transactionTypes = ['Bank' => '15', 'Cash Pickup' => '05', 'CBS' => '16', 'Bkash' => '17']; - $returnData->message = 'Something went wrong from vendor API: Status Code :'.$transactionCreateResponse['status']; - $returnData->status = 'failed'; - break; + $sender_last_name = isset($data->sender_last_name) ? $data->sender_last_name : ''; - } + $sender_first_name = isset($data->sender_first_name) ? $data->sender_first_name : ''; - $returnData->status_code = 201; - break; + $full_name = $sender_first_name; + if (strlen($sender_last_name) > 0) { + $full_name .= (' '.$sender_last_name); + } - case 400: + $nameArray = preg_split("/\s+(?=\S*+$)/", $full_name); - $returnData->message = $this->errorHandler($transactionCreateResponse['response']); - $returnData->status = 'failed'; - $returnData->status_code = 201; - break; + if (count($nameArray) > 1) { + $sender_first_name = $nameArray[0]; + $sender_last_name = $nameArray[1]; + } else { + $sender_last_name = $sender_first_name; + } - case 500: + $transferInfo['tranno'] = $data->reference_no; + $transferInfo['traninfosl'] = $data->reference_no; + $transferInfo['trmode'] = isset($data->recipient_type_name) + ? ($transactionTypes[$data->recipient_type_name] ?? '15') + : '15'; - $returnData->message = $transactionCreateResponse['response']['message']; - $returnData->status = 'failed'; - $returnData->status_code = 201; - break; + $transferInfo['purpose'] = $data->emq_purpose_of_remittance ?? null; //TODO agrani code needed + $transferInfo['remamountdest'] = isset($data->transfer_amount) ? round($data->transfer_amount, 2) : '0.00'; + $transferInfo['remfname'] = $sender_first_name; + $transferInfo['remlname'] = $sender_last_name; + $transferInfo['remit_tel'] = isset($data->sender_mobile) ? substr($data->sender_mobile, -11) : null; + $transferInfo['remaddress1'] = trim(($data->sender_address ?? null).' '.($data->sender_city ?? null)); + $transferInfo['remcountry'] = $data->trans_fast_sender_country_iso_code ?? null; //TODO agrani country code needed + $transferInfo['benename'] = $data->receiver_first_name ?? null; + $transferInfo['benemname'] = $data->receiver_middle_name ?? ' '; + $transferInfo['benelname'] = $data->receiver_last_name ?? null; + $transferInfo['beneaccountno'] = $data->bank_account_number ?? null; + $transferInfo['benetel'] = $data->receiver_contact_number ?? null; + $transferInfo['branchcode'] = substr(($data->location_routing_id[1]->bank_branch_location_field_value ?? null), -6); + $transferInfo['beneaddress'] = $data->receiver_address ?? null; + $transferInfo['benecountry'] = $data->trans_fast_receiver_country_iso_code ?? null; + $transferInfo['entereddatetime'] = Carbon::now(config('app.timezone'))->format('Y-m-d\TH:i:s.u'); + $transferInfo['ratevalue'] = 0; + $transferInfo['counttr'] = 0; + $transferInfo['excode'] = $this->getExcode(); + $transferInfo['signaturevalue'] = $this->getTransactionSignature($transferInfo); - default: + array_walk($transferInfo, function (&$value, $key) { + $this->transactionBody->appendChild($this->xmlBody->createElement($key, $value)); + }); - $returnData->message = 'Something went wrong from vendor API: Status Code :'.$transactionCreateResponse['status']; - $returnData->status = 'failed'; - $returnData->status_code = 201; - break; + $this->xmlBody->appendChild($this->transactionBody); - } + Log::info($this->xmlBody->saveXML()); - return $returnData; + //die(); + return $this->putPostData('/MyCash', $transferInfo, 'POST'); } /** - * Render Emq Response to pointed StdClass + * Return Excode from config * - * @param array $response emq response - * @param \stdClass $returnData class that will get rendered response - * @return void + * @return string */ - public function renderApiResponse(array $response, \stdClass &$returnData) + public function getExcode() { - $returnData->init_time = $response['created'] ?? date('Y-m-d H:i:s P'); - $returnData->recharge_time = $response['created'] ?? date('Y-m-d H:i:s P'); - $returnData->recharge_status = isset($response['info']['state']) ? $response['info']['state'] : null; - - $returnData->reference_no = isset($response['reference']) ? $response['reference'] : null; - - if (isset($response['destination']['type']) && $response['destination']['type'] == 'back_account') { - $returnData->operator_name = isset($response['destination']['bank']) ? $response['destination']['bank'] : null; - $returnData->operator_id = isset($response['destination']['branch']) ? $response['destination']['branch'] : null; - } else { - $returnData->operator_name = isset($response['destination']['partner']) ? $response['destination']['partner'] : null; - $returnData->operator_id = isset($response['destination']['segment']) ? $response['destination']['segment'] : null; - } - - $returnData->connection_type = isset($response['destination']['type']) ? $response['destination']['type'] : null; - $returnData->recipient_msisdn = isset($response['destination']['account_number']) ? $response['destination']['account_number'] : null; - - $returnData->amount = isset($response['destination_amount']['units']) ? $response['destination_amount']['units'] : null; - $returnData->order_total = isset($response['source_amount']['units']) ? $response['source_amount']['units'] : null; + return $this->config[$this->status]['excode'] ?? 7106; + } - $returnData->available_credit = isset($response['info']['state']) ? $response['info']['state'] : null; - $returnData->message = json_encode($response['info'], JSON_PRETTY_PRINT); + /** + * @return string|null + */ + public function getTransactionSignature(array $transferInfo = []) + { + $signature = ''; + $signature .= $transferInfo['tranno']; + $signature .= $transferInfo['trmode']; + $signature .= $transferInfo['benename']; + $signature .= $transferInfo['remfname']; + $signature .= $transferInfo['beneaccountno']; + $signature .= $transferInfo['branchcode']; + $signature .= $transferInfo['benetel']; + $signature .= $transferInfo['remamountdest']; + $signature .= $transferInfo['entereddatetime']; - //$returnData->vr_guid = $response['info']['code']; - $returnData->vr_guid = isset($response['reference']) ? $response['reference'] : null; - $returnData->telco_transaction_id = isset($response['info']['code']) ? $response['info']['code'] : null; + return $this->encryptSignature($signature, ''); } - /******************************************* Auth *******************************************/ - - public function createPfxFile() + public function encryptSignature(string $plainText, $privateKey) { - $certificate = file_get_contents($this->config['signature']['certificate']); - $output_filepath = $this->config['signature']['target_pfx']; - $private_key = file_get_contents($this->config['signature']['private_key']); - $password = $this->config['signature']['passphase']; + /*$signature = ''; - openssl_pkcs12_export_to_file($certificate, $output_filepath, $private_key, $password); + openssl_sign($plainText,$signature, $privateKey);*/ + $key = '-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA71FijlOQ4FfKc0VKtjc7Mv6aZmSR9oLjq3uDw/88avOSrIpw +qaTCrwtk2zsFMl1YA3hByhF+TP95E0dDwGWXk1JkLWfZ/sjep+694PtS1oiyvOB8 +hTPYk6U42leHIZDldKk1eu7n0wUph5/5GfahXrHY+8qr38s/QVvG7ohh/dVs3rvs +VJ+QBZz5X9WNYcWIWsEySkyAmtppNVUuf6pwtAkCO4565cNoTk+5zCXpRxsxkgkv +HyTB+Nk4QuXibdC3slscZs75G9tc0TO7sC6lcnZFtTd4z5qk6f6LeI2/asviehc7 +awOl8nm9C3VKjZlgOYIejHhx0A5+lkzFdrk+JwIDAQABAoIBAQDNaZGqkFe9+Byx +LDyggm+xqY9la9VNPbOlMPM8fAuj0UWIC5wAQIdKMAF1mwcu36f38nSluLYr6OxH +e9fPgGPF8+ZAgu8+HbPfeLBKN+42bkbcj+LRglrW/+34m0BFs1T/+W0KA53AJqIq +40iw3FxOJ2ETXjaAdLfqpZfujeluMOW+Rjhe2VpILpWurgX07kWphP09TqK3yuja +At4lBKYFQth7a773uzSy8cy0Ohl+lvRHa/oVS0SXsiLo1iA1NYpXzKi0ww3+sSnw +kfoacFImVuqm2rxikTgSu9GUkC1REoseT5FRj8uHzyBm/wXAM1lniUGr6Moh9Yl2 +a9KNbj8hAoGBAPpHuaWIboumderokBXOwjWcW0EBDx1+SiR3kFHoYvpck9wAe2BM +vdva8IbFomCllq8UUGaW6vXEqVEUITwgGjZBQWeOgSWjo4p0b7o63ftZrsI+/Bl7 +1KJSSR/O45DTXrfD/jxMgTbnYqxbyBCQz54Om9aq338XICsFJkPsU2GzAoGBAPTJ +hkvxxkPOEHmuNjWbxJluFtWfw1Sg5dLMrd6csPB/pczW/TZJwKCJslHH1/SA5PVm +nroSkYgJDMas5caZogvuIO5YIdVIM0SVU0Hl1wYkK4nz2Zpt1YH7peQrjx9iuiGy +UTYpjdxb4nkz6WL8Zp0AIG+5Wxm9IzYKZmpFPO+9AoGACI/fl/wc3AYrzod6NmTG +XBMnRAgHPlkNrEWy2Dp8+Femb0ZM8jRt4lGRHOsx7OB9USv+vCO5kgLSUAXCRU5L +10NQO3yyilkYxSnKkLJm2axtwBNriGumEI+EFOR9AH1apiq8Tc/IM9qik4boRzjN +AXk6d5OM5coivZYFgxlYmOUCgYEA07hqO82GWqckgNo5cOylgr9BaMuiOtRfc5As +4lpMf/coBJ/+qrHntfLjFPDwzD2fytFTgEUHMs4BCuYIZ1oCWqdAPGZl/P9RuIQf +WuPcsycdsVgEYhmVjbOGrG8wf0j5DKQaseoHFQ00OPi5aDA+4JR3eaqsLPr2NYuR +QWFZb1ECgYBYagQ16rdG/aBU0sOd745EskY9F6Z+vpQ7U1J2gA6hdqT3Pl8epSOY +k6aHAHli0D9xC3UQzJSYVIGx6PDR8q5TgADSLyPDwejCArLUpchYrFz3R1FWRs/W +egQQX++y13mrQFJVKA7RCQPWEynD29lwP2oizhGIfEiqGfJZd3pTXQ== +-----END RSA PRIVATE KEY-----'; + $certs = []; + openssl_pkcs12_read(file_get_contents(public_path('Certificate.crt')), $certs, '1'); //where 1106@123 is your certificate password + //dd($certs); - } + //if (! $certs ) return ; + $signature = ''; + openssl_sign($plainText, $signature, $key); - /** - * Encode Auth info to base64 and store on $basicAuthHash - * - * @return void - */ - protected function encodeCredential() - { - $asciString = '{ "Username=7106UAT", "Expassword=7106@Pass" }'; - $this->basicAuthHash = $asciString; + return base64_encode($signature); } /** - * Login and obtain session token. + * Base function that is responsible for interacting directly with the nium api to send data * - * @param string username - * @param string password + * @return array * * @throws Exception */ - public function postLogin() + public function putPostData(string $url, array $dataArray = [], string $method = 'POST') { - $payLoad = ['username' => $this->getUsername(), 'password' => $this->getPassword()]; - $this->putPostData('/auth/login', $payLoad, 'POST'); + $apiUrl = $this->apiUrl.$url; + Log::info($apiUrl); + $jsonArray = json_encode($dataArray); + Log::info(json_decode($jsonArray, true)); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $apiUrl); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($curl, CURLOPT_POST, count($dataArray)); + curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonArray); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_VERBOSE, true); + + $headers = [ + 'cache-control: no-cache', + 'Content-Type: application/xml', + 'Accepts: application/xml', + 'Username: '.$this->getUsername(), + 'Expassword: '.$this->getPassword(), + ]; + + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + $response = curl_exec($curl); + $info = curl_getinfo($curl); + $error = curl_error($curl); + + //dd([$error, $info, $response]); + if ($response == false) { + Log::info($info); + Log::info($error); + throw new Exception(curl_error($curl), curl_errno($curl)); + } + + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + curl_close($curl); + + Log::info(json_decode($response, true)); + + return [ + 'status' => $status, + 'response' => json_decode($response, true), + ]; } /** @@ -353,16 +400,6 @@ public function getUsername() return $this->config[$this->status]['username']; } - /** - * Return Excode from config - * - * @return string - */ - public function getExcode() - { - return $this->config[$this->status]['excode'] ?? 7106; - } - /** * Return Password from config * @@ -374,173 +411,156 @@ public function getPassword() } /** - * Base function that is responsible for interacting directly with the nium api to obtain data - * - * @param array $params - * @return array + * Render Emq Response to pointed StdClass * - * @throws Exception + * @param array $response emq response + * @param stdClass $returnData class that will get rendered response + * @return void */ - public function getData($url, $params = []) + public function renderApiResponse(array $response, stdClass &$returnData) { - $apiUrl = $this->apiUrl.$url; - $apiUrl .= http_build_query($params); - Log::info($apiUrl); - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $apiUrl); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - $headers = [ - 'cache-control: no-cache', - 'Content-Type: application/json', - 'Accepts: application/json', - 'Username: '.$this->getUsername(), - 'Expassword: '.$this->getPassword(), - ]; - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + $returnData->init_time = $response['created'] ?? date('Y-m-d H:i:s P'); + $returnData->recharge_time = $response['created'] ?? date('Y-m-d H:i:s P'); + $returnData->recharge_status = isset($response['info']['state']) ? $response['info']['state'] : null; - $response = curl_exec($curl); - $info = curl_getinfo($curl); - $error = curl_error($curl); + $returnData->reference_no = isset($response['reference']) ? $response['reference'] : null; - if ($response == false) { - Log::info($info); - Log::info($error); - throw new Exception(curl_error($curl), curl_errno($curl)); + if (isset($response['destination']['type']) && $response['destination']['type'] == 'back_account') { + $returnData->operator_name = isset($response['destination']['bank']) ? $response['destination']['bank'] : null; + $returnData->operator_id = isset($response['destination']['branch']) ? $response['destination']['branch'] : null; + } else { + $returnData->operator_name = isset($response['destination']['partner']) ? $response['destination']['partner'] : null; + $returnData->operator_id = isset($response['destination']['segment']) ? $response['destination']['segment'] : null; } - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - curl_close($curl); + $returnData->connection_type = isset($response['destination']['type']) ? $response['destination']['type'] : null; + $returnData->recipient_msisdn = isset($response['destination']['account_number']) ? $response['destination']['account_number'] : null; - Log::info('API Response : '.$response); + $returnData->amount = isset($response['destination_amount']['units']) ? $response['destination_amount']['units'] : null; + $returnData->order_total = isset($response['source_amount']['units']) ? $response['source_amount']['units'] : null; - echo $response; + $returnData->available_credit = isset($response['info']['state']) ? $response['info']['state'] : null; + $returnData->message = json_encode($response['info'], JSON_PRETTY_PRINT); - return [ - 'status' => $status, - 'response' => json_decode($response, true), - ]; + //$returnData->vr_guid = $response['info']['code']; + $returnData->vr_guid = isset($response['reference']) ? $response['reference'] : null; + $returnData->telco_transaction_id = isset($response['info']['code']) ? $response['info']['code'] : null; } /** - * Base function that is responsible for interacting directly with the nium api to send data + * Agrani Transfer TopUp * - * @return array + * @return stdClass * * @throws Exception */ - public function putPostData(string $url, array $dataArray = [], string $method = 'POST') + public function oldTopUp($data) { - $apiUrl = $this->apiUrl.$url; - Log::info($apiUrl); - $jsonArray = json_encode($dataArray); - Log::info(json_decode($jsonArray, true)); + $returnData = new stdClass(); - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $apiUrl); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); - curl_setopt($curl, CURLOPT_POST, count($dataArray)); - curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonArray); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_VERBOSE, true); + $reference = $data->reference_no; - $headers = [ - 'cache-control: no-cache', - 'Content-Type: application/xml', - 'Accepts: application/xml', - 'Username: '.$this->getUsername(), - 'Expassword: '.$this->getPassword(), - ]; + $transactionCreateResponse = $this->postCreateTransaction($data); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + Log::info('Unconfirmed APi Request:', $transactionCreateResponse); - $response = curl_exec($curl); - $info = curl_getinfo($curl); - $error = curl_error($curl); + $returnData->emq_create_response = json_encode($transactionCreateResponse); - //dd([$error, $info, $response]); - if ($response == false) { - Log::info($info); - Log::info($error); - throw new Exception(curl_error($curl), curl_errno($curl)); - } + switch ($transactionCreateResponse['status']) { + case 200: + case 201: - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - curl_close($curl); + //send confirmation request + $transConfirmResponse = $this->postTransactionConfirm($reference); + $returnData->emq_confirm_response = json_encode($transConfirmResponse); - Log::info(json_decode($response, true)); + Log::info('Confirmed APi Request:', $transConfirmResponse); - return [ - 'status' => $status, - 'response' => json_decode($response, true), - ]; + switch ($transConfirmResponse['status']) { + case 200: + case 201: + + $this->renderApiResponse($transConfirmResponse['response'], $returnData); + break; + + case 400: + + $returnData->message = $this->errorHandler($transConfirmResponse['response']); + $returnData->status = 'failed'; + break; + + case 500: + + $returnData->message = $transactionCreateResponse['response']['message']; + $returnData->status = 'failed'; + break; + + default: + + $returnData->message = 'Something went wrong from vendor API: Status Code :'.$transactionCreateResponse['status']; + $returnData->status = 'failed'; + break; + + } + + $returnData->status_code = 201; + break; + + case 400: + + $returnData->message = $this->errorHandler($transactionCreateResponse['response']); + $returnData->status = 'failed'; + $returnData->status_code = 201; + break; + + case 500: + + $returnData->message = $transactionCreateResponse['response']['message']; + $returnData->status = 'failed'; + $returnData->status_code = 201; + break; + + default: + + $returnData->message = 'Something went wrong from vendor API: Status Code :'.$transactionCreateResponse['status']; + $returnData->status = 'failed'; + $returnData->status_code = 201; + break; + + } + + return $returnData; } /*********************************** Transaction ***************************************/ - /** - * @return string|null - */ - public function getTransactionSignature(array $transferInfo = []) + /******************************************* Auth *******************************************/ + + public function createPfxFile() { - $signature = ''; - $signature .= $transferInfo['tranno']; - $signature .= $transferInfo['trmode']; - $signature .= $transferInfo['benename']; - $signature .= $transferInfo['remfname']; - $signature .= $transferInfo['beneaccountno']; - $signature .= $transferInfo['branchcode']; - $signature .= $transferInfo['benetel']; - $signature .= $transferInfo['remamountdest']; - $signature .= $transferInfo['entereddatetime']; + $certificate = file_get_contents($this->config['signature']['certificate']); + $output_filepath = $this->config['signature']['target_pfx']; + $private_key = file_get_contents($this->config['signature']['private_key']); + $password = $this->config['signature']['passphase']; - return $this->encryptSignature($signature, ''); + openssl_pkcs12_export_to_file($certificate, $output_filepath, $private_key, $password); } - public function encryptSignature(string $plainText, $privateKey) + /** + * Login and obtain session token. + * + * @param string username + * @param string password + * + * @throws Exception + */ + public function postLogin() { - /*$signature = ''; - - openssl_sign($plainText,$signature, $privateKey);*/ - $key = '-----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA71FijlOQ4FfKc0VKtjc7Mv6aZmSR9oLjq3uDw/88avOSrIpw -qaTCrwtk2zsFMl1YA3hByhF+TP95E0dDwGWXk1JkLWfZ/sjep+694PtS1oiyvOB8 -hTPYk6U42leHIZDldKk1eu7n0wUph5/5GfahXrHY+8qr38s/QVvG7ohh/dVs3rvs -VJ+QBZz5X9WNYcWIWsEySkyAmtppNVUuf6pwtAkCO4565cNoTk+5zCXpRxsxkgkv -HyTB+Nk4QuXibdC3slscZs75G9tc0TO7sC6lcnZFtTd4z5qk6f6LeI2/asviehc7 -awOl8nm9C3VKjZlgOYIejHhx0A5+lkzFdrk+JwIDAQABAoIBAQDNaZGqkFe9+Byx -LDyggm+xqY9la9VNPbOlMPM8fAuj0UWIC5wAQIdKMAF1mwcu36f38nSluLYr6OxH -e9fPgGPF8+ZAgu8+HbPfeLBKN+42bkbcj+LRglrW/+34m0BFs1T/+W0KA53AJqIq -40iw3FxOJ2ETXjaAdLfqpZfujeluMOW+Rjhe2VpILpWurgX07kWphP09TqK3yuja -At4lBKYFQth7a773uzSy8cy0Ohl+lvRHa/oVS0SXsiLo1iA1NYpXzKi0ww3+sSnw -kfoacFImVuqm2rxikTgSu9GUkC1REoseT5FRj8uHzyBm/wXAM1lniUGr6Moh9Yl2 -a9KNbj8hAoGBAPpHuaWIboumderokBXOwjWcW0EBDx1+SiR3kFHoYvpck9wAe2BM -vdva8IbFomCllq8UUGaW6vXEqVEUITwgGjZBQWeOgSWjo4p0b7o63ftZrsI+/Bl7 -1KJSSR/O45DTXrfD/jxMgTbnYqxbyBCQz54Om9aq338XICsFJkPsU2GzAoGBAPTJ -hkvxxkPOEHmuNjWbxJluFtWfw1Sg5dLMrd6csPB/pczW/TZJwKCJslHH1/SA5PVm -nroSkYgJDMas5caZogvuIO5YIdVIM0SVU0Hl1wYkK4nz2Zpt1YH7peQrjx9iuiGy -UTYpjdxb4nkz6WL8Zp0AIG+5Wxm9IzYKZmpFPO+9AoGACI/fl/wc3AYrzod6NmTG -XBMnRAgHPlkNrEWy2Dp8+Femb0ZM8jRt4lGRHOsx7OB9USv+vCO5kgLSUAXCRU5L -10NQO3yyilkYxSnKkLJm2axtwBNriGumEI+EFOR9AH1apiq8Tc/IM9qik4boRzjN -AXk6d5OM5coivZYFgxlYmOUCgYEA07hqO82GWqckgNo5cOylgr9BaMuiOtRfc5As -4lpMf/coBJ/+qrHntfLjFPDwzD2fytFTgEUHMs4BCuYIZ1oCWqdAPGZl/P9RuIQf -WuPcsycdsVgEYhmVjbOGrG8wf0j5DKQaseoHFQ00OPi5aDA+4JR3eaqsLPr2NYuR -QWFZb1ECgYBYagQ16rdG/aBU0sOd745EskY9F6Z+vpQ7U1J2gA6hdqT3Pl8epSOY -k6aHAHli0D9xC3UQzJSYVIGx6PDR8q5TgADSLyPDwejCArLUpchYrFz3R1FWRs/W -egQQX++y13mrQFJVKA7RCQPWEynD29lwP2oizhGIfEiqGfJZd3pTXQ== ------END RSA PRIVATE KEY-----'; - $certs = []; - openssl_pkcs12_read(file_get_contents(public_path('Certificate.crt')), $certs, '1'); //where 1106@123 is your certificate password - //dd($certs); - - //if (! $certs ) return ; - $signature = ''; - openssl_sign($plainText, $signature, $key); + $payLoad = ['username' => $this->getUsername(), 'password' => $this->getPassword()]; + $this->putPostData('/auth/login', $payLoad, 'POST'); - return base64_encode($signature); } /** @@ -553,70 +573,53 @@ public function getTransactionDetails(string $reference) } /** - * Create bank transfers to for All + * Base function that is responsible for interacting directly with the nium api to obtain data * + * @param array $params * @return array * * @throws Exception */ - public function postCreateTransaction($data) + public function getData($url, $params = []) { - $transactionTypes = ['Bank' => '15', 'Cash Pickup' => '05', 'CBS' => '16', 'Bkash' => '17']; - - $sender_last_name = isset($data->sender_last_name) ? $data->sender_last_name : ''; - - $sender_first_name = isset($data->sender_first_name) ? $data->sender_first_name : ''; + $apiUrl = $this->apiUrl.$url; + $apiUrl .= http_build_query($params); + Log::info($apiUrl); - $full_name = $sender_first_name; - if (strlen($sender_last_name) > 0) { - $full_name .= (' '.$sender_last_name); - } + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $apiUrl); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + $headers = [ + 'cache-control: no-cache', + 'Content-Type: application/json', + 'Accepts: application/json', + 'Username: '.$this->getUsername(), + 'Expassword: '.$this->getPassword(), + ]; + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - $nameArray = preg_split("/\s+(?=\S*+$)/", $full_name); + $response = curl_exec($curl); + $info = curl_getinfo($curl); + $error = curl_error($curl); - if (count($nameArray) > 1) { - $sender_first_name = $nameArray[0]; - $sender_last_name = $nameArray[1]; - } else { - $sender_last_name = $sender_first_name; + if ($response == false) { + Log::info($info); + Log::info($error); + throw new Exception(curl_error($curl), curl_errno($curl)); } - $transferInfo['tranno'] = $data->reference_no; - $transferInfo['traninfosl'] = $data->reference_no; - $transferInfo['trmode'] = isset($data->recipient_type_name) - ? ($transactionTypes[$data->recipient_type_name] ?? '15') - : '15'; - - $transferInfo['purpose'] = $data->emq_purpose_of_remittance ?? null; //TODO agrani code needed - $transferInfo['remamountdest'] = isset($data->transfer_amount) ? round($data->transfer_amount, 2) : '0.00'; - $transferInfo['remfname'] = $sender_first_name; - $transferInfo['remlname'] = $sender_last_name; - $transferInfo['remit_tel'] = isset($data->sender_mobile) ? substr($data->sender_mobile, -11) : null; - $transferInfo['remaddress1'] = trim(($data->sender_address ?? null).' '.($data->sender_city ?? null)); - $transferInfo['remcountry'] = $data->trans_fast_sender_country_iso_code ?? null; //TODO agrani country code needed - $transferInfo['benename'] = $data->receiver_first_name ?? null; - $transferInfo['benemname'] = $data->receiver_middle_name ?? ' '; - $transferInfo['benelname'] = $data->receiver_last_name ?? null; - $transferInfo['beneaccountno'] = $data->bank_account_number ?? null; - $transferInfo['benetel'] = $data->receiver_contact_number ?? null; - $transferInfo['branchcode'] = substr(($data->location_routing_id[1]->bank_branch_location_field_value ?? null), -6); - $transferInfo['beneaddress'] = $data->receiver_address ?? null; - $transferInfo['benecountry'] = $data->trans_fast_receiver_country_iso_code ?? null; - $transferInfo['entereddatetime'] = Carbon::now(config('app.timezone'))->format('Y-m-d\TH:i:s.u'); - $transferInfo['ratevalue'] = 0; - $transferInfo['counttr'] = 0; - $transferInfo['excode'] = $this->getExcode(); - $transferInfo['signaturevalue'] = $this->getTransactionSignature($transferInfo); + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + curl_close($curl); - array_walk($transferInfo, function (&$value, $key) { - $this->transactionBody->appendChild($this->xmlBody->createElement($key, $value)); - }); + Log::info('API Response : '.$response); - $this->xmlBody->appendChild($this->transactionBody); + echo $response; - Log::info($this->xmlBody->saveXML()); + return [ + 'status' => $status, + 'response' => json_decode($response, true), + ]; - //die(); - return $this->putPostData('/MyCash', $transferInfo, 'POST'); } } diff --git a/src/Vendors/CityBankApi.php b/src/Vendors/CityBankApi.php index 5d4d893..b34fb52 100644 --- a/src/Vendors/CityBankApi.php +++ b/src/Vendors/CityBankApi.php @@ -2,10 +2,14 @@ namespace Fintech\Remit\Vendors; +use Exception; use Fintech\Remit\Contracts\BankTransfer; +use Fintech\Remit\Contracts\OrderQuotation; use Illuminate\Support\Facades\Log; +use MongoDB\Laravel\Eloquent\Model; +use SimpleXMLElement; -class CityBankApi implements BankTransfer +class CityBankApi implements BankTransfer, OrderQuotation { /** * CityBank API configuration. @@ -28,7 +32,8 @@ class CityBankApi implements BankTransfer */ public function __construct() { - $this->config = config('city-bank'); + $this->config = config('fintech.remit.providers.citybank'); + if ($this->config['mode'] === 'sandbox') { $this->apiUrl = 'https://'.$this->config[$this->status]['app_host'].'/nrb_api_test/dynamicApi.php?wsdl'; $this->status = 'sandbox'; @@ -40,114 +45,45 @@ public function __construct() } /** - * Do authenticate service will provide you the access token by providing following parameter value + * Get transaction status service will help you to get the transaction status * + * @param $inputs_data + * reference_no like system transaction number * @return mixed * - * @throws \Exception + * @throws Exception */ - private function doAuthenticate() + public function getTnxStatus($inputs_data) { - $return = 'AUTH_FAILED'; - $xml_string = ' - - '.$this->config[$this->status]['username'].' - '.$this->config[$this->status]['password'].' - '.$this->config[$this->status]['exchange_company'].' - - '; - $soapMethod = 'doAuthenticate'; - $response = $this->connectionCheck($xml_string, $soapMethod); - $returnValue = json_decode($response->doAuthenticateResponse->Response, true); - if ($returnValue['message'] == 'Successful') { - $return = $returnValue['token']; - } - return $return; } /** - * Do transfer service will help you to send a new transaction by providing following parameter value + * bKash customer validation service will help you to validate the beneficiary bkash number before send the transaction * + * @param $inputData + * receiver_first_name like receiver name + * bank_account_number like receiver bkash number or wallet number * @return mixed * - * @throws \Exception + * @throws Exception */ - public function doTransfer($inputData) + public function bkashCustomerValidation($inputData) { $doAuthenticate = $this->doAuthenticate(); if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - if ($inputData->bank_id == 17) { - $mode_of_payment = 'CBL Account'; - } else { - $mode_of_payment = 'Other Bank'; - } - if ($inputData->recipient_type_name == 'Cash') { - $mode_of_payment = 'Cash'; - } - if ($inputData->recipient_type_name == 'Cash Pickup') { - $mode_of_payment = 'Cash'; - } $xml_string = ' - + + '.$doAuthenticate.' - '.$inputData->reference_no.' - '.$inputData->sender_first_name.' - '.$inputData->sender_mobile.' - - '.$inputData->sender_id_number.' - '.$inputData->sender_id_issue_country.' - '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' - '; - if ($mode_of_payment != 'Cash') { - $xml_string .= ' - '.$inputData->bank_account_number.' - Savings - '.$inputData->bank_name.' - '.$inputData->bank_branch_name.' - '.(isset($inputData->location_routing_id[1]->bank_branch_location_field_value) ? $inputData->location_routing_id[1]->bank_branch_location_field_value : null).' - '; - } - $xml_string .= ' - '.$inputData->transfer_amount.' - '.$inputData->purpose_of_remittance.' - '.$inputData->receiver_contact_number.' - - - '.$inputData->sender_address.' - '.$inputData->sender_mobile.' - '.$inputData->receiver_address.' - - NA - '.$mode_of_payment.' - '.date('Y-m-d', strtotime($inputData->created_date)).' - - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - + '.$inputData['receiver_first_name'].' + '.$inputData['bank_account_number'].' + '; - $soapMethod = 'doTransfer'; + $soapMethod = 'bkashCustomerValidation'; $response = $this->connectionCheck($xml_string, $soapMethod); if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->doTransferResponse->Response, true); + $returnValue = json_decode($response->bkashCustomerValidationResponse->Response, true); } else { $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; } @@ -159,138 +95,91 @@ public function doTransfer($inputData) } /** - * Get transaction status service will help you to get the transaction status + * Do authenticate service will provide you the access token by providing following parameter value * - * @param $inputs_data - * reference_no like system transaction number * @return mixed * - * @throws \Exception + * @throws Exception */ - public function getTnxStatus($inputs_data) + private function doAuthenticate() { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - - '.$doAuthenticate.' - '.$inputs_data['reference_no'].' - - '; - $soapMethod = 'getTnxStatus'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->getTnxStatusResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + $return = 'AUTH_FAILED'; + $xml_string = ' + + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '.$this->config[$this->status]['exchange_company'].' + + '; + $soapMethod = 'doAuthenticate'; + $response = $this->connectionCheck($xml_string, $soapMethod); + $returnValue = json_decode($response->doAuthenticateResponse->Response, true); + if ($returnValue['message'] == 'Successful') { + $return = $returnValue['token']; } - return $returnValue; + return $return; } /** - * Do amendment or cancel service will help you to send the transaction cancel/amendment request - * - * @param $inputData - * reference_no like system transaction number, amend_query like cancel/amendment - * @return mixed + * @return SimpleXMLElement * - * @throws \Exception + * @throws Exception */ - public function doAmendmentOrCancel($inputData) + private function connectionCheck($xml_post_string, $method) { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - - '.$doAuthenticate.' - '.$inputData['reference_no'].' - '.$inputData['amend_query'].' - - '; - $soapMethod = 'doAmendmentOrCancel'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->doAmendmentOrCancelResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - - return $returnValue; - } + $xml_string = $this->xmlGenerate($xml_post_string, $method); + Log::info($method.'
'.$xml_string); + $headers = [ + 'Host: '.$this->config[$this->status]['app_host'], + 'Content-type: text/xml;charset="utf-8"', + 'Content-length: '.strlen($xml_string), + 'SOAPAction: '.$method, + ]; - /** - * Get balance service will help to know the available balance - * - * @return mixed - * - * @throws \Exception - */ - public function getBalance() - { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - '.$doAuthenticate.' - - '; - $soapMethod = 'getBalance'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->getBalanceResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + // PHP cURL for connection + $ch = curl_init(); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_URL, $this->apiUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_setopt($ch, CURLOPT_TIMEOUT, 0); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_string); // the SOAP request + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + // execution + $response = curl_exec($ch); + Log::error($method.' CURL reported error: '); + if ($response === false) { + throw new Exception(curl_error($ch), curl_errno($ch)); } + curl_close($ch); + $response1 = str_replace('', '', $response); + $response2 = str_replace('', '', $response1); + $response = str_replace('xmlns:ns1="urn:dynamicapi"', '', $response2); + $response = str_replace('ns1:', '', $response); //dd($response); + Log::info($method.'
'.$response); - return $returnValue; + return simplexml_load_string($response); } /** - * bKash customer validation service will help you to validate the beneficiary bkash number before send the transaction - * - * @param $inputData - * receiver_first_name like receiver name - * bank_account_number like receiver bkash number or wallet number - * @return mixed - * - * @throws \Exception + * @return string */ - public function bkashCustomerValidation($inputData) + public function xmlGenerate($string, $method) { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - - '.$doAuthenticate.' - '.$inputData['receiver_first_name'].' - '.$inputData['bank_account_number'].' - - '; - $soapMethod = 'bkashCustomerValidation'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->bkashCustomerValidationResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } + $xml_string = ' + + + + + '.$string.' + + + + '; - return $returnValue; + return $xml_string; } /** @@ -300,7 +189,7 @@ public function bkashCustomerValidation($inputData) * bank_account_number like receiver bkash number or wallet number * @return mixed * - * @throws \Exception + * @throws Exception */ public function bkashValidation($inputData) { @@ -327,70 +216,6 @@ public function bkashValidation($inputData) return $returnValue; } - /** - * Do bKash transfer service will help you to send a bkash transaction - * - * @param $input_data - * @return mixed - * - * @throws \Exception - */ - public function doBkashTransfer($inputData) - { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - - '.$doAuthenticate.' - '.$inputData->transfer_amount.' - '.$inputData->reference_no.' - '.$inputData->sender_first_name.' - '.$inputData->sender_date_of_birth.' - - - '.$inputData->sender_id_number.' - - '.$inputData->sender_address.' - '.$inputData->sender_mobile.' - '.$inputData->sender_id_issue_country.' - '; - if (isset($inputData->wallet_account_actual_name) && $inputData->wallet_account_actual_name != '') { - $xml_string .= ' - '.(isset($inputData->wallet_account_actual_name) ? $inputData->wallet_account_actual_name : null).' - '; - } else { - $xml_string .= ' - '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' - '; - } - $xml_string .= ' - '.(isset($inputData->receiver_city) ? $inputData->receiver_city : 'Dhaka').' - - - - - '.$inputData->purpose_of_remittance.' - '.$inputData->bank_account_number.' - - '.$inputData->receiver_address.' - '.date('Y-m-d', strtotime($inputData->created_date)).' - - '; - $soapMethod = 'doBkashTransfer'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->doBkashTransferResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - - return $returnValue; - } - /** * This service call will provide you the bkash transaction status. * @@ -398,7 +223,7 @@ public function doBkashTransfer($inputData) * reference_no like system transaction number * @return mixed * - * @throws \Exception + * @throws Exception */ public function getBkashTnxStatus($inputData) { @@ -420,76 +245,15 @@ public function getBkashTnxStatus($inputData) } } else { $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - - return $returnValue; - } - - /** - * @return \SimpleXMLElement - * - * @throws \Exception - */ - public function connectionCheck($xml_post_string, $method) - { - $xml_string = $this->xmlGenerate($xml_post_string, $method); - Log::info($method.'
'.$xml_string); - $headers = [ - 'Host: '.$this->config[$this->status]['app_host'], - 'Content-type: text/xml;charset="utf-8"', - 'Content-length: '.strlen($xml_string), - 'SOAPAction: '.$method, - ]; - - // PHP cURL for connection - $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($ch, CURLOPT_URL, $this->apiUrl); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_TIMEOUT, 0); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_string); // the SOAP request - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - // execution - $response = curl_exec($ch); - Log::error($method.' CURL reported error: '); - if ($response === false) { - throw new \Exception(curl_error($ch), curl_errno($ch)); - } - curl_close($ch); - $response1 = str_replace('', '', $response); - $response2 = str_replace('', '', $response1); - $response = str_replace('xmlns:ns1="urn:dynamicapi"', '', $response2); - $response = str_replace('ns1:', '', $response); //dd($response); - Log::info($method.'
'.$response); - - return simplexml_load_string($response); - } - - /** - * @return string - */ - public function xmlGenerate($string, $method) - { - $xml_string = ' - - - - - '.$string.' - - - - '; + } - return $xml_string; + return $returnValue; } /** * @return object * - * @throws \Exception + * @throws Exception */ public function topUp($input) { @@ -505,50 +269,59 @@ public function topUp($input) } /** - * @return object - * - * @throws \Exception - */ - public function queryTnxStatus($input) - { - if ($input['service_id'] == 15) { - $returnValue = $this->getBkashTnxStatus($input); - } elseif ($input['service_id'] == 36) { - $returnValue = $this->getNagadTnxStatus($input); - } else { - $returnValue = $this->getTnxStatus($input); - } - - return $returnValue; - } - - /** - * nagad customer validation service will help you to validate the beneficiary nagad number before send the transaction + * Do bKash transfer service will help you to send a bkash transaction * - * @param $inputData - * receiver_first_name like receiver name - * bank_account_number like receiver nagad number or wallet number + * @param $input_data * @return mixed * - * @throws \Exception + * @throws Exception */ - public function nagadCustomerValidation($inputData) + public function doBkashTransfer($inputData) { $doAuthenticate = $this->doAuthenticate(); if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { $xml_string = ' - - + + '.$doAuthenticate.' - 50 - '.$inputData['bank_account_number'].' - N - + '.$inputData->transfer_amount.' + '.$inputData->reference_no.' + '.$inputData->sender_first_name.' + '.$inputData->sender_date_of_birth.' + + + '.$inputData->sender_id_number.' + + '.$inputData->sender_address.' + '.$inputData->sender_mobile.' + '.$inputData->sender_id_issue_country.' '; - $soapMethod = 'nagadCustomerValidation'; + if (isset($inputData->wallet_account_actual_name) && $inputData->wallet_account_actual_name != '') { + $xml_string .= ' + '.(isset($inputData->wallet_account_actual_name) ? $inputData->wallet_account_actual_name : null).' + '; + } else { + $xml_string .= ' + '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' + '; + } + $xml_string .= ' + '.(isset($inputData->receiver_city) ? $inputData->receiver_city : 'Dhaka').' + + + + + '.$inputData->purpose_of_remittance.' + '.$inputData->bank_account_number.' + + '.$inputData->receiver_address.' + '.date('Y-m-d', strtotime($inputData->created_date)).' + + '; + $soapMethod = 'doBkashTransfer'; $response = $this->connectionCheck($xml_string, $soapMethod); if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->nagadCustomerValidationResponse->Response, true); + $returnValue = json_decode($response->doBkashTransferResponse->Response, true); } else { $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; } @@ -565,7 +338,7 @@ public function nagadCustomerValidation($inputData) * @param $input_data * @return mixed * - * @throws \Exception + * @throws Exception */ public function doNagadTransfer($inputData) { @@ -624,6 +397,43 @@ public function doNagadTransfer($inputData) return $returnValue; } + /** + * nagad customer validation service will help you to validate the beneficiary nagad number before send the transaction + * + * @param $inputData + * receiver_first_name like receiver name + * bank_account_number like receiver nagad number or wallet number + * @return mixed + * + * @throws Exception + */ + public function nagadCustomerValidation($inputData) + { + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + + '.$doAuthenticate.' + 50 + '.$inputData['bank_account_number'].' + N + + '; + $soapMethod = 'nagadCustomerValidation'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->nagadCustomerValidationResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; + } + /** * This service call will provide you the nagad transaction status. * @@ -631,7 +441,7 @@ public function doNagadTransfer($inputData) * txnNo like system transaction number * @return mixed * - * @throws \Exception + * @throws Exception */ public function getNagadTnxStatus($inputData) { @@ -661,28 +471,183 @@ public function getNagadTnxStatus($inputData) /** * Execute the transfer operation */ - public function makeTransfer(array $orderInfo): mixed + public function makeTransfer(array $orderInfo = []): mixed { - // TODO: Implement makeTransfer() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + if ($inputData->bank_id == 17) { + $mode_of_payment = 'CBL Account'; + } else { + $mode_of_payment = 'Other Bank'; + } + if ($inputData->recipient_type_name == 'Cash') { + $mode_of_payment = 'Cash'; + } + if ($inputData->recipient_type_name == 'Cash Pickup') { + $mode_of_payment = 'Cash'; + } + $xml_string = ' + + '.$doAuthenticate.' + '.$inputData->reference_no.' + '.$inputData->sender_first_name.' + '.$inputData->sender_mobile.' + + '.$inputData->sender_id_number.' + '.$inputData->sender_id_issue_country.' + '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' + '; + if ($mode_of_payment != 'Cash') { + $xml_string .= ' + '.$inputData->bank_account_number.' + Savings + '.$inputData->bank_name.' + '.$inputData->bank_branch_name.' + '.(isset($inputData->location_routing_id[1]->bank_branch_location_field_value) ? $inputData->location_routing_id[1]->bank_branch_location_field_value : null).' + '; + } + $xml_string .= ' + '.$inputData->transfer_amount.' + '.$inputData->purpose_of_remittance.' + '.$inputData->receiver_contact_number.' + + + '.$inputData->sender_address.' + '.$inputData->sender_mobile.' + '.$inputData->receiver_address.' + + NA + '.$mode_of_payment.' + '.date('Y-m-d', strtotime($inputData->created_date)).' + + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + + '; + $soapMethod = 'doTransfer'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->doTransferResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } - public function transferStatus(array $orderInfo): mixed + public function transferStatus(array $orderInfo = []): mixed { - // TODO: Implement transferStatus() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + + '.$doAuthenticate.' + '.$inputs_data['reference_no'].' + + '; + $soapMethod = 'getTnxStatus'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->getTnxStatusResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } - public function cancelTransfer(array $orderInfo): mixed + /** + * Do amendment or cancel service will help you to send the transaction cancel/amendment request + * reference_no like system transaction number, amend_query like cancel/amendment + * + * @throws Exception + */ + public function cancelTransfer(array $orderInfo = []): mixed { - // TODO: Implement cancelTransfer() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + + '.$doAuthenticate.' + '.$inputData['reference_no'].' + '.$inputData['amend_query'].' + + '; + $soapMethod = 'doAmendmentOrCancel'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->doAmendmentOrCancelResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } - public function verifyAccount(array $accountInfo): mixed + public function verifyAccount(array $accountInfo = []): mixed { // TODO: Implement verifyAccount() method. } - public function vendorBalance(array $accountInfo): mixed + /** + * @param \Illuminate\Database\Eloquent\Model|Model $order + * + * @throws Exception + */ + public function requestQuotation($order): mixed + { + return $this->vendorBalance(); + } + + public function vendorBalance(array $accountInfo = []): mixed { - // TODO: Implement vendorBalance() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + '.$doAuthenticate.' + + '; + $soapMethod = 'getBalance'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->getBalanceResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } } diff --git a/src/Vendors/EmqApi.php b/src/Vendors/EmqApi.php index 142279a..4d7085e 100644 --- a/src/Vendors/EmqApi.php +++ b/src/Vendors/EmqApi.php @@ -8,10 +8,14 @@ use App\Services\Backend\Setting\CountryService; use Carbon\Carbon; use Exception; +use Fintech\Remit\Contracts\BankTransfer; +use Fintech\Remit\Contracts\OrderQuotation; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; +use MongoDB\Laravel\Eloquent\Model; +use stdClass; -class EmqApi +class EmqApi implements BankTransfer, OrderQuotation { const OCCUPATION = 'OCC'; @@ -79,16 +83,27 @@ public function __construct(CatalogListService $catalogListService, $this->countryService = $countryService; } + /** + * Encode Auth info to base64 and store on $basicAuthHash + * + * @return void + */ + protected function encodeCredential() + { + $asciString = mb_convert_encoding($this->config[$this->status]['username'].':'.$this->config[$this->status]['password'], 'ASCII'); + $this->basicAuthHash = base64_encode($asciString); + } + /** * EMQ Transfer TopUp * - * @return \stdClass + * @return stdClass * * @throws Exception */ public function topUp($data) { - $returnData = new \stdClass(); + $returnData = new stdClass(); $reference = $data->reference_no; @@ -164,14 +179,258 @@ public function topUp($data) return $returnData; } + /** + * Create bank transfers to for All + * + * @return array + * + * @throws Exception + */ + public function postCreateTransaction($data) + { + $reference = $data->reference_no; + + $transactionTypes = ['Bank' => 'bank_account', 'Cash Pickup' => 'cash_pickup', 'Cash' => 'cash_pickup', 'Wallet' => 'ewallet']; + + $sender_last_name = isset($data->sender_last_name) ? $data->sender_last_name : ''; + $sender_first_name = isset($data->sender_first_name) ? $data->sender_first_name : ''; + + $full_name = $sender_first_name; + if (strlen($sender_last_name) > 0) { + $full_name .= (' '.$sender_last_name); + } + + $nameArray = preg_split("/\s+(?=\S*+$)/", $full_name); + + if (count($nameArray) > 1) { + $sender_first_name = $nameArray[0]; + $sender_last_name = $nameArray[1]; + } else { + $sender_last_name = $sender_first_name; + } + + $transferInfo['destination_amount']['currency'] = isset($data->transfer_currency) ? $data->transfer_currency : null; + $transferInfo['destination_amount']['units'] = isset($data->transfer_amount) ? (string) round($data->transfer_amount, 2) : null; //TODO with charge or without charge + //TODO FOR PHL + $transferInfo['destination']['country'] = isset($data->emq_receiver_country_iso_code) ? $data->emq_receiver_country_iso_code : null; + if (in_array($transferInfo['destination']['country'], ['PHL', 'IDN'])) { + $transferInfo['destination_amount']['units'] = isset($data->transfer_amount) ? (string) floor($data->transfer_amount) : null; //TODO with charge or without charge + } + + //$transferInfo["source_amount"]["currency"] = isset($data->sender_currency) ? $data->sender_currency : null; + //$transferInfo["source_amount"]["units"] = isset($data->sender_amount) ? (string)round($data->sender_amount) : null; //TODO with charge or without charge + + $transferInfo['compliance']['source_of_funds'] = isset($data->emq_sender_source_of_fund_id) ? (string) $data->emq_sender_source_of_fund_id : null; + $transferInfo['compliance']['remittance_purpose'] = isset($data->emq_purpose_of_remittance) ? $data->emq_purpose_of_remittance : null; + + $transferInfo['compliance']['relationship']['code'] = isset($data->emq_sender_beneficiary_relationship_code) ? $data->emq_sender_beneficiary_relationship_code : null; + if ($transferInfo['compliance']['relationship']['code'] == '99' || $transferInfo['compliance']['relationship']['code'] == null) { + $transferInfo['compliance']['relationship']['code'] = '99'; + $transferInfo['compliance']['relationship']['relation'] = isset($data->sender_beneficiary_relationship) ? ucwords(strtolower($data->sender_beneficiary_relationship)) : 'Others'; + } + + //Source + $transferInfo['source']['type'] = 'partner'; + $transferInfo['source']['gender'] = isset($data->sender_gender) ? strtoupper(substr($data->sender_gender, 0, 1)) : 'M'; + $transferInfo['source']['country'] = isset($data->emq_sender_country_iso3_code) ? $data->emq_sender_country_iso3_code : null; + + $transferInfo['source']['segment'] = isset($data->emq_sender_segment) ? $data->emq_sender_segment : 'individual'; + $transferInfo['source']['legal_name_first'] = $sender_first_name; + $transferInfo['source']['legal_name_last'] = $sender_last_name; + + $transferInfo['source']['mobile_number'] = isset($data->sender_mobile) ? ('+'.$data->sender_mobile) : null; + + $transferInfo['source']['date_of_birth'] = isset($data->sender_date_of_birth) ? Carbon::parse($data->sender_date_of_birth)->format('Y-m-d') : null; + + $transferInfo['source']['nationality'] = isset($data->emq_sender_nationality) ? $data->emq_sender_nationality : null; + + //$transferInfo['source']["id_type"] = isset($data->emq_sender_id_type) ? strtolower($data->emq_sender_id_type) : null; + $transferInfo['source']['id_type'] = 'passport'; //national + $transferInfo['source']['id_country'] = isset($data->emq_sender_id_issue_country) ? $data->emq_sender_id_issue_country : null; + $transferInfo['source']['id_number'] = isset($data->sender_id_number) ? $data->sender_id_number : null; + $transferInfo['source']['id_expiration'] = isset($data->sender_expire_date) ? Carbon::parse($data->sender_expire_date)->format('Y-m-d') : null; + + $transferInfo['source']['address_city'] = isset($data->sender_city) ? $data->sender_city : null; + $transferInfo['source']['address_line'] = isset($data->sender_address) ? $data->sender_address : null; + $transferInfo['source']['address_zip'] = isset($data->sender_zipcode) ? $data->sender_zipcode : null; + $transferInfo['source']['address_country'] = isset($data->emq_sender_country_iso3_code) ? $data->emq_sender_country_iso3_code : null; + + //Destination + $transferInfo['destination']['type'] = isset($data->recipient_type_name) + ? (isset($transactionTypes[$data->recipient_type_name]) + ? $transactionTypes[$data->recipient_type_name] : 'bank_account') + : null; + $transferInfo['destination']['country'] = isset($data->emq_receiver_country_iso_code) ? $data->emq_receiver_country_iso_code : null; + $transferInfo['destination']['legal_name_first'] = isset($data->receiver_first_name) ? $data->receiver_first_name : null; + $transferInfo['destination']['legal_name_last'] = isset($data->receiver_last_name) ? $data->receiver_last_name : null; + $transferInfo['destination']['mobile_number'] = isset($data->receiver_contact_number) ? ('+'.$data->receiver_contact_number) : null; + + $transferInfo['destination']['address_line'] = isset($data->receiver_address) ? $data->receiver_address : null; + $transferInfo['destination']['address_city'] = isset($data->receiver_city) ? $data->receiver_city : null; + + //type bank account + if ($transferInfo['destination']['type'] === 'bank_account') { + + if ($transferInfo['destination']['country'] !== 'CHN') { + $transferInfo['destination']['bank'] = isset($data->emq_bank_id) ? $data->emq_bank_id : null; + } + //remove china bank address info + if ($transferInfo['destination']['country'] == 'CHN') { + unset($transferInfo['destination']['address_line']); + unset($transferInfo['destination']['address_city']); + } + + //remove malaysia bank address info + if ($transferInfo['destination']['country'] == 'MYS') { + unset($transferInfo['destination']['mobile_number']); + unset($transferInfo['destination']['address_city']); + } + + //indonesia + if ($transferInfo['destination']['country'] == 'IDN') { + $transferInfo['destination']['address_state'] = isset($data->receiver_province) ? $data->receiver_province : 'Jawa Barat'; + $transferInfo['destination']['address_state_code'] = isset($data->emq_receiver_province_code) ? $data->emq_receiver_province_code : '01'; + $transferInfo['destination']['address_city'] = isset($data->emq_receiver_city) ? $data->emq_receiver_city : 'BANDUNG'; + $transferInfo['destination']['address_city_code'] = isset($data->emq_receiver_city_code) ? $data->emq_receiver_city_code : '0191'; + $transferInfo['destination']['id_number'] = isset($data->receiver_id_number) ? $data->receiver_id_number : null; + } + + $transferInfo['destination']['account_number'] = isset($data->bank_account_number) ? $data->bank_account_number : null; + //branch + if ($transferInfo['destination']['country'] === 'IND') { //India //99 + //$transferInfo["destination"]["branch"] = isset($data->emq_bank_branch_id) ? $data->emq_bank_branch_id : null; + //$transferInfo["destination"]["branch"] = str_replace((isset($data->emq_bank_id) ? $data->emq_bank_id : null), '', (isset($data->location_routing_id[1]->bank_branch_location_field_value) ? $data->location_routing_id[1]->bank_branch_location_field_value : null)); + $transferInfo['destination']['branch'] = substr((isset($data->location_routing_id[1]->bank_branch_location_field_value) ? $data->location_routing_id[1]->bank_branch_location_field_value : null), -6); + + } elseif ($transferInfo['destination']['country'] === 'JPN') { + $transferInfo['destination']['branch'] = isset($data->emq_bank_branch_id) ? $data->emq_bank_branch_id : null; + } + + //swift //SPEA Country TODO Feature Work + /*if ($transferInfo["destination"]["country"] === '') : + $transferInfo["destination"]["swift_code"] = isset($data->emq_bank_swift_code) ? $data->emq_bank_swift_code : null; + $transferInfo["destination"]["iban"] = isset($data->emq_bank_iban_code) ? $data->emq_bank_iban_code : null; + endif;*/ + } + + //type ewallet + if ($transferInfo['destination']['type'] === 'ewallet') { + if (in_array($transferInfo['destination']['country'], $this->config['ewallet_allow_country'])) { + $transferInfo['destination']['segment'] = isset($data->emq_sender_segment) ? $data->emq_sender_segment : 'individual'; + + if ($transferInfo['destination']['country'] === 'PHL') { + $transferInfo['destination']['ewallet_id'] = isset($data->bank_account_number) + ? preg_replace('/^(63)(.+)/u', '$2', $data->bank_account_number, 1) + : null; + } else { + $transferInfo['destination']['ewallet_id'] = isset($data->bank_account_number) ? $data->bank_account_number : null; + } + + if (count($this->config['partners'][$transferInfo['destination']['country']]['ewallet']) > 0) { + $transferInfo['destination']['partner'] = isset($data->emq_ewallet_partner) + ? $data->emq_ewallet_partner + : $this->config['partners'][$transferInfo['destination']['country']]['ewallet'][0]; + } + } + } + + //type cash_pickup + if ($transferInfo['destination']['type'] === 'cash_pickup') { + $transferInfo['destination']['partner'] = isset($data->emq_cash_pickup_partner) ? $data->emq_cash_pickup_partner : null; + } + + /* //verify recipient + $recipientConfirm = $this->verifyRecipient($transferInfo["destination"]); + + if ($recipientConfirm['status'] === 200 && $recipientConfirm['response']['result'] === 'ok') {*/ + + $returnData = $this->putPostData("/transfers/{$reference}", $transferInfo, 'PUT'); + + /* } else { + $returnData = $recipientConfirm; + }*/ + + return $returnData; + } + + /** + * Base function that is responsible for interacting directly with the nium api to send data + * + * @return array + * + * @throws Exception + */ + public function putPostData(string $url, array $dataArray, string $method = 'POST') + { + $apiUrl = $this->apiUrl.$url; + Log::info($apiUrl); + $jsonArray = json_encode($dataArray); + Log::info(json_decode($jsonArray, true)); + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $apiUrl); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($curl, CURLOPT_POST, count($dataArray)); + curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonArray); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_VERBOSE, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, [ + 'cache-control: no-cache', + 'Content-Type: application/json', + 'Accepts: application/json', + 'Authorization: Basic '.$this->getBasicAuthHash(), + ] + ); + + $response = curl_exec($curl); + $info = curl_getinfo($curl); + $error = curl_error($curl); + + if ($response == false) { + Log::info($info); + Log::info($error); + throw new Exception(curl_error($curl), curl_errno($curl)); + } + + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + curl_close($curl); + + Log::info(json_decode($response, true)); + + return [ + 'status' => $status, + 'response' => json_decode($response, true), + ]; + } + + /** + * Return encode auth header value + * + * @return string|null + */ + public function getBasicAuthHash() + { + return $this->basicAuthHash; + } + + /** + * @return array + * + * @throws Exception + */ + public function postTransactionConfirm(string $reference) + { + return $this->putPostData("/transfers/{$reference}/confirm", [], 'POST'); + } + /** * Render Emq Response to pointed StdClass * * @param array $response emq response - * @param \stdClass $returnData class that will get rendered response + * @param stdClass $returnData class that will get rendered response * @return void */ - public function renderApiResponse(array $response, \stdClass &$returnData) + public function renderApiResponse(array $response, stdClass &$returnData) { $returnData->init_time = isset($response['created']) ? $response['created'] : date('Y-m-d H:i:s P'); $returnData->recharge_time = isset($response['created']) ? $response['created'] : date('Y-m-d H:i:s P'); @@ -338,17 +597,6 @@ public function customErrorMessage(array $fields, string $message) } } - /** - * Encode Auth info to base64 and store on $basicAuthHash - * - * @return void - */ - protected function encodeCredential() - { - $asciString = mb_convert_encoding($this->config[$this->status]['username'].':'.$this->config[$this->status]['password'], 'ASCII'); - $this->basicAuthHash = base64_encode($asciString); - } - /** * Convert Country full into ISO 3 value * @@ -372,109 +620,49 @@ public function getCatalogeEmqCodeFromName(string $catalog, string $type) { $catalogModel = $this->catalogListService->ShowAllCatalogList([ 'catalog_data_wild_card' => $catalog, - 'catalog_type' => $type, - 'emq_code_not_null' => true])->get()->first(); - - return ($catalogModel instanceof CatalogList) ? $catalogModel->emq_code : null; - } - - /** - * Login and obtain session token. - * - * @param string username - * @param string password - * - * @throws Exception - */ - public function postLogin() - { - $payLoad = ['username' => $this->getUsername(), 'password' => $this->getPassword()]; - $this->putPostData('/auth/login', $payLoad, 'POST'); - - } - - /** - * Return Username from config - * - * @return string - */ - public function getUsername() - { - return $this->config[$this->status]['username']; - } - - /** - * Return Password from config - * - * @return string - */ - public function getPassword() - { - return $this->config[$this->status]['password']; - } - - /** - * Base function that is responsible for interacting directly with the nium api to send data - * - * @return array - * - * @throws Exception - */ - public function putPostData(string $url, array $dataArray, string $method = 'POST') - { - $apiUrl = $this->apiUrl.$url; - Log::info($apiUrl); - $jsonArray = json_encode($dataArray); - Log::info(json_decode($jsonArray, true)); - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $apiUrl); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); - curl_setopt($curl, CURLOPT_POST, count($dataArray)); - curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonArray); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_VERBOSE, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, [ - 'cache-control: no-cache', - 'Content-Type: application/json', - 'Accepts: application/json', - 'Authorization: Basic '.$this->getBasicAuthHash(), - ] - ); - - $response = curl_exec($curl); - $info = curl_getinfo($curl); - $error = curl_error($curl); - - if ($response == false) { - Log::info($info); - Log::info($error); - throw new Exception(curl_error($curl), curl_errno($curl)); - } - - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - curl_close($curl); - - Log::info(json_decode($response, true)); + 'catalog_type' => $type, + 'emq_code_not_null' => true])->get()->first(); - return [ - 'status' => $status, - 'response' => json_decode($response, true), - ]; + return ($catalogModel instanceof CatalogList) ? $catalogModel->emq_code : null; } /** - * Return encode auth header value + * Login and obtain session token. * - * @return string|null + * @param string username + * @param string password + * + * @throws Exception */ - public function getBasicAuthHash() + public function postLogin() { - return $this->basicAuthHash; + $payLoad = ['username' => $this->getUsername(), 'password' => $this->getPassword()]; + $this->putPostData('/auth/login', $payLoad, 'POST'); + } /******************************************* Support *******************************************/ + /** + * Return Username from config + * + * @return string + */ + public function getUsername() + { + return $this->config[$this->status]['username']; + } + + /** + * Return Password from config + * + * @return string + */ + public function getPassword() + { + return $this->config[$this->status]['password']; + } + /** * Retrieve a quote of current rate. * @@ -548,6 +736,7 @@ public function getData($url, $params = []) ]; } + /******************************************* Auth *******************************************/ /** * Retrieve current balances @@ -576,11 +765,7 @@ public function getAllBalance(?string $currency = null) } } - protected function getBalanceFromCurrency(string $currency, $response) - { - - } - /******************************************* Auth *******************************************/ + /******************************************* Quota *******************************************/ /** * Retrieve a daily statement for a given day. @@ -596,7 +781,7 @@ public function getDailyStatement(string $date) } - /******************************************* Quota *******************************************/ + /******************************************* Balance *******************************************/ /** * Retrieve a monthly statement up to a given day. @@ -612,7 +797,7 @@ public function getMonthlyStatement(string $date) } - /******************************************* Balance *******************************************/ + /******************************************* Report *******************************************/ /** * Retrieve the settlement report for a given date and a given destination country @@ -629,8 +814,6 @@ public function getDailySettlement(array $param) } - /******************************************* Report *******************************************/ - /** * List or search senders * @@ -667,6 +850,8 @@ public function createSender(array $data) } + /******************************************* Sender *******************************************/ + /** * Retrieve a sender * @@ -680,8 +865,6 @@ public function getSenderDetails(string $senderId) } - /******************************************* Sender *******************************************/ - /** * Update a sender * @@ -735,6 +918,8 @@ public function createRecipient(string $senderId, array $data) } + /******************************************* Recipient *******************************************/ + /** * Retrieve a recipient. * @@ -748,8 +933,6 @@ public function getRecipientDetails(string $senderId, string $recipientId) } - /******************************************* Recipient *******************************************/ - /** * Update a recipient. * @@ -825,6 +1008,8 @@ public function getAllCountries() } + /******************************************* Static Data *******************************************/ + /** * List currencies * Retrieve list of currencies to be used in creating transfer @@ -837,8 +1022,6 @@ public function getAllCurrencies() } - /******************************************* Static Data *******************************************/ - /** * List occupations * Retrieve list of occupations @@ -1091,6 +1274,8 @@ public function getAllDestinationByCountry(?string $country = null) } + /*********************************** Transaction ***************************************/ + /** * List transfers, oldest first. * @@ -1105,8 +1290,6 @@ public function getAllTransactions(array $data = []) } - /*********************************** Transaction ***************************************/ - /** * @param array $reference MCM6196575170666 * @return array|mixed @@ -1128,16 +1311,6 @@ public function getTransactionDetails(string $reference) } - /** - * @return array - * - * @throws Exception - */ - public function postTransactionConfirm(string $reference) - { - return $this->putPostData("/transfers/{$reference}/confirm", [], 'POST'); - } - /** * @return array * @@ -1149,176 +1322,43 @@ public function postTransactionCancel(string $reference) } /** - * Create bank transfers to for All - * - * @return array - * - * @throws Exception + * Execute the transfer operation */ - public function postCreateTransaction($data) + public function makeTransfer(array $orderInfo = []): mixed { - $reference = $data->reference_no; - - $transactionTypes = ['Bank' => 'bank_account', 'Cash Pickup' => 'cash_pickup', 'Cash' => 'cash_pickup', 'Wallet' => 'ewallet']; - - $sender_last_name = isset($data->sender_last_name) ? $data->sender_last_name : ''; - $sender_first_name = isset($data->sender_first_name) ? $data->sender_first_name : ''; - - $full_name = $sender_first_name; - if (strlen($sender_last_name) > 0) { - $full_name .= (' '.$sender_last_name); - } - - $nameArray = preg_split("/\s+(?=\S*+$)/", $full_name); - - if (count($nameArray) > 1) { - $sender_first_name = $nameArray[0]; - $sender_last_name = $nameArray[1]; - } else { - $sender_last_name = $sender_first_name; - } - - $transferInfo['destination_amount']['currency'] = isset($data->transfer_currency) ? $data->transfer_currency : null; - $transferInfo['destination_amount']['units'] = isset($data->transfer_amount) ? (string) round($data->transfer_amount, 2) : null; //TODO with charge or without charge - //TODO FOR PHL - $transferInfo['destination']['country'] = isset($data->emq_receiver_country_iso_code) ? $data->emq_receiver_country_iso_code : null; - if (in_array($transferInfo['destination']['country'], ['PHL', 'IDN'])) { - $transferInfo['destination_amount']['units'] = isset($data->transfer_amount) ? (string) floor($data->transfer_amount) : null; //TODO with charge or without charge - } - - //$transferInfo["source_amount"]["currency"] = isset($data->sender_currency) ? $data->sender_currency : null; - //$transferInfo["source_amount"]["units"] = isset($data->sender_amount) ? (string)round($data->sender_amount) : null; //TODO with charge or without charge - - $transferInfo['compliance']['source_of_funds'] = isset($data->emq_sender_source_of_fund_id) ? (string) $data->emq_sender_source_of_fund_id : null; - $transferInfo['compliance']['remittance_purpose'] = isset($data->emq_purpose_of_remittance) ? $data->emq_purpose_of_remittance : null; - - $transferInfo['compliance']['relationship']['code'] = isset($data->emq_sender_beneficiary_relationship_code) ? $data->emq_sender_beneficiary_relationship_code : null; - if ($transferInfo['compliance']['relationship']['code'] == '99' || $transferInfo['compliance']['relationship']['code'] == null) { - $transferInfo['compliance']['relationship']['code'] = '99'; - $transferInfo['compliance']['relationship']['relation'] = isset($data->sender_beneficiary_relationship) ? ucwords(strtolower($data->sender_beneficiary_relationship)) : 'Others'; - } - - //Source - $transferInfo['source']['type'] = 'partner'; - $transferInfo['source']['gender'] = isset($data->sender_gender) ? strtoupper(substr($data->sender_gender, 0, 1)) : 'M'; - $transferInfo['source']['country'] = isset($data->emq_sender_country_iso3_code) ? $data->emq_sender_country_iso3_code : null; - - $transferInfo['source']['segment'] = isset($data->emq_sender_segment) ? $data->emq_sender_segment : 'individual'; - $transferInfo['source']['legal_name_first'] = $sender_first_name; - $transferInfo['source']['legal_name_last'] = $sender_last_name; - - $transferInfo['source']['mobile_number'] = isset($data->sender_mobile) ? ('+'.$data->sender_mobile) : null; - - $transferInfo['source']['date_of_birth'] = isset($data->sender_date_of_birth) ? Carbon::parse($data->sender_date_of_birth)->format('Y-m-d') : null; - - $transferInfo['source']['nationality'] = isset($data->emq_sender_nationality) ? $data->emq_sender_nationality : null; - - //$transferInfo['source']["id_type"] = isset($data->emq_sender_id_type) ? strtolower($data->emq_sender_id_type) : null; - $transferInfo['source']['id_type'] = 'passport'; //national - $transferInfo['source']['id_country'] = isset($data->emq_sender_id_issue_country) ? $data->emq_sender_id_issue_country : null; - $transferInfo['source']['id_number'] = isset($data->sender_id_number) ? $data->sender_id_number : null; - $transferInfo['source']['id_expiration'] = isset($data->sender_expire_date) ? Carbon::parse($data->sender_expire_date)->format('Y-m-d') : null; - - $transferInfo['source']['address_city'] = isset($data->sender_city) ? $data->sender_city : null; - $transferInfo['source']['address_line'] = isset($data->sender_address) ? $data->sender_address : null; - $transferInfo['source']['address_zip'] = isset($data->sender_zipcode) ? $data->sender_zipcode : null; - $transferInfo['source']['address_country'] = isset($data->emq_sender_country_iso3_code) ? $data->emq_sender_country_iso3_code : null; - - //Destination - $transferInfo['destination']['type'] = isset($data->recipient_type_name) - ? (isset($transactionTypes[$data->recipient_type_name]) - ? $transactionTypes[$data->recipient_type_name] : 'bank_account') - : null; - $transferInfo['destination']['country'] = isset($data->emq_receiver_country_iso_code) ? $data->emq_receiver_country_iso_code : null; - $transferInfo['destination']['legal_name_first'] = isset($data->receiver_first_name) ? $data->receiver_first_name : null; - $transferInfo['destination']['legal_name_last'] = isset($data->receiver_last_name) ? $data->receiver_last_name : null; - $transferInfo['destination']['mobile_number'] = isset($data->receiver_contact_number) ? ('+'.$data->receiver_contact_number) : null; - - $transferInfo['destination']['address_line'] = isset($data->receiver_address) ? $data->receiver_address : null; - $transferInfo['destination']['address_city'] = isset($data->receiver_city) ? $data->receiver_city : null; - - //type bank account - if ($transferInfo['destination']['type'] === 'bank_account') { - - if ($transferInfo['destination']['country'] !== 'CHN') { - $transferInfo['destination']['bank'] = isset($data->emq_bank_id) ? $data->emq_bank_id : null; - } - //remove china bank address info - if ($transferInfo['destination']['country'] == 'CHN') { - unset($transferInfo['destination']['address_line']); - unset($transferInfo['destination']['address_city']); - } - - //remove malaysia bank address info - if ($transferInfo['destination']['country'] == 'MYS') { - unset($transferInfo['destination']['mobile_number']); - unset($transferInfo['destination']['address_city']); - } - - //indonesia - if ($transferInfo['destination']['country'] == 'IDN') { - $transferInfo['destination']['address_state'] = isset($data->receiver_province) ? $data->receiver_province : 'Jawa Barat'; - $transferInfo['destination']['address_state_code'] = isset($data->emq_receiver_province_code) ? $data->emq_receiver_province_code : '01'; - $transferInfo['destination']['address_city'] = isset($data->emq_receiver_city) ? $data->emq_receiver_city : 'BANDUNG'; - $transferInfo['destination']['address_city_code'] = isset($data->emq_receiver_city_code) ? $data->emq_receiver_city_code : '0191'; - $transferInfo['destination']['id_number'] = isset($data->receiver_id_number) ? $data->receiver_id_number : null; - } - - $transferInfo['destination']['account_number'] = isset($data->bank_account_number) ? $data->bank_account_number : null; - //branch - if ($transferInfo['destination']['country'] === 'IND') { //India //99 - //$transferInfo["destination"]["branch"] = isset($data->emq_bank_branch_id) ? $data->emq_bank_branch_id : null; - //$transferInfo["destination"]["branch"] = str_replace((isset($data->emq_bank_id) ? $data->emq_bank_id : null), '', (isset($data->location_routing_id[1]->bank_branch_location_field_value) ? $data->location_routing_id[1]->bank_branch_location_field_value : null)); - $transferInfo['destination']['branch'] = substr((isset($data->location_routing_id[1]->bank_branch_location_field_value) ? $data->location_routing_id[1]->bank_branch_location_field_value : null), -6); - - } elseif ($transferInfo['destination']['country'] === 'JPN') { - $transferInfo['destination']['branch'] = isset($data->emq_bank_branch_id) ? $data->emq_bank_branch_id : null; - } - - //swift //SPEA Country TODO Feature Work - /*if ($transferInfo["destination"]["country"] === '') : - $transferInfo["destination"]["swift_code"] = isset($data->emq_bank_swift_code) ? $data->emq_bank_swift_code : null; - $transferInfo["destination"]["iban"] = isset($data->emq_bank_iban_code) ? $data->emq_bank_iban_code : null; - endif;*/ - } - - //type ewallet - if ($transferInfo['destination']['type'] === 'ewallet') { - if (in_array($transferInfo['destination']['country'], $this->config['ewallet_allow_country'])) { - $transferInfo['destination']['segment'] = isset($data->emq_sender_segment) ? $data->emq_sender_segment : 'individual'; - - if ($transferInfo['destination']['country'] === 'PHL') { - $transferInfo['destination']['ewallet_id'] = isset($data->bank_account_number) - ? preg_replace('/^(63)(.+)/u', '$2', $data->bank_account_number, 1) - : null; - } else { - $transferInfo['destination']['ewallet_id'] = isset($data->bank_account_number) ? $data->bank_account_number : null; - } + // TODO: Implement makeTransfer() method. + } - if (count($this->config['partners'][$transferInfo['destination']['country']]['ewallet']) > 0) { - $transferInfo['destination']['partner'] = isset($data->emq_ewallet_partner) - ? $data->emq_ewallet_partner - : $this->config['partners'][$transferInfo['destination']['country']]['ewallet'][0]; - } - } - } + public function transferStatus(array $orderInfo = []): mixed + { + // TODO: Implement transferStatus() method. + } - //type cash_pickup - if ($transferInfo['destination']['type'] === 'cash_pickup') { - $transferInfo['destination']['partner'] = isset($data->emq_cash_pickup_partner) ? $data->emq_cash_pickup_partner : null; - } + public function cancelTransfer(array $orderInfo = []): mixed + { + // TODO: Implement cancelTransfer() method. + } - /* //verify recipient - $recipientConfirm = $this->verifyRecipient($transferInfo["destination"]); + public function verifyAccount(array $accountInfo = []): mixed + { + // TODO: Implement verifyAccount() method. + } - if ($recipientConfirm['status'] === 200 && $recipientConfirm['response']['result'] === 'ok') {*/ + public function vendorBalance(array $accountInfo = []): mixed + { + // TODO: Implement vendorBalance() method. + } - $returnData = $this->putPostData("/transfers/{$reference}", $transferInfo, 'PUT'); + /** + * @param \Illuminate\Database\Eloquent\Model|Model $order + */ + public function requestQuotation($order): mixed + { + // TODO: Implement requestQuotation() method. + } - /* } else { - $returnData = $recipientConfirm; - }*/ + protected function getBalanceFromCurrency(string $currency, $response) + { - return $returnData; } } diff --git a/src/Vendors/IslamiBankApi.php b/src/Vendors/IslamiBankApi.php new file mode 100644 index 0000000..bfaa7ba --- /dev/null +++ b/src/Vendors/IslamiBankApi.php @@ -0,0 +1,545 @@ +config = config('fintech.remit.providers.islamibank'); + + if ($this->config['mode'] === 'sandbox') { + $this->apiUrl = $this->config[$this->status]['endpoint']; + $this->status = 'sandbox'; + + } else { + $this->apiUrl = $this->config[$this->status]['endpoint']; + $this->status = 'live'; + } + } + + /** + * Fetch Exchange House NRT/NRD account balance (fetchBalance) + * Parameters: userID, password, currency + * + * @throws Exception + */ + public function fetchBalance(string $currency): SimpleXMLElement + { + $xmlString = " + {$this->config[$this->status]['username']} + {$this->config[$this->status]['password']} + {$currency}"; + $soapMethod = 'fetchBalance'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->fetchBalanceResponse->Response; + } + + /** + * Fetch Account Details (fetchAccountDetail) + * Parameters: userID, password, account_number, account_type, branch_code + * + * @throws Exception + */ + public function fetchAccountDetail(array $data): SimpleXMLElement + { + $xmlString = ' + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '; + $xmlString .= ''.($data['account_number'] ?? null).''; + $xmlString .= ''.($data['account_type'] ?? null).''; + $xmlString .= ''.($data['branch_code'] ?? null).''; + $soapMethod = 'fetchAccountDetail'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->fetchAccountDetailResponse->Response; + } + + /** + * Fetch Remittance Status (fetchWSMessageStatus) + * Parameters: userID, password, transaction_reference_number, secret_key + * + * @throws Exception + */ + public function fetchRemittanceStatus(array $data): SimpleXMLElement + { + $xmlString = ' + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '; + $xmlString .= ''.($data['transaction_reference_number'] ?? null).''; + $xmlString .= ''.($data['secret_key'] ?? null).''; + $soapMethod = 'fetchWSMessageStatusResponse'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->fetchAccountDetailResponse->Response; + } + + /** + * Direct Credit Remittance (directCreditWSMessage) + * Parameters: userID, password, accNo, wsMessage + * + * @throws Exception + */ + public function directCreditRemittance(array $data): SimpleXMLElement + { + $xmlString = ' + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '; + $xmlString .= ''.($data['transaction_reference_number'] ?? null).''; + $xmlString .= ''; + $xmlString .= ''.($data['amount'] ?? null).''; + $xmlString .= ''.($data['isoCode'] ?? null).''; + + $xmlString .= ''.($data['beneficiaryAccNo'] ?? null).''; + $xmlString .= ''.($data['beneficiaryAccType'] ?? null).''; + + $xmlString .= ''.($data['beneficiaryAddress'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBankCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBankName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBranchCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBranchName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryPhoneNo'] ?? null).''; + $xmlString .= ''.($data['issueDate'] ?? null).''; + $xmlString .= ''.($data['note'] ?? null).''; + $xmlString .= ''.($data['paymentType'] ?? null).''; + $xmlString .= ''.($data['remitterAddress'] ?? null).''; + $xmlString .= ''.($data['remitterIdentificationNo'] ?? null).''; + $xmlString .= ''; + $xmlString .= ''.($data['remitterPhoneNo'] ?? null).''; + $xmlString .= ''.($data['secretKey'] ?? null).''; + $xmlString .= ''.($data['transReferenceNo'] ?? null).''; + $xmlString .= ''.($data['remittancePurpose'] ?? null).''; + $xmlString .= ''; + $soapMethod = 'directCreditWSMessage'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->directCreditWSMessageResponse->Response; + } + + /** + * Import/push remittance (importWSMessage) + * Parameters: userID, password, accNo, wsMessage + * + * @throws Exception + */ + public function importOrPushRemittance(array $data): SimpleXMLElement + { + $xmlString = ' + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '; + $xmlString .= ''.($data['transaction_reference_number'] ?? null).''; + $xmlString .= ''; + $xmlString .= ''.($data['amount'] ?? null).''; + $xmlString .= ''.($data['isoCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryAddress'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBankCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBankName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBranchCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBranchName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryPassportNo'] ?? null).''; + $xmlString .= ''.($data['beneficiaryPhoneNo'] ?? null).''; + $xmlString .= ''.($data['creatorID'] ?? null).''; + $xmlString .= ''.($data['exchHouseSwiftCode'] ?? null).''; + $xmlString .= ''.($data['identityDescription'] ?? null).''; + $xmlString .= ''.($data['identityType'] ?? null).''; + $xmlString .= ''.($data['issueDate'] ?? null).''; + $xmlString .= ''.($data['note'] ?? null).''; + $xmlString .= ''.($data['paymentType'] ?? null).''; + $xmlString .= ''.($data['remitterAddress'] ?? null).''; + $xmlString .= ''.($data['remitterIdentificationNo'] ?? null).''; + $xmlString .= ''; + $xmlString .= ''.($data['remitterPhoneNo'] ?? null).''; + $xmlString .= ''.($data['secretKey'] ?? null).''; + $xmlString .= ''.($data['transReferenceNo'] ?? null).''; + $xmlString .= ''.($data['transferDate'] ?? null).''; + $xmlString .= ''.($data['remittancePurpose'] ?? null).''; + $xmlString .= ''; + $soapMethod = 'directCreditWSMessage'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->directCreditWSMessageResponse->Response; + } + + /** + * Verify remittance (importWSMessage) + * Parameters: userID, password, accNo, wsMessage + * + * @throws Exception + */ + public function verifyRemittance(array $data): SimpleXMLElement + { + $xmlString = ' + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '; + $xmlString .= ''.($data['transaction_reference_number'] ?? null).''; + $xmlString .= ''; + $xmlString .= ''.($data['amount'] ?? null).''; + $xmlString .= ''.($data['isoCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryAddress'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBankCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBankName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBranchCode'] ?? null).''; + $xmlString .= ''.($data['beneficiaryBranchName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryName'] ?? null).''; + $xmlString .= ''.($data['beneficiaryPassportNo'] ?? null).''; + $xmlString .= ''.($data['beneficiaryPhoneNo'] ?? null).''; + $xmlString .= ''.($data['creatorID'] ?? null).''; + $xmlString .= ''.($data['exchHouseSwiftCode'] ?? null).''; + $xmlString .= ''.($data['identityDescription'] ?? null).''; + $xmlString .= ''.($data['identityType'] ?? null).''; + $xmlString .= ''.($data['issueDate'] ?? null).''; + $xmlString .= ''.($data['note'] ?? null).''; + $xmlString .= ''.($data['paymentType'] ?? null).''; + $xmlString .= ''.($data['remitterAddress'] ?? null).''; + $xmlString .= ''.($data['remitterIdentificationNo'] ?? null).''; + $xmlString .= ''; + $xmlString .= ''.($data['remitterPhoneNo'] ?? null).''; + $xmlString .= ''.($data['secretKey'] ?? null).''; + $xmlString .= ''.($data['transReferenceNo'] ?? null).''; + $xmlString .= ''.($data['transferDate'] ?? null).''; + $xmlString .= ''.($data['remittancePurpose'] ?? null).''; + $xmlString .= ''; + $soapMethod = 'directCreditWSMessage'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->directCreditWSMessageResponse->Response; + } + + /** + * ValidateBeneficiaryWallet (validateBeneficiaryWallet) + * Parameters: userID, password, walletNo, paymentType + * + * @throws Exception + */ + public function validateBeneficiaryWallet(array $data): SimpleXMLElement + { + $xmlString = ' + '.$this->config[$this->status]['username'].' + '.$this->config[$this->status]['password'].' + '; + $xmlString .= ''.($data['account_number'] ?? null).''; + $xmlString .= ''.($data['account_type'] ?? null).''; + $soapMethod = 'validateBeneficiaryWallet'; + $response = $this->connectionCheck($xmlString, $soapMethod); + + return $response->validateBeneficiaryWalletResponse->Response; + } + + /** + * @throws Exception + */ + private function connectionCheck($xml_post_string, $method) + { + $xml_string = $this->xmlGenerate($xml_post_string, $method); + Log::info($method.'
'.$xml_string); + $headers = [ + 'Host: '.parse_url($this->apiUrl, PHP_URL_HOST), + 'Content-type: text/xml;charset="utf-8"', + 'Content-length: '.strlen($xml_string), + 'SOAPAction: '.$method, + ]; + + // PHP cURL for connection + $ch = curl_init(); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_URL, $this->apiUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_setopt($ch, CURLOPT_TIMEOUT, 0); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_string); // the SOAP request + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + // execution + $response = curl_exec($ch); + Log::error($method.' CURL reported error: '); + if ($response === false) { + throw new Exception(curl_error($ch), curl_errno($ch)); + } + curl_close($ch); + Log::info('Raw Response'.PHP_EOL.$response); + // $response1 = str_replace('', '', $response); + // $response2 = str_replace('', '', $response1); + // $response = str_replace('xmlns:ns="http://service.ws.mt.ibbl"', '', $response2); + // $response = str_replace('ns:', '', $response); //dd($response); + // Log::info($method . '
' . $response); + + return simplexml_load_string($response); + } + + public function xmlGenerate($string, $method): string + { + return << + + + + + {$string} + + + +XML; + } + + /** + * Response Code List + * These codes will return in all operations. + * + * @return string[] + */ + private function __responseCodeList(int $code): array + { + return [ + 1000 => 'ERROR OTHERS', + 1001 => 'TRANSACTION REF INVALID', + 1002 => 'AMOUNT INVALID', + 1003 => 'ISO CODE INVALID', + 1004 => 'SWIFT CODE INVALID', + 1005 => 'NOTE INVALID', + 1006 => 'SECRET KEY INVALID', + 1007 => 'PAYMENT TYPE INVALID', + 1008 => 'IDENTITY TYPE INVALID', + 1009 => 'IDENTITY DESCRIPTION INVALID', + 1010 => 'EXCHANGE BR CODE INVALID', + 1011 => 'ISSUE DATE INVALID', + 1101 => 'TRANSACTION REF MISSING', + 1102 => 'AMOUNT MISSING', + 1103 => 'CURRENCY MISSING', + 1104 => 'SWIFT CODE MISSING', + 1105 => 'NOTE MISSING', + 1106 => 'SECRET KEY MISSING', + 1107 => 'PAYMENT TYPE MISSING', + 1108 => 'IDENTITY TYPE MISSING', + 1109 => 'IDENTITY DESCRIPTION MISSING', + 1110 => 'EXCHANGE BR CODE MISSING', + 1111 => 'ISSUE DATE MISSING', + 1201 => 'BENEFICIARY ACC NO NOT APPLICABLE', + 1202 => 'BENEFICIARY ROUTING NO NOT APPLICABLE', + 1301 => 'BENEFICIARY ACC NO NOT FOUND', + 2001 => 'REMITTER NAME INVALID', + 2002 => 'REMITTER IDENTIFICATION NO INVALID', + 2003 => 'REMITTER PHONE NO INVALID', + 2004 => 'REMITTER ADDRESS INVALID', + 2101 => 'REMITTER NAME MISSING', + 2102 => 'REMITTER IDENTIFICATION NO MISSING', + 2103 => 'REMITTER PHONE NO MISSING', + 2104 => 'REMITTER ADDRESS MISSING', + 3001 => 'BENEFICIARY NAME INVALID', + 3002 => 'BENEFICIARY PASSPORT INVALID', + 3003 => 'BENEFICIARY PHONE INVALID', + 3004 => 'BENEFICIARY ADDRESS INVALID', + 3005 => 'BENEFICIARY ACC NO INVALID', + 3006 => 'BENEFICIARY ACC TYPE INVALID', + 3007 => 'BENEFICIARY BANK CODE INVALID', + 3008 => 'BENEFICIARY BANK NAME INVALID', + 3009 => 'BENEFICIARY BRANCH CODE INVALID', + 3010 => 'BENEFICIARY BRANCH NAME INVALID', + 3011 => 'BENEFICIARY ROUTING NO INVALID', + 3101 => 'BENEFICIARY NAME MISSING', + 3102 => 'BENEFICIARY PASSPORT MISSING', + 3103 => 'BENEFICIARY PHONE MISSING', + 3104 => 'BENEFICIARY ADDRESS MISSING', + 3105 => 'BENEFICIARY ACC NO MISSING', + 3106 => 'BENEFICIARY ACC TYPE MISSING', + 3107 => 'BENEFICIARY BANK CODE MISSING', + 3108 => 'BENEFICIARY BANK NAME MISSING', + 3109 => 'BENEFICIARY BRANCH CODE MISSING', + 3110 => 'BENEFICIARY BRANCH NAME MISSING', + 3111 => 'BENEFICIARY ROUTING NO MISSING', + 3112 => 'BENEFICIARY CARD NO MISSING', + 3113 => 'BENEFICIARY WALLET ACC NO MISSING', + 3114 => 'BENEFICIARY ACC NO LENGTH INVALID', + 5001 => 'REMITTANCE ALREADY IMPORTED', + 5002 => 'REMITTANCE VERIFIED SUCCESSFULLY', + 5003 => 'REMITTANCE SUCCESS', + 5004 => 'REMITTANCE FAILED', + 5005 => 'REMITTANCE SKIPPED', + 5006 => 'REMITTANCE NOT_FOUND', + 5007 => 'REMITTANCE IS ENQUEUED', + 6001 => 'INSUFFICIENT BALANCE', + 6002 => 'ACCOUNT NAME AND ACCOUNT NO. DIFFER', + 6003 => 'FIELD LENGTH INVALID', + 6004 => 'ACCOUNT NO. NOT FOUND', + 7001 => 'USER NAME OR PASSWORD IS MISSING', + 7002 => 'USER NAME OR PASSWORD IS INVALID', + 7003 => 'USER IS BLOCKED', + 7004 => 'USER IS INACTIVE', + 7005 => 'USER IS DEAD (PERMANENTLY BLOCKED)', + ]; + } + + /** + * Response Status Code List + * These codes will return in only Fetch Remittance Status (fetchWSMessageStatus) operation. + * + * @return string[] + */ + private function __responseStatusCodeList(string $code): array + { + return [ + '01' => 'REMITTANCE ISSUED', + '02' => 'REMITTANCE TRANSFERRED/AUTHORIZED BY EXCHANGE HOUSE', + '03' => 'REMITTANCE READY FOR PAYMENT', + '04' => 'REMITTANCE UNDER PROCESS', + '05' => 'REMITTANCE STOPPED', + '06' => 'REMITTANCE STOPPED BY EXCHANGE HOUSE', + '07' => 'REMITTANCE PAID', + '08' => 'REMITTANCE AMENDED', + '11' => 'REMITTANCE CANCELLED', + '17' => 'REMITTANCE REVERSED', + '20' => 'REMITTANCE CANCEL REQUEST', + '30' => 'REMITTANCE AMENDMENT REQUEST', + '70' => 'REMITTANCE CBS UNDER PROCESS', + '73' => 'REMITTANCE CBS AUTHORIZED', + '74' => 'REMITTANCE CBS PENDING', + '77' => 'REMITTANCE CBS NRT ACCOUNT DEBITED', + '78' => 'REMITTANCE CBS READY FOR PAYMENT', + '79' => 'REMITTANCE CBS CREDITED TO ACCOUNT', + '80' => 'REMITTANCE CBS UNKNOWN STATE', + '82' => 'CBS ACC PAYEE TITLE AND ACCOUNT NO DIFFER', + '83' => 'CBS EFT INVALID ACCOUNT', + '84' => 'CBS EFT SENT TO THIRD BANK', + '99' => 'REMITTANCE INVALID STATUS', + ]; + } + + /** + * Instrument/Payment Type Code + * + * @return string[] + */ + private function __instrumentOrPaymentTypeCode(int $code): array + { + return [ + 1 => 'Instant Cash / Spot Cash/COC', + 2 => 'IBBL Account Payee', + 3 => 'Other Bank (BEFTN)', + 4 => 'Remittance Card5 Mobile Banking (mCash)', + 6 => 'New IBBL Account Open', + 7 => 'Mobile Banking(bKash)', + 8 => 'Mobile Banking (Nagad)', + ]; + } + + /** + * Beneficiary Identity Type Code + * + * @return string[] + */ + private function __beneficiaryIdentityTypeCode(int $code): array + { + return [ + 1 => 'Passport', + 2 => 'Cheque', + 3 => 'Photo', + 4 => 'Finger Print', + 5 => 'Introducer', + 6 => 'Driving License', + 7 => 'Other', + 8 => 'Remittance Card', + 9 => 'National ID Card', + 10 => 'Birth Certificate', + 11 => 'Student ID Card', + ]; + } + + /** + * Account Type Code + * Please send the following two digit code against the different types of account. + * + * @return string[] + */ + private function __accountTypeCode(string $code): array + { + return [ + '01' => 'AWCA (Current)', + '02' => 'MSA (Savings)', + '03' => 'MSSA (Scheme)', + '05' => 'MTDRA(Term Deposit)', + '06' => 'MMSA (Mohr)', + '07' => 'MHSA (Hajj)', + '09' => 'SND(Short Notice Deposit)', + '10' => 'MSA-STAFF', + '11' => 'FCA (FC Current)', + '12' => 'MFCA (FC Savings)', + '67' => 'SMSA(Student Savings)', + '68' => 'MNSBA(NRB Savings Bond)', + ]; + } + + public function makeTransfer(array $orderInfo = []): mixed + { + return []; + } + + /** + * @throws Exception + */ + public function transferStatus(array $orderInfo = []): mixed + { + return $this->fetchRemittanceStatus($orderInfo); + } + + public function cancelTransfer(array $orderInfo = []): mixed + { + return []; + } + + /** + * @throws Exception + */ + public function verifyAccount(array $accountInfo = []): mixed + { + $this->validateBeneficiaryWallet($accountInfo); + + return []; + } + + /** + * @throws Exception + */ + public function vendorBalance(array $accountInfo = []): mixed + { + $currency = $accountInfo['currency'] ?? 'USD'; + + return $this->fetchBalance($currency); + } + + public function requestQuotation($order): mixed + { + return []; + } +} diff --git a/src/Vendors/TransFastApi.php b/src/Vendors/TransFastApi.php index be36866..b3e5db5 100644 --- a/src/Vendors/TransFastApi.php +++ b/src/Vendors/TransFastApi.php @@ -2,10 +2,15 @@ namespace Fintech\Remit\Vendors; +use Exception; use Illuminate\Support\Facades\Log; class TransFastApi { + protected $payment_mode; + + protected $account_type; + /** * TransFast API configuration. * @@ -20,10 +25,6 @@ class TransFastApi */ private $apiUrl; - protected $payment_mode; - - protected $account_type; - /** * @var string */ @@ -34,14 +35,15 @@ class TransFastApi */ public function __construct() { - $this->config = config('trans-fast'); + $this->config = config('fintech.remit.providers.transfast'); + if ($this->config['mode'] === 'sandbox') { + $this->apiUrl = $this->config[$this->status]['endpoint']; $this->status = 'sandbox'; - $this->apiUrl = 'https://'.$this->config[$this->status]['app_host']; } else { + $this->apiUrl = $this->config[$this->status]['endpoint']; $this->status = 'live'; - $this->apiUrl = 'https://'.$this->config[$this->status]['app_host']; } $this->payment_mode = 'C'; //C = Bank Deposit, 2 = Cash Pick Up, G = Mobile Cash, U = Cash Card @@ -49,74 +51,41 @@ public function __construct() } /** - * Base function that is responsible for interacting directly with the transpay api to obtain data + * Get the available countries * - * @param array $params * @return array * - * @throws \Exception + * @throws Exception */ - public function getData($url, $params = []) + public function getCountries() { - $apiUrl = $this->apiUrl.$url; - $apiUrl .= http_build_query($params); - Log::info($apiUrl); - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $apiUrl); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - 'Authorization: Credentials '.$this->config[$this->status]['api_token']] - ); - - $response = curl_exec($curl); - $info = curl_getinfo($curl); - $error = curl_error($curl); - - if ($response === false) { - Log::info($info); - Log::info($error); - throw new \Exception(curl_error($curl), curl_errno($curl)); - } - - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - curl_close($curl); - Log::info(json_decode($response, true)); - - return [ - 'status' => $status, - 'response' => json_decode($response, true), - ]; + $url = 'catalogs/countries'; + $response = $this->getData($url); + return $response; } /** - * Base function that is responsible for interacting directly with the trans fast api to send data + * Base function that is responsible for interacting directly with the transpay api to obtain data * - * @param string $method + * @param array $params * @return array * - * @throws \Exception + * @throws Exception */ - public function putPostData($url, $dataArray, $method = 'POST') + public function getData($url, $params = []) { $apiUrl = $this->apiUrl.$url; + $apiUrl .= http_build_query($params); Log::info($apiUrl); - $jsonArray = json_encode($dataArray); - Log::info(json_decode($jsonArray, true)); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $apiUrl); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); - curl_setopt($curl, CURLOPT_POST, count($dataArray)); - curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonArray); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_VERBOSE, true); curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', - 'Authorization: Credentials '.$this->config[$this->status]['api_token']] + 'Authorization: Credentials '.$this->config[$this->status]['token']] ); $response = curl_exec($curl); @@ -126,33 +95,18 @@ public function putPostData($url, $dataArray, $method = 'POST') if ($response === false) { Log::info($info); Log::info($error); - throw new \Exception(curl_error($curl), curl_errno($curl)); + throw new Exception(curl_error($curl), curl_errno($curl)); } $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); - Log::info(json_decode($response, true)); return [ 'status' => $status, 'response' => json_decode($response, true), ]; - } - /** - * Get the available countries - * - * @return array - * - * @throws \Exception - */ - public function getCountries() - { - $url = 'catalogs/countries'; - $response = $this->getData($url); - - return $response; } /** @@ -160,7 +114,7 @@ public function getCountries() * * @return array * - * @throws \Exception + * @throws Exception */ public function getStates($country) { @@ -176,7 +130,7 @@ public function getStates($country) * * @return array * - * @throws \Exception + * @throws Exception */ public function getCities($country, $state) { @@ -192,7 +146,7 @@ public function getCities($country, $state) * * @return array * - * @throws \Exception + * @throws Exception */ public function getTowns($country, $state, $city) { @@ -207,6 +161,8 @@ public function getTowns($country, $state, $city) * Get the available banks for a country * * @return array + * + * @throws Exception */ public function getBanks($country) { @@ -222,7 +178,7 @@ public function getBanks($country) * * @return array * - * @throws \Exception + * @throws Exception */ public function getBanksBranch($bank, $state, $city) { @@ -238,7 +194,7 @@ public function getBanksBranch($bank, $state, $city) * * @return array * - * @throws \Exception + * @throws Exception */ public function getBranchPayers($country, $state, $city, $receiveCurrencyIsoCode, $bank, $paymentMode, $sourceCurrencyIsoCode) { @@ -257,7 +213,7 @@ public function getBranchPayers($country, $state, $city, $receiveCurrencyIsoCode * * @return array * - * @throws \Exception + * @throws Exception */ public function getSenderOccupation() { @@ -272,7 +228,7 @@ public function getSenderOccupation() * * @return array * - * @throws \Exception + * @throws Exception */ public function getRequiredFields() { @@ -290,7 +246,7 @@ public function getRequiredFields() * * @return array * - * @throws \Exception + * @throws Exception */ public function getCurrencies($country, $state, $city, $paymentMode) { @@ -310,7 +266,7 @@ public function getCurrencies($country, $state, $city, $paymentMode) * * @return array * - * @throws \Exception + * @throws Exception */ public function getPaymentModes($country, $state, $city) { @@ -326,7 +282,7 @@ public function getPaymentModes($country, $state, $city) * * @return array * - * @throws \Exception + * @throws Exception */ public function getPayoutLimits($country, $city, $paymentMode, $receiveCurrencyIsoCode, $sourceCurrencyIsoCode) { @@ -343,7 +299,7 @@ public function getPayoutLimits($country, $city, $paymentMode, $receiveCurrencyI * * @return array * - * @throws \Exception + * @throws Exception */ public function getNationality($country) { @@ -359,7 +315,7 @@ public function getNationality($country) * * @return array * - * @throws \Exception + * @throws Exception */ public function getSourceOfFunds() { @@ -374,7 +330,7 @@ public function getSourceOfFunds() * * @return array * - * @throws \Exception + * @throws Exception */ public function getReceiversTypeOfId($country) { @@ -390,7 +346,7 @@ public function getReceiversTypeOfId($country) * * @return array * - * @throws \Exception + * @throws Exception */ public function getSendersTypeOfId($country) { @@ -409,7 +365,7 @@ public function getSendersTypeOfId($country) * @param $country * @return array * - * @throws \Exception + * @throws Exception */ public function getCashPickupCountry() { @@ -425,7 +381,7 @@ public function getCashPickupCountry() * * @return array * - * @throws \Exception + * @throws Exception */ public function getReceiveCountries() { @@ -445,7 +401,7 @@ public function getReceiveCountries() * * @return array * - * @throws \Exception + * @throws Exception */ public function getTransactionInfo($inputData) { @@ -485,7 +441,7 @@ public function getTransactionInfo($inputData) * * @return array * - * @throws \Exception + * @throws Exception */ public function getBankDetailByRoutingNo($country, $routingNumber) { @@ -501,7 +457,7 @@ public function getBankDetailByRoutingNo($country, $routingNumber) * * @return array * - * @throws \Exception + * @throws Exception */ public function getByReferenceNumber($referenceNumber) { @@ -518,7 +474,7 @@ public function getByReferenceNumber($referenceNumber) * * @return array * - * @throws \Exception + * @throws Exception */ public function getTransactionStatus($tfpin) { @@ -534,7 +490,7 @@ public function getTransactionStatus($tfpin) * @param string $feeProduct * @return array * - * @throws \Exception + * @throws Exception */ public function getCountryRates($sourceCurrencyIsoCode, $receiveCountryIsoCode, $feeProduct = '') { @@ -550,7 +506,7 @@ public function getCountryRates($sourceCurrencyIsoCode, $receiveCountryIsoCode, * * @return array * - * @throws \Exception + * @throws Exception */ public function getTransactionList($startDate, $endDate) { @@ -569,7 +525,7 @@ public function getTransactionList($startDate, $endDate) * * @return array * - * @throws \Exception + * @throws Exception */ public function getSenderBySenderID($senderId) { @@ -585,7 +541,7 @@ public function getSenderBySenderID($senderId) * @param string $feeProduct * @return array * - * @throws \Exception + * @throws Exception */ public function getCommissionByCountry($sourceCurrencyIsoCode, $receiveCountryIsoCode, $feeProduct = '') { @@ -602,7 +558,7 @@ public function getCommissionByCountry($sourceCurrencyIsoCode, $receiveCountryIs * @param $onlyForCustomerCare -- i.e. true or false * @return array * - * @throws \Exception + * @throws Exception */ public function getComplaintType($onlyForCustomerCare) { @@ -617,7 +573,7 @@ public function getComplaintType($onlyForCustomerCare) * * @return array * - * @throws \Exception + * @throws Exception */ public function getCancelReasons() { @@ -631,7 +587,7 @@ public function getCancelReasons() * * @return array * - * @throws \Exception + * @throws Exception */ public function getFormOfPayments() { @@ -645,7 +601,7 @@ public function getFormOfPayments() * * @return array * - * @throws \Exception + * @throws Exception */ public function getRemittancePurposes($country) { @@ -661,7 +617,7 @@ public function getRemittancePurposes($country) * @param string $generatedUnused * @return array * - * @throws \Exception + * @throws Exception */ public function getGeneratedTransFastPins($country, $payerId, $numberOfPins, $generatedUnused = '') { @@ -676,7 +632,7 @@ public function getGeneratedTransFastPins($country, $payerId, $numberOfPins, $ge * * @return array * - * @throws \Exception + * @throws Exception */ public function getAccountingBalance($currencyIsoCode) { @@ -691,7 +647,7 @@ public function getAccountingBalance($currencyIsoCode) * * @return array * - * @throws \Exception + * @throws Exception */ public function getAccountType($countryIsoCode) { @@ -707,7 +663,7 @@ public function getAccountType($countryIsoCode) * * @return array * - * @throws \Exception + * @throws Exception */ public function putReleaseTransaction($transFastPin) { @@ -717,12 +673,60 @@ public function putReleaseTransaction($transFastPin) return $this->putPostData($url, $params, 'PUT'); } + /** + * Base function that is responsible for interacting directly with the trans fast api to send data + * + * @param string $method + * @return array + * + * @throws Exception + */ + public function putPostData($url, $dataArray, $method = 'POST') + { + $apiUrl = $this->apiUrl.$url; + Log::info($apiUrl); + $jsonArray = json_encode($dataArray); + Log::info(json_decode($jsonArray, true)); + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $apiUrl); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($curl, CURLOPT_POST, count($dataArray)); + curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonArray); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_VERBOSE, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'Authorization: Credentials '.$this->config[$this->status]['token']] + ); + + $response = curl_exec($curl); + $info = curl_getinfo($curl); + $error = curl_error($curl); + + if ($response === false) { + Log::info($info); + Log::info($error); + throw new Exception(curl_error($curl), curl_errno($curl)); + } + + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + curl_close($curl); + + Log::info(json_decode($response, true)); + + return [ + 'status' => $status, + 'response' => json_decode($response, true), + ]; + } + /** * Cancel transaction given a TfPin (transaction number) and reason code (reason for cancellation). * * @return array * - * @throws \Exception + * @throws Exception */ public function putCancelTransaction($transFastPin, $reasonId) { @@ -738,7 +742,7 @@ public function putCancelTransaction($transFastPin, $reasonId) * * @return array * - * @throws \Exception + * @throws Exception */ public function putModifySenderID( $senderId, $name, $address, $phoneHome, $phoneWork, $isIndividual, $countryISO, $phoneMobile, $email, $stateId, @@ -773,7 +777,7 @@ public function putModifySenderID( * * @return array * - * @throws \Exception + * @throws Exception */ public function putReadCustomerCareComplaintOrPetition($transFastPin, $startDate, $endDate, $isReadAll = 'true') { @@ -792,7 +796,7 @@ public function putReadCustomerCareComplaintOrPetition($transFastPin, $startDate * * @return array * - * @throws \Exception + * @throws Exception */ public function postCustomerCareComplaintOrPetition($transFastPin, $petitionType, $message) { @@ -810,7 +814,7 @@ public function postCustomerCareComplaintOrPetition($transFastPin, $petitionType * * @return array * - * @throws \Exception + * @throws Exception */ public function postCreateSenderID( $name, $address, $phoneHome, $phoneWork, $isIndividual, $countryISO, $phoneMobile, $email, $stateId, @@ -846,7 +850,7 @@ public function postCreateSenderID( * * @return array * - * @throws \Exception + * @throws Exception */ public function postCreateTransaction($data) { diff --git a/src/Vendors/ValYouApi.php b/src/Vendors/ValYouApi.php index 64554ac..02224e1 100644 --- a/src/Vendors/ValYouApi.php +++ b/src/Vendors/ValYouApi.php @@ -2,26 +2,12 @@ namespace Fintech\Remit\Vendors; +use Exception; use Illuminate\Support\Facades\Log; +use SimpleXMLElement; class ValYouApi { - /** - * ValYou API configuration. - * - * @var array - */ - private $config; - - /** - * ValYou API Url. - * - * @var string - */ - private $apiUrl; - - private $status = 'sandbox'; - /** * @var string */ @@ -52,6 +38,22 @@ class ValYouApi */ protected $calculated_by_sending_payout_currency; + /** + * ValYou API configuration. + * + * @var array + */ + private $config; + + /** + * ValYou API Url. + * + * @var string + */ + private $apiUrl; + + private $status = 'sandbox'; + /** * ValYouApiService constructor. */ @@ -80,7 +82,7 @@ public function __construct() * * @return mixed * - * @throws \Exception + * @throws Exception */ public function getEcho() { @@ -99,6 +101,65 @@ public function getEcho() return json_decode(json_encode($response->GetEchoResponse), true); } + /** + * @return string + */ + public function xmlGenerate($string, $method) + { + $xml_string = ' + + + <'.$method.' xmlns="WebServices"> + '.$string.' + + + + '; + + return $xml_string; + } + + /** + * @return SimpleXMLElement + * + * @throws Exception + */ + public function connectionCheck($xml_post_string, $method) + { + $headers = [ + 'Host: '.$this->config[$this->status]['app_host'], + 'Content-type: text/xml;charset="utf-8"', + 'Content-length: '.strlen($xml_post_string), + 'SOAPAction: WebServices/'.$method, + ]; + + // PHP cURL for connection + $ch = curl_init(); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_URL, $this->apiUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_setopt($ch, CURLOPT_TIMEOUT, 0); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + // execution + $response = curl_exec($ch); + if ($response === false) { + throw new Exception(curl_error($ch), curl_errno($ch)); + $response .= "\nError occoured when connecting to the SMS SOAP Server!"; + $response .= "\nSoap Exception: ".$exception; + $response .= "\nSOAP Fault: (faultcode: {curl_errno($ch)}, faultstring: {curl_error($ch)})"; + Log::error('CURL reported error: ', $response); + } + curl_close($ch); + $response1 = str_replace('', '', $response); + $response2 = str_replace('', '', $response1); + $response = str_replace('xmlns="WebServices"', '', $response2); + + return simplexml_load_string($response); + } + /** * Call this method to Get the Static Data like Countries, list Payment Mode, Get Payout Agent List * @@ -110,7 +171,7 @@ public function getEcho() * ADDITIONAL_FIELD2: Payment Mode (C: cash pickup | B: Account Deposit| H: Home Delivery) * @return mixed * - * @throws \Exception + * @throws Exception */ public function getCatalogue($input_data) { @@ -144,7 +205,7 @@ public function getCatalogue($input_data) * * @return mixed * - * @throws \Exception + * @throws Exception */ public function getAgentList($input_data) { @@ -186,7 +247,7 @@ public function getAgentList($input_data) * LOCATION_ID (location_id), TRANSFERAMOUNT (transfer_amount), PAYOUT_COUNTRY (payout_country) * @return mixed * - * @throws \Exception + * @throws Exception */ public function exRate($input_data) { @@ -226,169 +287,6 @@ public function exRate($input_data) return json_decode(json_encode($response->GetEXRateResponse->GetEXRateResult), true); } - /** - * After Successful calling GetExRate method, call this function to send transaction. - * While sending Transaction if Customer already exists, it will update the existing Customer. - * If theCustomer is new, the SendTransaction method Auto-creates new Customer based on Sender_ID_Type and - * Sender_ID_Number(these information will be unique to identify Customer) - * - * The Authorized_Confirmed method has to be called within 30 minutes of SendTransaction - * - * @return mixed - * - * @throws \Exception - */ - public function sendTransaction($input_data) - { - //dd($input_data); - $location_id = $input_data->valyou_location_routing_id[0]->bank_branch_location_field_value; - $AGENT_TXNID = $input_data->purchase_number; - $SENDER_FIRST_NAME = $input_data->sender_first_name; - $SENDER_MIDDLE_NAME = ''; - $SENDER_LAST_NAME = ''; - $SENDER_GENDER = $input_data->sender_gender; - $SENDER_ADDRESS = $input_data->sender_address; - $SENDER_CITY = $input_data->sender_city; - $SENDER_STATES = $input_data->sender_states; - $SENDER_ZIPCODE = $input_data->sender_zipcode; - $SENDER_COUNTRY = $input_data->sender_country; - $SENDER_MOBILE = $input_data->sender_mobile; - $SENDER_NATIONALITY = $input_data->sender_nationality; - $SENDER_ID_TYPE = $input_data->sender_id_type; - $SENDER_ID_NUMBER = $input_data->sender_id_number; - $SENDER_ID_ISSUE_COUNTRY = $input_data->sender_id_issue_country; - $SENDER_ID_ISSUE_DATE = date('Y-m-d', strtotime($input_data->sender_id_issue_date)); - $SENDER_ID_EXPIRE_DATE = date('Y-m-d', strtotime($input_data->sender_expire_date)); - $SENDER_DATE_OF_BIRTH = date('Y-m-d', strtotime($input_data->sender_date_of_birth)); - $SENDER_OCCUPATION = $input_data->sender_occupation; - $SENDER_SOURCE_OF_FUND = $input_data->sender_source_of_fund; - $SENDER_COUNTRY_OF_BIRTH = $input_data->sender_country_of_birth; - $SENDER_BENEFICIARY_RELATIONSHIP = $input_data->sender_beneficiary_relationship; - //$PURPOSE_OF_REMITTANCE = $input_data->purpose_of_remittance; - $PURPOSE_OF_REMITTANCE = 'FAMILY MAINTENANCE/SAVINGS'; - $RECEIVER_FIRST_NAME = $input_data->receiver_first_name; - $RECEIVER_MIDDLE_NAME = ''; //$input_data->receiver_middle_name; - $RECEIVER_LAST_NAME = $input_data->receiver_last_name; - $RECEIVER_ADDRESS = $input_data->receiver_address; - $RECEIVER_CONTACT_NUMBER = ''; //$input_data->receiver_contact_number; - $RECEIVER_COUNTRY = $input_data->receiver_country; - $RECEIVER_CITY = $input_data->receiver_country; - $TRANSFER_AMOUNT = $input_data->transfer_amount; - $REMIT_CURRENCY = ''; //$input_data->sender_currency; - $TRANSFER_CURRENCY = $input_data->transfer_currency; - $BANK_NAME = $input_data->valyou_bank_name; - $BANK_BRANCH_NAME = $input_data->valyou_bank_branch_name; - if ($TRANSFER_CURRENCY == 'INR') { - $BANK_BRANCH_NAME = $input_data->valyou_location_routing_id[1]->bank_branch_location_field_value; - } - $BANK_ACCOUNT_NUMBER = $input_data->bank_account_number; - if ($input_data['recipient_type_name'] == 'Cash') { - $location_id = is_null($input_data['location_id']) ? $input_data['location_id'] : '96700015P39319013P743723'; - $this->payment_mode = 'C'; - //$this->calculated_by_sending_payout_currency = 'C'; - } elseif ($input_data['recipient_type_name'] == 'Wallet') { - $location_id = is_null($input_data['location_id']) ? $input_data['location_id'] : '96700241P96836978'; - } - $signature = $this->agent_code.$this->ClientId.$this->agent_session_id.$AGENT_TXNID.$location_id. - $SENDER_FIRST_NAME.$SENDER_MIDDLE_NAME.$SENDER_LAST_NAME.$SENDER_GENDER. - $SENDER_ADDRESS.$SENDER_CITY.$SENDER_STATES.$SENDER_ZIPCODE.$SENDER_COUNTRY.$SENDER_MOBILE. - $SENDER_NATIONALITY.$SENDER_ID_TYPE.$SENDER_ID_NUMBER.$SENDER_ID_ISSUE_COUNTRY.$SENDER_ID_ISSUE_DATE. - $SENDER_ID_EXPIRE_DATE.$SENDER_DATE_OF_BIRTH.$SENDER_OCCUPATION.$SENDER_SOURCE_OF_FUND. - $SENDER_COUNTRY_OF_BIRTH.$SENDER_BENEFICIARY_RELATIONSHIP.$PURPOSE_OF_REMITTANCE. - $RECEIVER_FIRST_NAME.$RECEIVER_MIDDLE_NAME.$RECEIVER_LAST_NAME.$RECEIVER_ADDRESS. - $RECEIVER_CONTACT_NUMBER.$RECEIVER_CITY.$RECEIVER_COUNTRY. - $this->calculated_by_sending_payout_currency.$TRANSFER_AMOUNT.$REMIT_CURRENCY. - $TRANSFER_CURRENCY.$this->payment_mode.$BANK_NAME.$BANK_BRANCH_NAME.$BANK_ACCOUNT_NUMBER.$this->ClientPass; - $hash_signature = hash('sha256', $signature); - $xml_string = ' - '.$this->agent_code.' - '.$this->ClientId.' - '.$this->agent_session_id.' - '.$AGENT_TXNID.' - '.$location_id.' - '.$SENDER_FIRST_NAME.' - - - '.$SENDER_GENDER.' - '.$SENDER_ADDRESS.' - '.$SENDER_CITY.' - '.$SENDER_STATES.' - '.$SENDER_ZIPCODE.' - '.$SENDER_COUNTRY.' - '.$SENDER_MOBILE.' - '.$SENDER_NATIONALITY.' - '.$SENDER_ID_TYPE.' - '.$SENDER_ID_NUMBER.' - '.$SENDER_ID_ISSUE_COUNTRY.' - '.$SENDER_ID_ISSUE_DATE.' - '.$SENDER_ID_EXPIRE_DATE.' - '.$SENDER_DATE_OF_BIRTH.' - '.$SENDER_OCCUPATION.' - '.$SENDER_SOURCE_OF_FUND.' - - - '.$SENDER_COUNTRY_OF_BIRTH.' - '.$SENDER_BENEFICIARY_RELATIONSHIP.' - '.$PURPOSE_OF_REMITTANCE.' - '.$RECEIVER_FIRST_NAME.' - '.$RECEIVER_MIDDLE_NAME.' - '.$RECEIVER_LAST_NAME.' - '.$RECEIVER_ADDRESS.' - '.$RECEIVER_CONTACT_NUMBER.' - '.$RECEIVER_CITY.' - '.$RECEIVER_COUNTRY.' - - - '.$this->calculated_by_sending_payout_currency.' - '.$TRANSFER_AMOUNT.' - '.$REMIT_CURRENCY.' - '.$TRANSFER_CURRENCY.' - '.$this->payment_mode.' - '.$BANK_NAME.' - '.$BANK_BRANCH_NAME.' - '.$BANK_ACCOUNT_NUMBER.' - - '.$hash_signature.' - - '; - $soapMethod = 'SendTransaction'; - $xml_post_string = $this->xmlGenerate($xml_string, $soapMethod); - $response = $this->connectionCheck($xml_post_string, $soapMethod); - Log::info(json_decode(json_encode($response->SendTransactionResponse->SendTransactionResult), true)); - - return json_decode(json_encode($response->SendTransactionResponse->SendTransactionResult), true); - } - - /** - * Call this method to Commit Transaction. - * After SendTransaction, you must call Authorized_Confirmed to make transaction available. - * Session will be expired in 30 mins. - * All those transactions which are not Authorized, will be truncated from system at End of Day. - * - * @return mixed - * - * @throws \Exception - */ - public function authorizedConfirmed($input_data) - { - $PINNO = $input_data['PINNO']; - $signature = $this->agent_code.$this->ClientId.$PINNO.$this->agent_session_id.$this->ClientPass; - $hash_signature = hash('sha256', $signature); - $xml_string = ' - '.$this->agent_code.' - '.$this->ClientId.' - '.$PINNO.' - '.$this->agent_session_id.' - '.$hash_signature.' - '; - $soapMethod = 'Authorized_Confirmed'; - $xml_post_string = $this->xmlGenerate($xml_string, $soapMethod); - $response = $this->connectionCheck($xml_post_string, $soapMethod); - Log::info(json_decode(json_encode($response->Authorized_ConfirmedResponse->Authorized_ConfirmedResult), true)); - - return json_decode(json_encode($response->Authorized_ConfirmedResponse->Authorized_ConfirmedResult), true); - } - /** * This method is used the check current status of transaction by PINNO or by Agent TXN ID. * @@ -396,7 +294,7 @@ public function authorizedConfirmed($input_data) * PINNO (PINNO), AGENT_TXNID (AGENT_TXNID) * @return mixed * - * @throws \Exception + * @throws Exception */ public function queryTxnStatus($input_data) { @@ -433,7 +331,7 @@ public function queryTxnStatus($input_data) * FROM_DATE ($input_data['from_date']), TO_DATE ($input_data['to_date']) * @return mixed * - * @throws \Exception + * @throws Exception */ public function reconcileReport($input_data) { @@ -465,7 +363,7 @@ public function reconcileReport($input_data) * * @return mixed * - * @throws \Exception + * @throws Exception */ public function reconcileReportV2($input_data) { @@ -497,7 +395,7 @@ public function reconcileReportV2($input_data) * PAYOUT_COUNTRY ($input_data['country_name']) * @return mixed * - * @throws \Exception + * @throws Exception */ public function getCountryWiseRate($input_data) { @@ -523,7 +421,7 @@ public function getCountryWiseRate($input_data) * * @return mixed * - * @throws \Exception + * @throws Exception */ public function accountValidate($input_data) { @@ -557,7 +455,7 @@ public function accountValidate($input_data) * If "y" then FROM_DATE and TO_DATE not required * @return mixed * - * @throws \Exception + * @throws Exception */ public function notificationStatus($input_data) { @@ -583,82 +481,186 @@ public function notificationStatus($input_data) } /** - * @return \SimpleXMLElement + * @return object * - * @throws \Exception + * @throws Exception */ - public function connectionCheck($xml_post_string, $method) + public function topUp($input) { - $headers = [ - 'Host: '.$this->config[$this->status]['app_host'], - 'Content-type: text/xml;charset="utf-8"', - 'Content-length: '.strlen($xml_post_string), - 'SOAPAction: WebServices/'.$method, - ]; - - // PHP cURL for connection - $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($ch, CURLOPT_URL, $this->apiUrl); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_TIMEOUT, 0); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - // execution - $response = curl_exec($ch); - if ($response === false) { - throw new \Exception(curl_error($ch), curl_errno($ch)); - $response .= "\nError occoured when connecting to the SMS SOAP Server!"; - $response .= "\nSoap Exception: ".$exception; - $response .= "\nSOAP Fault: (faultcode: {curl_errno($ch)}, faultstring: {curl_error($ch)})"; - Log::error('CURL reported error: ', $response); + $sendTransfer = $this->sendTransaction($input); + if ($sendTransfer['CODE'] == 0) { + $sendTransfer['status_code'] = 200; + $authorizedConfirmed = $this->authorizedConfirmed($sendTransfer); + } else { + $authorizedConfirmed = [ + 'MESSAGE' => 'Transaction Error', + 'CODE' => '3007', + ]; } - curl_close($ch); - $response1 = str_replace('', '', $response); - $response2 = str_replace('', '', $response1); - $response = str_replace('xmlns="WebServices"', '', $response2); - return simplexml_load_string($response); + return (object) array_merge($sendTransfer, $authorizedConfirmed); } /** - * @return string + * After Successful calling GetExRate method, call this function to send transaction. + * While sending Transaction if Customer already exists, it will update the existing Customer. + * If theCustomer is new, the SendTransaction method Auto-creates new Customer based on Sender_ID_Type and + * Sender_ID_Number(these information will be unique to identify Customer) + * + * The Authorized_Confirmed method has to be called within 30 minutes of SendTransaction + * + * @return mixed + * + * @throws Exception */ - public function xmlGenerate($string, $method) + public function sendTransaction($input_data) { - $xml_string = ' - - - <'.$method.' xmlns="WebServices"> - '.$string.' - - - + //dd($input_data); + $location_id = $input_data->valyou_location_routing_id[0]->bank_branch_location_field_value; + $AGENT_TXNID = $input_data->purchase_number; + $SENDER_FIRST_NAME = $input_data->sender_first_name; + $SENDER_MIDDLE_NAME = ''; + $SENDER_LAST_NAME = ''; + $SENDER_GENDER = $input_data->sender_gender; + $SENDER_ADDRESS = $input_data->sender_address; + $SENDER_CITY = $input_data->sender_city; + $SENDER_STATES = $input_data->sender_states; + $SENDER_ZIPCODE = $input_data->sender_zipcode; + $SENDER_COUNTRY = $input_data->sender_country; + $SENDER_MOBILE = $input_data->sender_mobile; + $SENDER_NATIONALITY = $input_data->sender_nationality; + $SENDER_ID_TYPE = $input_data->sender_id_type; + $SENDER_ID_NUMBER = $input_data->sender_id_number; + $SENDER_ID_ISSUE_COUNTRY = $input_data->sender_id_issue_country; + $SENDER_ID_ISSUE_DATE = date('Y-m-d', strtotime($input_data->sender_id_issue_date)); + $SENDER_ID_EXPIRE_DATE = date('Y-m-d', strtotime($input_data->sender_expire_date)); + $SENDER_DATE_OF_BIRTH = date('Y-m-d', strtotime($input_data->sender_date_of_birth)); + $SENDER_OCCUPATION = $input_data->sender_occupation; + $SENDER_SOURCE_OF_FUND = $input_data->sender_source_of_fund; + $SENDER_COUNTRY_OF_BIRTH = $input_data->sender_country_of_birth; + $SENDER_BENEFICIARY_RELATIONSHIP = $input_data->sender_beneficiary_relationship; + //$PURPOSE_OF_REMITTANCE = $input_data->purpose_of_remittance; + $PURPOSE_OF_REMITTANCE = 'FAMILY MAINTENANCE/SAVINGS'; + $RECEIVER_FIRST_NAME = $input_data->receiver_first_name; + $RECEIVER_MIDDLE_NAME = ''; //$input_data->receiver_middle_name; + $RECEIVER_LAST_NAME = $input_data->receiver_last_name; + $RECEIVER_ADDRESS = $input_data->receiver_address; + $RECEIVER_CONTACT_NUMBER = ''; //$input_data->receiver_contact_number; + $RECEIVER_COUNTRY = $input_data->receiver_country; + $RECEIVER_CITY = $input_data->receiver_country; + $TRANSFER_AMOUNT = $input_data->transfer_amount; + $REMIT_CURRENCY = ''; //$input_data->sender_currency; + $TRANSFER_CURRENCY = $input_data->transfer_currency; + $BANK_NAME = $input_data->valyou_bank_name; + $BANK_BRANCH_NAME = $input_data->valyou_bank_branch_name; + if ($TRANSFER_CURRENCY == 'INR') { + $BANK_BRANCH_NAME = $input_data->valyou_location_routing_id[1]->bank_branch_location_field_value; + } + $BANK_ACCOUNT_NUMBER = $input_data->bank_account_number; + if ($input_data['recipient_type_name'] == 'Cash') { + $location_id = is_null($input_data['location_id']) ? $input_data['location_id'] : '96700015P39319013P743723'; + $this->payment_mode = 'C'; + //$this->calculated_by_sending_payout_currency = 'C'; + } elseif ($input_data['recipient_type_name'] == 'Wallet') { + $location_id = is_null($input_data['location_id']) ? $input_data['location_id'] : '96700241P96836978'; + } + $signature = $this->agent_code.$this->ClientId.$this->agent_session_id.$AGENT_TXNID.$location_id. + $SENDER_FIRST_NAME.$SENDER_MIDDLE_NAME.$SENDER_LAST_NAME.$SENDER_GENDER. + $SENDER_ADDRESS.$SENDER_CITY.$SENDER_STATES.$SENDER_ZIPCODE.$SENDER_COUNTRY.$SENDER_MOBILE. + $SENDER_NATIONALITY.$SENDER_ID_TYPE.$SENDER_ID_NUMBER.$SENDER_ID_ISSUE_COUNTRY.$SENDER_ID_ISSUE_DATE. + $SENDER_ID_EXPIRE_DATE.$SENDER_DATE_OF_BIRTH.$SENDER_OCCUPATION.$SENDER_SOURCE_OF_FUND. + $SENDER_COUNTRY_OF_BIRTH.$SENDER_BENEFICIARY_RELATIONSHIP.$PURPOSE_OF_REMITTANCE. + $RECEIVER_FIRST_NAME.$RECEIVER_MIDDLE_NAME.$RECEIVER_LAST_NAME.$RECEIVER_ADDRESS. + $RECEIVER_CONTACT_NUMBER.$RECEIVER_CITY.$RECEIVER_COUNTRY. + $this->calculated_by_sending_payout_currency.$TRANSFER_AMOUNT.$REMIT_CURRENCY. + $TRANSFER_CURRENCY.$this->payment_mode.$BANK_NAME.$BANK_BRANCH_NAME.$BANK_ACCOUNT_NUMBER.$this->ClientPass; + $hash_signature = hash('sha256', $signature); + $xml_string = ' + '.$this->agent_code.' + '.$this->ClientId.' + '.$this->agent_session_id.' + '.$AGENT_TXNID.' + '.$location_id.' + '.$SENDER_FIRST_NAME.' + + + '.$SENDER_GENDER.' + '.$SENDER_ADDRESS.' + '.$SENDER_CITY.' + '.$SENDER_STATES.' + '.$SENDER_ZIPCODE.' + '.$SENDER_COUNTRY.' + '.$SENDER_MOBILE.' + '.$SENDER_NATIONALITY.' + '.$SENDER_ID_TYPE.' + '.$SENDER_ID_NUMBER.' + '.$SENDER_ID_ISSUE_COUNTRY.' + '.$SENDER_ID_ISSUE_DATE.' + '.$SENDER_ID_EXPIRE_DATE.' + '.$SENDER_DATE_OF_BIRTH.' + '.$SENDER_OCCUPATION.' + '.$SENDER_SOURCE_OF_FUND.' + + + '.$SENDER_COUNTRY_OF_BIRTH.' + '.$SENDER_BENEFICIARY_RELATIONSHIP.' + '.$PURPOSE_OF_REMITTANCE.' + '.$RECEIVER_FIRST_NAME.' + '.$RECEIVER_MIDDLE_NAME.' + '.$RECEIVER_LAST_NAME.' + '.$RECEIVER_ADDRESS.' + '.$RECEIVER_CONTACT_NUMBER.' + '.$RECEIVER_CITY.' + '.$RECEIVER_COUNTRY.' + + + '.$this->calculated_by_sending_payout_currency.' + '.$TRANSFER_AMOUNT.' + '.$REMIT_CURRENCY.' + '.$TRANSFER_CURRENCY.' + '.$this->payment_mode.' + '.$BANK_NAME.' + '.$BANK_BRANCH_NAME.' + '.$BANK_ACCOUNT_NUMBER.' + + '.$hash_signature.' + '; + $soapMethod = 'SendTransaction'; + $xml_post_string = $this->xmlGenerate($xml_string, $soapMethod); + $response = $this->connectionCheck($xml_post_string, $soapMethod); + Log::info(json_decode(json_encode($response->SendTransactionResponse->SendTransactionResult), true)); - return $xml_string; + return json_decode(json_encode($response->SendTransactionResponse->SendTransactionResult), true); } /** - * @return object + * Call this method to Commit Transaction. + * After SendTransaction, you must call Authorized_Confirmed to make transaction available. + * Session will be expired in 30 mins. + * All those transactions which are not Authorized, will be truncated from system at End of Day. + * + * @return mixed * - * @throws \Exception + * @throws Exception */ - public function topUp($input) + public function authorizedConfirmed($input_data) { - $sendTransfer = $this->sendTransaction($input); - if ($sendTransfer['CODE'] == 0) { - $sendTransfer['status_code'] = 200; - $authorizedConfirmed = $this->authorizedConfirmed($sendTransfer); - } else { - $authorizedConfirmed = [ - 'MESSAGE' => 'Transaction Error', - 'CODE' => '3007', - ]; - } + $PINNO = $input_data['PINNO']; + $signature = $this->agent_code.$this->ClientId.$PINNO.$this->agent_session_id.$this->ClientPass; + $hash_signature = hash('sha256', $signature); + $xml_string = ' + '.$this->agent_code.' + '.$this->ClientId.' + '.$PINNO.' + '.$this->agent_session_id.' + '.$hash_signature.' + '; + $soapMethod = 'Authorized_Confirmed'; + $xml_post_string = $this->xmlGenerate($xml_string, $soapMethod); + $response = $this->connectionCheck($xml_post_string, $soapMethod); + Log::info(json_decode(json_encode($response->Authorized_ConfirmedResponse->Authorized_ConfirmedResult), true)); - return (object) array_merge($sendTransfer, $authorizedConfirmed); + return json_decode(json_encode($response->Authorized_ConfirmedResponse->Authorized_ConfirmedResult), true); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 0a5e12d..6cd7f06 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,6 +8,16 @@ class TestCase extends Orchestra { + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + /* + $migration = include __DIR__.'/../database/migrations/create_remit_table.php.stub'; + $migration->up(); + */ + } + protected function setUp(): void { parent::setUp(); @@ -23,14 +33,4 @@ protected function getPackageProviders($app) RemitServiceProvider::class, ]; } - - public function getEnvironmentSetUp($app) - { - config()->set('database.default', 'testing'); - - /* - $migration = include __DIR__.'/../database/migrations/create_remit_table.php.stub'; - $migration->up(); - */ - } }