diff --git a/composer.json b/composer.json index 12c7cd80c..e05761cf5 100644 --- a/composer.json +++ b/composer.json @@ -109,7 +109,8 @@ "Sarga\\Shop\\": "packages/Sarga/Shop/src", "Sarga\\API\\": "packages/Sarga/API", "Sarga\\Admin\\": "packages/Sarga/Admin/src", - "Sarga\\Brand\\": "packages/Sarga/Brand/src" + "Sarga\\Brand\\": "packages/Sarga/Brand/src", + "Sarga\\Payment\\": "packages/Sarga/Payment" } }, "autoload-dev": { diff --git a/config/app.php b/config/app.php index 5039b8835..d91f2f1f3 100755 --- a/config/app.php +++ b/config/app.php @@ -282,6 +282,7 @@ return [ Sarga\API\Providers\APIServiceProvider::class, Sarga\Admin\Providers\AdminServiceProvider::class, Sarga\Brand\Providers\BrandServiceProvider::class, + Sarga\Payment\Providers\PaymentServiceProvider::class, ], /* diff --git a/packages/Sarga/API/Http/Resources/Catalog/Product.php b/packages/Sarga/API/Http/Resources/Catalog/Product.php index bf64caba8..0ce77aa41 100644 --- a/packages/Sarga/API/Http/Resources/Catalog/Product.php +++ b/packages/Sarga/API/Http/Resources/Catalog/Product.php @@ -69,12 +69,32 @@ class Product extends JsonResource $this->merge($this->specialPriceInfo()), /* super attributes */ -// $this->mergeWhen($productTypeInstance->isComposite(), [ -// 'super_attributes' => Attribute::collection($product->super_attributes), -// ]), + $this->mergeWhen($productTypeInstance->isComposite(), [ + 'super_attributes' => $this->super_attributes, + ]), ]; } + private function super_attributes(){ + if(is_countable($this->super_attributes)){ + return $this->super_attributes->map(function($item, $key){ + return [ + 'code' => $item->code, + 'value' => $this->{$item->code}, + 'name' => $item->name, + 'label' => $item->options->where('id',$this->{$item->code})->first()->admin_name + ]; + })->toArray(); + }else{ + $item = $this->super_attributes; + return [ + 'code' => $item->code, + 'value' => $this->{$item->code}, + 'name' => $item->name, + 'label' => $item->options->where('id',$this->{$item->code})->first()->admin_name + ]; + } + } /** * Get special price information. * diff --git a/packages/Sarga/Payment/Config/paymentmethods.php b/packages/Sarga/Payment/Config/paymentmethods.php new file mode 100644 index 000000000..2a9d7ae14 --- /dev/null +++ b/packages/Sarga/Payment/Config/paymentmethods.php @@ -0,0 +1,29 @@ + [ +// 'code' => 'terminal', +// 'title' => 'Terminal', +// 'description' => 'Card On Delivery', +// 'class' => 'Payment\Methods\Terminal', +// 'active' => true, +// 'sort' => 3, +// ], + 'altynasyr' =>[ + 'code' => 'altynasyr', + 'title' => 'Altyn Asyr', + 'description' => 'Altyn Asyr Kartly Töleg', + 'api_url' => 'https://mpi.gov.tm/payment/rest/', + 'class' => 'Payment\Methods\AltynAsyr', + 'active' => false, + 'sort' => 4 + ], + 'tfeb' =>[ + 'code' => 'tfeb', + 'title' =>'TFEB', + 'description' => 'THE STATE BANK FOR FOREIGN ECONOMIC AFFAIRS OF TURKMENISTAN', + 'api_url' => 'https://ecomt.tfeb.gov.tm/v1/orders/', + 'class' => 'Payment\Methods\TFEB', + 'active' => false, + 'sort' => 5 + ] +]; \ No newline at end of file diff --git a/packages/Sarga/Payment/Config/system.php b/packages/Sarga/Payment/Config/system.php new file mode 100644 index 000000000..de801c2df --- /dev/null +++ b/packages/Sarga/Payment/Config/system.php @@ -0,0 +1,181 @@ + 'sales.paymentmethods.terminal', +// 'name' => 'Terminal', +// 'sort' => 3, +// 'fields' => [ +// [ +// 'name' => 'title', +// 'title' => 'admin::app.admin.system.title', +// 'type' => 'depends', +// 'depend' => 'active:1', +// 'validation' => 'required_if:active,1', +// 'channel_based' => true, +// 'locale_based' => true, +// ], [ +// 'name' => 'description', +// 'title' => 'admin::app.admin.system.description', +// 'type' => 'textarea', +// 'channel_based' => true, +// 'locale_based' => true, +// ], [ +// 'name' => 'instructions', +// 'title' => 'admin::app.admin.system.instructions', +// 'type' => 'textarea', +// 'channel_based' => true, +// 'locale_based' => true, +// ], [ +// 'name' => 'generate_invoice', +// 'title' => 'admin::app.admin.system.generate-invoice', +// 'type' => 'boolean', +// 'default_value' => false, +// 'channel_based' => true, +// 'locale_based' => false, +// ], [ +// 'name' => 'invoice_status', +// 'title' => 'admin::app.admin.system.set-invoice-status', +// 'validation' => 'required_if:generate_invoice,1', +// 'type' => 'select', +// 'options' => [ +// [ +// 'title' => 'admin::app.sales.invoices.status-pending', +// 'value' => 'pending', +// ], [ +// 'title' => 'admin::app.sales.invoices.status-paid', +// 'value' => 'paid', +// ], +// ], +// 'info' => 'admin::app.admin.system.generate-invoice-applicable', +// 'channel_based' => true, +// 'locale_based' => false, +// ], [ +// 'name' => 'order_status', +// 'title' => 'admin::app.admin.system.set-order-status', +// 'type' => 'select', +// 'options' => [ +// [ +// 'title' => 'admin::app.sales.orders.order-status-pending', +// 'value' => 'pending', +// ], [ +// 'title' => 'admin::app.sales.orders.order-status-pending-payment', +// 'value' => 'pending_payment', +// ], [ +// 'title' => 'admin::app.sales.orders.order-status-processing', +// 'value' => 'processing', +// ], +// ], +// 'info' => 'admin::app.admin.system.generate-invoice-applicable', +// 'channel_based' => true, +// 'locale_based' => false, +// ], [ +// 'name' => 'active', +// 'title' => 'admin::app.admin.system.status', +// 'type' => 'boolean', +// 'validation' => 'required', +// 'channel_based' => true, +// 'locale_based' => true, +// ], [ +// 'name' => 'sort', +// 'title' => 'admin::app.admin.system.sort_order', +// 'type' => 'select', +// 'options' => [ +// [ +// 'title' => '1', +// 'value' => 1, +// ], [ +// 'title' => '2', +// 'value' => 2, +// ], [ +// 'title' => '3', +// 'value' => 3, +// ], [ +// 'title' => '4', +// 'value' => 4, +// ], +// ], +// ], +// ], +// ], + [ + 'key' => 'sales.paymentmethods.altynasyr', + 'name' => 'admin::app.admin.system.altyn-asyr', + 'sort' => 4, + 'fields' => [ + [ + 'name' => 'title', + 'title' => 'admin::app.admin.system.title', + 'type' => 'text', + 'validation' => 'required', + 'locale_based' => true + ], [ + 'name' => 'description', + 'title' => 'admin::app.admin.system.description', + 'type' => 'textarea', + 'locale_based' => true + ], [ + 'name' => 'business_account', + 'title' => 'admin::app.admin.system.business-account', + 'type' => 'text', + 'validation' => 'required' + ],[ + 'name' => 'account_password', + 'title' => 'admin::app.account.password', + 'type' => 'password', + 'validation' => 'required' + ], [ + 'name' => 'active', + 'title' => 'admin::app.admin.system.status', + 'type' => 'boolean', + 'validation' => 'required', + + ] + ] + ], + [ + 'key' => 'sales.paymentmethods.tfeb', + 'name' => 'TFEB', + 'sort' => 5, + 'fields' => [ + [ + 'name' => 'title', + 'title' => 'admin::app.admin.system.title', + 'type' => 'text', + 'validation' => 'required', + 'locale_based' => true + ], [ + 'name' => 'description', + 'title' => 'admin::app.admin.system.description', + 'type' => 'textarea', + 'locale_based' => true + ], [ + 'name' => 'client_id', + 'title' => 'ClientID', + 'type' => 'text', + 'validation' => 'required' + ],[ + 'name' => 'client_secret', + 'title' => 'Client Secret', + 'type' => 'text', + 'validation' => 'required' + ],[ + 'name' => 'merchant', + 'title' => 'Merchant', + 'type' => 'text', + 'validation' => 'required' + ],[ + 'name' => 'terminal', + 'title' => 'Terminal', + 'type' => 'text', + 'validation' => 'required' + ], [ + 'name' => 'active', + 'title' => 'admin::app.admin.system.status', + 'type' => 'boolean', + 'validation' => 'required', + + ] + ] + ] +]; \ No newline at end of file diff --git a/packages/Sarga/Payment/Database/migrations/2019_07_27_142343_add_order_id_to_cart_payment_table.php b/packages/Sarga/Payment/Database/migrations/2019_07_27_142343_add_order_id_to_cart_payment_table.php new file mode 100644 index 000000000..c43904402 --- /dev/null +++ b/packages/Sarga/Payment/Database/migrations/2019_07_27_142343_add_order_id_to_cart_payment_table.php @@ -0,0 +1,35 @@ +string('order_id')->nullable(); +// $table->unsignedSmallInteger('OrderStatus')->nullable(); + // + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('cart_payment', function (Blueprint $table) { + $table->dropColumn('order_id'); +// $table->dropColumn('OrderStatus'); + }); + } +} diff --git a/packages/Sarga/Payment/Http/Controllers/AltynAsyrController.php b/packages/Sarga/Payment/Http/Controllers/AltynAsyrController.php new file mode 100644 index 000000000..2e5db65a5 --- /dev/null +++ b/packages/Sarga/Payment/Http/Controllers/AltynAsyrController.php @@ -0,0 +1,106 @@ +orderRepository = $orderRepository; + $this->altynAsyr = $altynAsyr; + } + + /** + * Redirects to payment gateway + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function redirect(){ + // register order to payment gateway + try{ + $result = $this->altynAsyr->registerOrder(); + if($result['errorCode'] == 0){ +// dd($result); + $this->altynAsyr->registerOrderId($result['orderId']); + return redirect($result['formUrl']); + } + else{//if already registered or otkazana w dostupe + //todo log + session()->flash('error', $result['errorMessage']); + } + + }catch (\Exception $exception){ + //todo Check exception if not connection excepion redirect to login ore somewhere if session expired + session()->flash('error', $exception->getMessage()); + } + + return redirect()->route('shop.checkout.cart.index'); + } + + /** + * Success payment + * + * @return \Illuminate\Http\RedirectResponse + */ + public function success(){ + try { + $result = $this->altynAsyr->getOrderStatus(); + + if ($result['ErrorCode'] == 0) { + if ($result['OrderStatus'] == 2) { + $order = $this->orderRepository->create(Cart::prepareDataForOrder()); + //todo save card details to cart->payment + Cart::deActivateCart(); + + session()->flash('order', $order); + + return redirect()->route('shop.checkout.success'); + } else { + return view('payment::order-status')->with('cart', $this->altynAsyr->getCart()); + } + + } else { + session()->flash('error', trans('payment.unsuccessfull')); + } + } + catch (ConnectException $connectException){ + session()->flash('error',trans('payment::messages.connection_failed')); + } + catch (\Exception $exception){ + session()->flash('error',trans('payment::messages.session_expired')); + } + return redirect()->route('shop.checkout.cart.index'); + } + + /** + * Cancel payment from gateway + * + * @return \Illuminate\Http\RedirectResponse + */ + public function cancel(){ + session()->flash('error', trans('payment::messages.unsuccessfull')); + + return redirect()->route('shop.checkout.cart.index'); + } + + public function status(){ + + return view('payment::order-status'); + } +} diff --git a/packages/Sarga/Payment/Http/Controllers/Controller.php b/packages/Sarga/Payment/Http/Controllers/Controller.php new file mode 100644 index 000000000..8163dc6e2 --- /dev/null +++ b/packages/Sarga/Payment/Http/Controllers/Controller.php @@ -0,0 +1,17 @@ +guard = request()->has('token') ? 'api' : 'customer'; + + auth()->setDefaultDriver($this->guard); + +// $this->middleware('auth:' . $this->guard); + + $this->orderRepository = $orderRepository; + $this->teb = $teb; + } + + /** + * Redirects to payment gateway + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function redirect(){ + // register order to payment gateway + try{ + $result = json_decode($this->teb->registerOrder(),true); + Log::info($result); + if($result['response']['operationResult'] == 'OPG-00100' && $orderId = $result['response']['orderId']){ +// dd($result); + $this->teb->registerOrderId($orderId); + return request()->has('token') ? response()->json(['status' => true, 'redirect_url' => $result['_links']['redirectToCheckout']['href']]): + redirect($result['_links']['redirectToCheckout']['href']); + } + else{//if already registered or otkazana w dostupe + //todo log + if(request()->has('token')){ + return response()->json([ + 'status' => false, + 'message' => $result['response']['operationResultDescription'] + ]); + } + session()->flash('error', $result['response']['operationResultDescription']); + } + + }catch (\Exception $exception){ + //todo Check exception if not connection excepion redirect to login ore somewhere if session expired + Log::error($exception); + + if(request()->has('token')){ + return response()->json([ + 'status' => false, + 'message' => $exception->getMessage() + ]); + + } + + session()->flash('error', $exception->getMessage()); + } + + return redirect()->route('shop.checkout.cart.index'); + } + + /** + * Success payment + * + * @return \Illuminate\Http\RedirectResponse + */ + public function complete(){ + try { + $result = json_decode($this->teb->getOrderStatus(),true); + + if ($result['response']['operationResult'] == 'GEN-00000') { + $order = $this->orderRepository->create(Cart::prepareDataForOrder()); + //todo save card details to cart->payment + Cart::deActivateCart(); + + session()->flash('order', $order); + + return redirect()->route('shop.checkout.success'); + + } else { + + session()->flash('error', trans('payment.unsuccessfull')); + } + } + catch (ConnectException $connectException){ + + session()->flash('error',trans('payment::messages.connection_failed')); + } + catch (\Exception $exception){ + Log::error($exception); + + session()->flash('error',$exception->getMessage()); + } + return redirect()->route('shop.checkout.cart.index'); + } + + /** + * Cancel payment from gateway + * + * @return \Illuminate\Http\RedirectResponse + */ + public function cancel(){ + session()->flash('error', trans('payment::messages.unsuccessfull')); + + return redirect()->route('shop.checkout.cart.index'); + } + + public function status(){ + + return view('payment::order-status'); + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Http/Resoures/Payment/Browser.php b/packages/Sarga/Payment/Http/Resoures/Payment/Browser.php new file mode 100644 index 000000000..0f9a122ff --- /dev/null +++ b/packages/Sarga/Payment/Http/Resoures/Payment/Browser.php @@ -0,0 +1,29 @@ + "*/*", + "IpAddress" => "10.33.27.3", + "Language" => "ru-RU", + "ScreenColorDepth" => 48, + "ScreenHeight" => 1200, + "ScreenWidth" => 1900, + "UserAgentString" => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.3" + ]; + } + +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Http/Resoures/Payment/Card.php b/packages/Sarga/Payment/Http/Resoures/Payment/Card.php new file mode 100644 index 000000000..b510bc6b5 --- /dev/null +++ b/packages/Sarga/Payment/Http/Resoures/Payment/Card.php @@ -0,0 +1,26 @@ + "6015840000000843", + "ExpiryDate" => "2401", + "SecurityCode2" => "725", + "Name" => "John Doe", + "TAVV" => null, + "IsCardOnFile" => false + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Http/Resoures/Payment/CartAddress.php b/packages/Sarga/Payment/Http/Resoures/Payment/CartAddress.php new file mode 100644 index 000000000..cd0a7faff --- /dev/null +++ b/packages/Sarga/Payment/Http/Resoures/Payment/CartAddress.php @@ -0,0 +1,21 @@ + true, + "Line1"=> 'L1:'.substr($this->address1,0,47),//Line1 must be max 50 chars + "Line2"=> 'L2:'.substr($this->address2,0,47), + "PostCode"=> "74000", + "City"=> "01", + "CountrySubdivision"=> "01", + "Country"=> "196" + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Http/Resoures/Payment/Cusromer.php b/packages/Sarga/Payment/Http/Resoures/Payment/Cusromer.php new file mode 100644 index 000000000..1af057a21 --- /dev/null +++ b/packages/Sarga/Payment/Http/Resoures/Payment/Cusromer.php @@ -0,0 +1,33 @@ + $this->name, + "Language" => "en-US", + "Email" => $this->phone.'@ozan.com.tm', + "HomePhone" => [ + "cc" => "993", + "subscriber" => $this->phone + ], + "MobilePhone" => [ + "cc" => "993", + "subscriber" => $this->phone + ], + "WorkPhone" => null + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Http/Resoures/Payment/Order.php b/packages/Sarga/Payment/Http/Resoures/Payment/Order.php new file mode 100644 index 000000000..073af87be --- /dev/null +++ b/packages/Sarga/Payment/Http/Resoures/Payment/Order.php @@ -0,0 +1,106 @@ +getConfigData('sales.paymentmethods.tfeb.' . $field); + } + + public function toArray($request){ + return [ + "RequestId" => $this->id, + "Environment" => [ + "Merchant" => [ + "Id" =>$this->getConfigData('merchant') + ], + "POI" => [ + "Id" => $this->getConfigData('terminal'), + "Language" => "en-US" + ], + "Transport" => [ + "MerchantFinalResponseUrl" => route('paymentmethod.tfeb.complete',['uid'=>auth()->user()->id]), + "ChallengeResponseUrl" => route('paymentmethod.tfeb.complete',['uid'=>auth()->user()->id]), + "ChallengeWindowSize" => 3, + "ChallengeResponseData"=> null, + "ThreeDSMethodNotificationUrl"=> "", + "MethodCompletion"=> false, + "Consent" => false, + "EndpointHostAddress" => "/orders/7b72093d-bb14-45b5-a6ec-a3ca5f6c2731" + ], + "SponsoredMerchant"=> null, + "SponsoredMerchantPOI"=> null, + "Card" => null, + "CardRecipient"=> null, + "Customer" => [ + "Name" => $this->customer_first_name, + "Language" => "en-US", + "Email" => $this->customer_email.'@ozan.com.tm', + "HomePhone" => [ + "cc" => "993", + "subscriber" => $this->customer_email + ], + "MobilePhone" => [ + "cc" => "993", + "subscriber" => $this->customer_email + ], + "WorkPhone" => null + ], + + "CustomerDevice" => [ + "Browser" => [ + "AcceptHeader" => "*/*", + "IpAddress" => request()->ip(), + "Language" => "en-US", + "ScreenColorDepth" => 48, + "ScreenHeight" => 1200, + "ScreenWidth" => 1900, + "UserAgentString" => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.3" + ], + "MobileApp" => null, + ], + 'BillingAddress' => CartAddress::make($this->billing_address), + 'ShippingAddress' => CartAddress::make($this->shipping_address), + + ], + "Transaction" => [ + "InvoiceNumber" => "Acquirer", + "Type" => "CRDP", + "AdditionalService" => null, + "TransactionText" => "ozan online sowda", + "TotalAmount" => (double)$this->grand_total, + "Currency" => "934", + "CurrencyConversion"=> null, + "DetailedAmount"=> null, + "AirlineItems"=> null, + "MerchantOrderId" => $this->id, + "AutoComplete" => true, + "Instalment"=> null, + "MerchantCategoryCode"=> null, + "AntiMoneyLaundering"=> [ + "SenderName"=> $this->customer_first_name, + "SenderDateOfBirth"=> null, + "SenderPlaceOfBirth"=> null, + "NationalIdentifier"=> null, + "NationalIdentifierCountry"=> null, + "NationalIdentifierExpiry"=> null, + "PassportNumber"=> "123-456", + "PassportIssuingCountry"=> null, + "PassportExpiry"=> "20291/12/01" + ], + ] + ]; + } +} diff --git a/packages/Sarga/Payment/Http/routes.php b/packages/Sarga/Payment/Http/routes.php new file mode 100644 index 000000000..290bbf309 --- /dev/null +++ b/packages/Sarga/Payment/Http/routes.php @@ -0,0 +1,31 @@ +'payment','middleware' => ['web', 'locale', 'theme', 'currency']], function () +{ + Route::get('altynasyr/redirect', [AltynAsyrController::class,'redirect']) + ->name('paymentmethod.altynasyr.redirect'); + + Route::get('altynasyr/success', [AltynAsyrController::class,'success']) + ->name('paymentmethod.altynasyr.success'); + + Route::get('altynasyr/cancel', [AltynAsyrController::class,'cancel']) + ->name('paymentmethod.altynasyr.cancel'); + + Route::get('tfeb/redirect',[TFEBController::class,'redirect']) + ->name('paymentmethod.tfeb.redirect'); + + Route::get('tfeb/complete', [TFEBController::class,'complete']) + ->name('paymentmethod.tfeb.complete'); + + Route::get('tfeb/cancel', [TFEBController::class,'cancel']) + ->name('paymentmethod.tfeb.cancel'); +}); \ No newline at end of file diff --git a/packages/Sarga/Payment/Methods/AltynAsyr.php b/packages/Sarga/Payment/Methods/AltynAsyr.php new file mode 100644 index 000000000..6f280050f --- /dev/null +++ b/packages/Sarga/Payment/Methods/AltynAsyr.php @@ -0,0 +1,89 @@ + $this->getConfigData('api_url'), + 'connect_timeout' => 10,//sec + 'timeout' => 10,//sec + 'verify' => true, + ]); + } + + public function isRegistered(){ + $payment = $this->getCart()->payment; + return (!empty($payment) && !empty($payment->orderId)); + } + + public function registerOrder(){ + + $cart = $this->getCart(); + $lifeTime = config('session.lifetime',10);//10 minutes + + $client = $this->getApiClient(); + + + $params =[ + 'form_params' => [ + 'userName' => $this->getConfigData('business_account'),//'103161020074', + 'password' => $this->getConfigData('account_password'),//'E12wKp7a7vD8', + 'sessionTimeoutSecs' => $lifeTime * 30, //(600 sec) + 'orderNumber' =>$cart->id . Carbon::now()->timestamp, + 'currency' => 934, + 'language' => 'ru', + 'description'=> "bagisto multivendor {$cart->grand_total}m.", + 'amount' =>$cart->grand_total * 100,// amount w kopeykah + 'returnUrl' => route('paymentmethod.altynasyr.success'), + 'failUrl' => route('paymentmethod.altynasyr.cancel') + ], + ]; + + return json_decode($client->post('register.do',$params)->getBody(),true); + + } + + public function registerOrderId($orderId){ + $payment = $this->getCart()->payment; + $payment->order_id = $orderId; +// dd($payment); +// $payment->paymentFormUrl = $formUrl; + $payment->save(); + } + + public function getOrderStatus(){ + $client = $this->getApiClient(); + $payment = $this->getCart()->payment; + + $params = [ + 'form_params' => [ + 'userName' => $this->getConfigData('business_account'),//'103161020074', + 'password' => $this->getConfigData('account_password'),//'E12wKp7a7vD8', + 'orderId' => $payment->order_id, + ] + ]; + + return json_decode($client->post('getOrderStatus.do',$params)->getBody(),true); + + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Methods/TFEB.php b/packages/Sarga/Payment/Methods/TFEB.php new file mode 100644 index 000000000..9a2f5359d --- /dev/null +++ b/packages/Sarga/Payment/Methods/TFEB.php @@ -0,0 +1,73 @@ + $this->getConfigData('api_url'), + 'connect_timeout' => 55,//sec + 'timeout' => 55,//sec + 'verify' => false, + 'headers' =>[ + 'ClientId' => $this->getConfigData('client_id'), + 'ClientSecret' => $this->getConfigData('client_secret'), + 'Accept' => "application/hal+json", + "Content-Type" => 'application/json' + ], + ]); + } + + public function registerOrder(){ + + $client = $this->getApiClient(); + $cart_order = new Order($this->getCart()); + $body = $cart_order->toJson(); + $params =[ + 'body' => $body + ]; + + return $client->post('',$params)->getBody(); + + } + + public function getRedirectUrl() + { + return route('paymentmethod.tfeb.redirect'); + } + + public function isRegistered(){ + $payment = $this->getCart()->payment; + return (!empty($payment) && !empty($payment->orderId)); + } + + public function getOrderStatus(){ + $client = $this->getApiClient(); + $payment = $this->getCart()->payment; + + return $client->get($payment->order_id)->getBody(); + } + + public function registerOrderId($orderId){ + $payment = $this->getCart()->payment; + $payment->order_id = $orderId; +// dd($payment); +// $payment->paymentFormUrl = $formUrl; + $payment->save(); + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Methods/Terminal.php b/packages/Sarga/Payment/Methods/Terminal.php new file mode 100644 index 000000000..548514400 --- /dev/null +++ b/packages/Sarga/Payment/Methods/Terminal.php @@ -0,0 +1,20 @@ +loadRoutesFrom(__DIR__ . '/../Http/routes.php'); + $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'payment'); + $this->loadMigrationsFrom(__DIR__ . '/../Database/migrations'); + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'payment'); + } + public function register() + { + $this->mergeConfigFrom( + dirname(__DIR__) . '/Config/paymentmethods.php', 'paymentmethods' + ); + $this->mergeConfigFrom( + dirname(__DIR__) . '/Config/system.php', 'core' + ); + } +} \ No newline at end of file diff --git a/packages/Sarga/Payment/Resources/lang/en/messages.php b/packages/Sarga/Payment/Resources/lang/en/messages.php new file mode 100644 index 000000000..95853800b --- /dev/null +++ b/packages/Sarga/Payment/Resources/lang/en/messages.php @@ -0,0 +1,14 @@ + 'Insufficient balance or card credentials you supplied were not correct or did not grant access.', + 'connection_failed' => 'Unable to connect to bank service. Please try again later!.', + 'session_expired' => 'Session expired please try again later.', + 'processing_payment' => 'Your payment is being processed... Please press the refresh button if page doesnt refreshes', + 'refresh' => 'Refresh' +]; \ No newline at end of file diff --git a/packages/Sarga/Payment/Resources/lang/ru/messages.php b/packages/Sarga/Payment/Resources/lang/ru/messages.php new file mode 100644 index 000000000..0cd8a69a5 --- /dev/null +++ b/packages/Sarga/Payment/Resources/lang/ru/messages.php @@ -0,0 +1,14 @@ + 'Недостаточный баланс или учетные данные карты, которые вы указали, были неверными или не давали доступа.', + 'connection_failed' => 'Невозможно подключиться к банковской услуге. Пожалуйста, повторите попытку позже!.', + 'session_expired' => 'Срок действия сеанса истек, повторите попытку позже.', + 'processing_payment' => 'Ваш платеж обрабатывается ... Нажмите кнопку "Обновить", если страница не обновляется.', + 'refresh' => 'Обновить' +]; \ No newline at end of file diff --git a/packages/Sarga/Payment/Resources/lang/tm/messages.php b/packages/Sarga/Payment/Resources/lang/tm/messages.php new file mode 100644 index 000000000..620033342 --- /dev/null +++ b/packages/Sarga/Payment/Resources/lang/tm/messages.php @@ -0,0 +1,14 @@ + 'Hasabyňyzda ýeterli serişde ýok. Ýa-da kart maglumatlaryňyz nädogry girizdiňiz', + 'connection_failed' => 'Bank bilen aragatnaşykda säwlik ýüze çykdy. Ýene birsalymdan täzeden synanşyp görmegiňizi haýş edýäris!', + 'session_expired' => 'Siziň sessiýaňyzyň wagty doldy', + 'processing_payment' => 'Siziň tölegiňiziň üstünde işlenilýär.... Egerde sahypa täzelenmese. Aşakdaky dügmä basmagyňyzy haýyş edýäris.', + 'refresh' => 'Täzele' +]; \ No newline at end of file diff --git a/packages/Sarga/Payment/Resources/views/order-status.blade.php b/packages/Sarga/Payment/Resources/views/order-status.blade.php new file mode 100644 index 000000000..578901ca2 --- /dev/null +++ b/packages/Sarga/Payment/Resources/views/order-status.blade.php @@ -0,0 +1,189 @@ +@extends('shop::layouts.master') + +@section('page_title') + {{ __('shop::app.checkout.onepage.title') }} +@stop + +@section('content-wrapper') + +
Some problem occured while connecting with your bank.Please try again later!
+RESPONSE : {{$message}}
+