Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Bug fix and Improve
Browse files Browse the repository at this point in the history
add payment available in configuration
improve debug for repsonse in controller
bug fixed in dokucontroller
add new view for mandiri click pay
  • Loading branch information
fherryfherry committed Aug 28, 2016
1 parent cf80442 commit 7073408
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 50 deletions.
30 changes: 16 additions & 14 deletions src/Config/dokularavel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
93 changes: 64 additions & 29 deletions src/Controllers/DokuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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'){
Expand Down Expand Up @@ -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);
}


Expand All @@ -358,6 +380,7 @@ public function pay() {
}
}


public function debug() {

if(config('dokularavel.DEBUG_MODE') == FALSE) abort(404);
Expand All @@ -375,7 +398,7 @@ public function debug() {
]);

foreach($this->payment_available as $pa) {
echo '<a href="'.Route("DokuController.index").'?trans_id='.$invoice_no.'&payment_channel='.$pa.'">'.$invoice_no.' Payment Channel '.$pa.'</a><br/>';
echo '<a target="doku" href="'.Route("DokuController.index").'?trans_id='.$invoice_no.'&payment_channel='.$pa.'">'.$invoice_no.' Payment Channel '.$pa.'</a><br/>';
}

echo '<hr/>';
Expand All @@ -388,6 +411,18 @@ public function debug() {
echo '<strong>doPaymentRaw</strong><br/>';
echo Cache::get('doPaymentRaw');

echo '<hr/>';

echo '<strong>doDirectPayment</strong><br/>';
echo Cache::get('doDirectPaymentRaw');

echo '<hr/>';

echo '<strong>dataPayment</strong><br/>';
echo '<pre>';
echo print_r(Cache::get('dataPayment'));
echo '</pre>';

echo '<hr/>';
echo '<strong>Doku Laravel Session</strong>';
dd(Session::all());
Expand 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';
}


Expand Down
Loading

0 comments on commit 7073408

Please sign in to comment.