From 7073408ce8ffb761e1cc8ffd3d6ec13b8e2d0646 Mon Sep 17 00:00:00 2001 From: Ferry Ariawan Date: Sun, 28 Aug 2016 21:26:47 +0700 Subject: [PATCH] Bug fix and Improve add payment available in configuration improve debug for repsonse in controller bug fixed in dokucontroller add new view for mandiri click pay --- src/Config/dokularavel.php | 30 ++-- src/Controllers/Controller.php | 14 +- src/Controllers/DokuController.php | 93 +++++++---- .../payment_form_mandiri_clickpay.blade.php | 146 ++++++++++++++++++ 4 files changed, 233 insertions(+), 50 deletions(-) create mode 100644 src/Views/payment_form_mandiri_clickpay.blade.php diff --git a/src/Config/dokularavel.php b/src/Config/dokularavel.php index 6ab2a07..3a6bcec 100644 --- a/src/Config/dokularavel.php +++ b/src/Config/dokularavel.php @@ -13,20 +13,6 @@ 'MALL_ID' => NULL, 'CURRENCY' => 360, - /* - | --------------------------------------------------------- - | DOKU PAYMENT AVAILABLE CHANNEL - | --------------------------------------------------------- - | 15 = Credit Card - | 04 = Doku Wallet - | 02 = Mandiri Clickpay - | 14 = ALFA - | - | This setting is for default payment channel otherwise you can set the payment channel on the fly by url parameter "payment_channel" - */ - 'DEFAULT_PAYMENT_CHANNEL'=> 15, - - /* | --------------------------------------------------------- | Define your table of order and the fields @@ -42,6 +28,22 @@ 'TABLE_FIELD_CUSTOMER_ADDRESS' => NULL, + /* + | --------------------------------------------------------- + | DOKU PAYMENT AVAILABLE CHANNEL + | --------------------------------------------------------- + | 15 = Credit Card + | 04 = Doku Wallet + | 02 = Mandiri Clickpay + | 05 = Permata VA Lite + | 14 = ALFA + | + | This setting is for default payment channel otherwise you can set the payment channel on the fly by url parameter "payment_channel" + */ + 'AVAILABLE_PAYMENT_CHANNEL'=> ['15','04','02','05','14'], + 'DEFAULT_PAYMENT_CHANNEL'=> '15', + + /* | --------------------------------------------------------- | This setting is for set the product name in doku transaction diff --git a/src/Controllers/Controller.php b/src/Controllers/Controller.php index fc85aee..a17bb7a 100644 --- a/src/Controllers/Controller.php +++ b/src/Controllers/Controller.php @@ -33,7 +33,7 @@ public function doPrePayment($data){ $responseJson = curl_exec( $ch ); - Cache::put('doPrePaymentRaw',$responseJson, 60); + Cache::put('doPrePaymentRaw',date('Y-m-d H:i:s').'--'.$responseJson, 3); curl_close($ch); @@ -53,7 +53,7 @@ public function doPayment($data){ $responseJson = curl_exec( $ch ); - Cache::put('doPaymentRaw',$responseJson, 60); + Cache::put('doPaymentRaw',date('Y-m-d H:i:s').'--'.$responseJson, 3); curl_close($ch); @@ -76,7 +76,7 @@ public function doDirectPayment($data){ $responseJson = curl_exec( $ch ); - Cache::put('doDirectPayment',$responseJson, 60); + Cache::put('doDirectPaymentRaw',date('Y-m-d H:i:s').'--'.$responseJson, 3); curl_close($ch); @@ -99,7 +99,7 @@ public function doGeneratePaycode($data){ $responseJson = curl_exec( $ch ); - Cache::put('doGeneratePaycodeRaw',$responseJson, 60); + Cache::put('doGeneratePaycodeRaw',date('Y-m-d H:i:s').'--'.$responseJson, 3); curl_close($ch); @@ -122,7 +122,7 @@ public function doRedirectPayment($data){ $responseJson = curl_exec( $ch ); - Cache::put('doRedirectPayment',$responseJson, 60); + Cache::put('doRedirectPayment',date('Y-m-d H:i:s').'--'.$responseJson, 3); curl_close($ch); @@ -145,7 +145,7 @@ public function doCapture($data){ $responseJson = curl_exec( $ch ); - Cache::put('doCapture',$responseJson, 60); + Cache::put('doCapture',date('Y-m-d H:i:s').'--'.$responseJson, 3); curl_close($ch); @@ -175,7 +175,7 @@ public function doCheckPaymentStatus($trans_id){ $responseXML = curl_exec( $ch ); - Cache::put('doPostCURL',$responseXML, 60); + Cache::put('doPostCURL',date('Y-m-d H:i:s').'--'.$responseXML, 3); curl_close($ch); diff --git a/src/Controllers/DokuController.php b/src/Controllers/DokuController.php index 3e78d56..a9f009a 100644 --- a/src/Controllers/DokuController.php +++ b/src/Controllers/DokuController.php @@ -27,7 +27,7 @@ class DokuController extends Controller { var $customer_phone; var $customer_email; var $customer_address; - var $payment_available = array('15','04','02','14'); + var $payment_available = array(); var $session_dokularavel = array(); var $product_name_format; var $show_doku_success_page; @@ -52,6 +52,7 @@ function __construct() { $this->show_doku_success_page = config('dokularavel.SHOW_DOKU_SUCCESS_PAGE'); $this->show_finish_page = config('dokularavel.SHOW_FINISH_PAGE'); $this->your_own_finish_page = config('dokularavel.YOUR_OWN_FINISH_PAGE'); + $this->payment_available = config('dokularavel.AVAILABLE_PAYMENT_CHANNEL'); if($this->show_finish_page) { if($this->your_own_finish_page) { @@ -91,7 +92,7 @@ function __construct() { 'trans_id' =>Request::get('trans_id'), 'payment_channel' =>$this->payment_channel, 'amount' =>preg_replace('/\D/', '', $query->{$this->table_field_amount}), - 'customer_name' =>preg_replace('/[^a-zA-Z]+/', '', $query->{$this->table_field_customer_name}), + 'customer_name' =>preg_replace('/[^a-zA-Z ]+/', '', $query->{$this->table_field_customer_name}), 'customer_phone' =>str_limit(preg_replace('/\D/', '', $query->{$this->table_field_customer_phone}), 12, ''), 'customer_email' =>$query->{$this->table_field_customer_email}, 'customer_address' =>$query->{$this->table_field_customer_address} @@ -164,7 +165,11 @@ public function index() { $hook = new \App\Http\Controllers\DokuLaravelHookController; $hook->beforePayment($data); - return view('dokularavel::payment_form',$data); + if($this->payment_channel == '02') { + return view('dokularavel::payment_form_mandiri_clickpay',$data); + }else{ + return view('dokularavel::payment_form',$data); + } } public function pay() { @@ -174,17 +179,18 @@ public function pay() { $token = Request::get('doku_token'); $pairing_code = Request::get('doku_pairing_code'); - $invoice_no = Request::get('doku_invoice_no'); - $amount = Request::get('doku_amount'); - $currency = Request::get('doku_currency'); - $chain = Request::get('doku_chain_merchant'); + $invoice_no = Request::get('doku_invoice_no')?:$this->invoice_no; + $amount = Request::get('doku_amount')?:$this->amount; + $currency = Request::get('doku_currency')?:$this->currency; + $chain = Request::get('doku_chain_merchant')?:'NA'; $customer_name = $this->customer_name; $customer_phone = $this->customer_phone; $customer_email = $this->customer_email; $customer_address = $this->customer_address; - if(!$token || !$pairing_code || !$invoice_no || !$amount || !$currency || !$chain || !$customer_name || !$customer_phone || !$customer_email || !$customer_address) { + + if(!$amount || !$currency || !$invoice_no || !$customer_name || !$customer_phone || !$customer_email || !$customer_address) { $param = Request::all(); $param['customer_name'] = $customer_name; $param['customer_phone'] = $customer_phone; @@ -198,10 +204,20 @@ public function pay() { $params = array( 'amount' => $amount, 'invoice' => $invoice_no, - 'currency' => $currency, - 'pairing_code' => $pairing_code, - 'token' => $token + 'currency' => $currency ); + + if($pairing_code) { + $params['pairing_code'] = $pairing_code; + } + + if($token) { + $params['token'] = $token; + } + + if($this->payment_channel == '02') { + unset($params['currency']); + } $words = $this->doCreateWords($params); $wordsRaw = $this->doCreateWordsRaw($params); @@ -218,15 +234,7 @@ public function pay() { 'data_phone' => $customer_phone, 'data_email' => $customer_email, 'data_address' => $customer_address - ); - - $data = array( - 'req_token_id' => $token, - 'req_pairing_code' => $pairing_code, - 'req_customer' => $customer, - 'req_basket' => $basket, - 'req_words' => $words - ); + ); $ymdis = date('YmdHis'); $dataPayment = array( @@ -250,9 +258,19 @@ public function pay() { 'req_address' => $customer_address ); + Cache::put('dataPayment',$dataPayment,25); + if($this->payment_channel == '15') { //If Payment Credit Card + $data = array( + 'req_token_id' => $token, + 'req_pairing_code' => $pairing_code, + 'req_customer' => $customer, + 'req_basket' => $basket, + 'req_words' => $words + ); + $responsePrePayment = $this->doPrePayment($data); if($responsePrePayment->res_response_code == '0000'){ @@ -310,29 +328,33 @@ public function pay() { } - }elseif ($this->payment_channel == '02') { //If payment mandiri clickpay + }elseif ($this->payment_channel == '02') { //If payment mandiri clickpay + $dataPayment['req_card_number'] = str_replace(" - ", "", Request::get('cc_number')); $dataPayment['req_challenge_code_1'] = Request::get('CHALLENGE_CODE_1'); $dataPayment['req_challenge_code_2'] = Request::get('CHALLENGE_CODE_2'); $dataPayment['req_challenge_code_3'] = Request::get('CHALLENGE_CODE_3'); - $dataPayment['req_response_token'] = Request::get('response_token'); + $dataPayment['req_response_token'] = Request::get('response_token'); + + unset($dataPayment['req_token_id']); $result = $this->doDirectPayment($dataPayment); if($result->res_response_code == '0000'){ $result->res_redirect_url = ($this->show_finish_page)?$this->redirect_url:NULL; - $result->res_show_doku_page = $this->show_doku_success_page; + $result->res_show_doku_page = $this->show_doku_success_page; $hook->afterPayment(true,$dataPayment); Session::put('dokularavel_finished',$invoice_no); - echo json_encode($result); + return redirect($this->redirect_url.'?status=success'); }else{ $hook->afterPayment(false,$dataPayment); - echo json_encode($result); + // return redirect($this->redirect_url.'?status=failed'); + dd($result); } @@ -358,6 +380,7 @@ public function pay() { } } + public function debug() { if(config('dokularavel.DEBUG_MODE') == FALSE) abort(404); @@ -375,7 +398,7 @@ public function debug() { ]); foreach($this->payment_available as $pa) { - echo ''.$invoice_no.' Payment Channel '.$pa.'
'; + echo ''.$invoice_no.' Payment Channel '.$pa.'
'; } echo '
'; @@ -388,6 +411,18 @@ public function debug() { echo 'doPaymentRaw
'; echo Cache::get('doPaymentRaw'); + echo '
'; + + echo 'doDirectPayment
'; + echo Cache::get('doDirectPaymentRaw'); + + echo '
'; + + echo 'dataPayment
'; + echo '
';
+		echo print_r(Cache::get('dataPayment'));
+		echo '
'; + echo '
'; echo 'Doku Laravel Session'; dd(Session::all()); @@ -398,17 +433,17 @@ public function debug() { public function finish() { if(!$this->session_dokularavel) { - return redirect()->route('DokuController.index'); + return redirect()->route('DokuController.index').'?r=session_expired'; } $invoice_no = $this->session_dokularavel['trans_id']; if(!$invoice_no) { - return redirect()->route('DokuController.index'); + return redirect()->route('DokuController.index').'?r=invoice_null'; } if(Session::get('dokularavel_finished') != $invoice_no) { - return redirect()->route('DokuController.index'); + return redirect()->route('DokuController.index').'?r=finished_incorrect'; } diff --git a/src/Views/payment_form_mandiri_clickpay.blade.php b/src/Views/payment_form_mandiri_clickpay.blade.php new file mode 100644 index 0000000..8edb1f5 --- /dev/null +++ b/src/Views/payment_form_mandiri_clickpay.blade.php @@ -0,0 +1,146 @@ + + + + DOKU Payment + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
Total Payment ( IDR )
+
{{ number_format($amount) }}
+
+
+
+ +
+ Mandiri Clickpay +
+ +
+
+
+
+ +
+ + +
+
+ Pastikan bahwa kartu Anda telah diaktivasi melalui layanan mandiri Internet Banking Bank Mandiri pada menu Authorized Payment agar dapat melakukan transaksi Internet Payment. +
+
+
+ +
+ Gunakan token pin mandiri untuk bertransaksi. Nilai yang dimasukkan pada token Anda (Metode APPLI 3) +
+
+
+
+
    +
  • +
    Challenge Code 1
    + +
    +
  • +
  • +
    Challenge Code 2
    +
    0000100000
    + +
    +
  • +
  • +
    Challenge Code 3
    +
    + +
    +
  • +
    +
+
+
+
+ + +
+
+ + + +
+ + +
+
+
+ +
+ + + + + \ No newline at end of file