Skip to content

Commit

Permalink
update dari server
Browse files Browse the repository at this point in the history
update dari server v 2.11.0 setelah dicustom andy untuk BCA
  • Loading branch information
diditho committed Jul 16, 2020
1 parent 512007a commit f0c34c5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 46 deletions.
79 changes: 45 additions & 34 deletions class/class.midtrans-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,19 +606,16 @@ function midtrans_vtweb_response() {
@ob_clean();

global $woocommerce;
$order = new WC_Order( $order_id );

Veritrans_Config::$isProduction = ($this->environment == 'production') ? true : false;

if ($this->environment == 'production') {
Veritrans_Config::$serverKey = $this->server_key_v2_production;
} else {
Veritrans_Config::$serverKey = $this->server_key_v2_sandbox;
}
Veritrans_Config::$isProduction = ($this->environment == 'production') ?
true:
false;
Veritrans_Config::$serverKey = ($this->environment == 'production') ?
$this->server_key_v2_production:
$this->server_key_v2_sandbox;

// check whether the request is GET or POST,
// if request == GET, request is for finish OR failed URL, then redirect to WooCommerce's order complete/failed
// else if request == POST, request is for payment notification, then update the payment status
// check whether the request is POST or GET,
// if request == POST, request is for payment notification, then update the payment status
if(!isset($_GET['order_id']) && !isset($_GET['id']) && !isset($_POST['response'])){ // Check if POST, then create new notification
$this->earlyResponse();
// Handle pdf url update
Expand All @@ -628,60 +625,74 @@ function midtrans_vtweb_response() {
$midtrans_notification = new Veritrans_Notification();
// If notification verified, handle it
if (in_array($midtrans_notification->status_code, array(200, 201, 202, 407))) {
if ($order->get_order($midtrans_notification->order_id) == true) {
if (wc_get_order($midtrans_notification->order_id) != false) {
do_action( "valid-midtrans-web-request", $midtrans_notification );
}
}
exit;

} else { // else if GET, redirect to order complete/failed
}
// if request == GET, request is for finish OR failed URL, then redirect to WooCommerce's order complete/failed
else {
// error_log('status_code '. $_GET['status_code']); //debug
// error_log('status_code '. $_GET['transaction_status']); //debug
if( isset($_GET['order_id']) && isset($_GET['transaction_status']) && $_GET['status_code'] == 200) //if capture or pending or challenge or settlement, redirect to order received page
{

// if capture or pending or challenge or settlement, redirect to order received page
if( isset($_GET['order_id']) && isset($_GET['transaction_status']) && $_GET['status_code'] <= 201) {
$order_id = $_GET['order_id'];
// error_log($this->get_return_url( $order )); //debug
$order = new WC_Order( $order_id );
wp_redirect($order->get_checkout_order_received_url());
}else if( isset($_GET['order_id']) && isset($_GET['transaction_status']) && $_GET['status_code'] != 200) //if deny, redirect to order checkout page again
{
}
//if deny, redirect to order checkout page again
else if( isset($_GET['order_id']) && isset($_GET['transaction_status']) && $_GET['status_code'] >= 201){
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
} else if( isset($_GET['order_id']) && !isset($_GET['transaction_status'])){ // if customer click "back" button, redirect to checkout page again
}
// if customer click "back" button, redirect to checkout page again
else if( isset($_GET['order_id']) && !isset($_GET['transaction_status'])){
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
} else if ( isset($_POST['response']) ){ // if customer redirected from async payment
// if customer redirected from async payment with POST `response` (CIMB clicks, etc)
} else if ( isset($_POST['response']) ){
$responses = json_decode( stripslashes($_POST['response']), true);
$order = new WC_Order( $responses['order_id'] );
if ( $responses['status_code'] == 200) { // async payment success
// if async payment paid
if ( $responses['status_code'] == 200) {
wp_redirect($order->get_checkout_order_received_url());
} else {
}
// if async payment not paid
else {
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
}
} else if (isset($_GET['id']) || (isset($_GET['wc-api']) && strlen($_GET['wc-api']) >= 25) ){ // if customer redirected form bca klikpay
if (isset($_GET['wc-api']) && strlen($_GET['wc-api']) >= 25) // if papi id get-query still in wrong format, need to manually substring
// if customer redirected from async payment with GET `id` (BCA klikpay, etc)
} else if (isset($_GET['id']) || (isset($_GET['wc-api']) && strlen($_GET['wc-api']) >= 25) ){
// Workaround if id query string is malformed, manual substring
if (isset($_GET['wc-api']) && strlen($_GET['wc-api']) >= 25) {
$id = str_replace("WC_Gateway_Midtrans?id=", "", $_GET['wc-api']);
else
}
// else if id query string format is correct
else {
$id = $_GET['id'];
}

$midtrans_notification = Veritrans_Transaction::status($id);
$order_id = $midtrans_notification->order_id;
// if async payment paid
if ($midtrans_notification->transaction_status == 'settlement'){
$order = new WC_Order( $order_id );
wp_redirect($order->get_checkout_order_received_url());
} else {
}
// if async payment not paid
else {
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
}
} else {
}
// if unhandled case, fallback, redirect to home
else {
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
}
}

}

/**
* Method ini akan dipanggil jika customer telah sukses melakukan
* pembayaran. Method ini akan mengubah status order yang tersimpan
* di back-end berdasarkan status pembayaran yang dilakukan customer.
*
*/

/**
* Handle Midtrans Notification Object, after payment status changes on Midtrans
* Will update WC payment status accordingly
Expand Down
2 changes: 1 addition & 1 deletion class/finish-url-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_footer(); ?>
<?php get_footer(); ?>
15 changes: 12 additions & 3 deletions class/order-view-and-thankyou-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@
?>
<?php if( $order->meta_exists('_mt_payment_url') ) : ?>
<h2>Payment Info</h2>
<table class="woocommerce-table shop_table payment_info">
<table class="woocommerce-table shop_table midtrans_payment_info">
<tbody>
<?php if( $order->is_paid() ) : ?>
<tr>
<th>Payment Complete?</th>
<td><?php echo $order->is_paid()? 'Yes. Payment Completed' : 'No' ?></td>
<th>Payment Status</th>
<td>Payment Completed</td>
</tr>
<?php else : ?>
<!-- Make customer focus to payment url, if order need payment -->
<script type="text/javascript">
setTimeout(function(){
document.querySelectorAll('.midtrans_payment_info')[0].scrollIntoView();
}, 1500);
</script>
<?php endif; ?>
<?php if( $order->meta_exists('_mt_payment_pdf_url') ) : ?>
<tr>
<th>Payment Instructions</th>
Expand Down
9 changes: 6 additions & 3 deletions class/payment-page-paymentrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
<a id="pay-button" title="Do Payment!" class="button alt">Loading Payment...</a>

<div id="payment-instruction" style="display:none;">
<h3 class="alert alert-info"> Awaiting Your Payment </h3>
<!-- <h3 class="alert alert-info"> Awaiting Your Payment </h3> -->
<!-- <br> -->
<p> Please complete your payment as instructed </p>
<p> Please complete your payment as instructed. If you have done your payment, please check your email or my "Order" menu for order status. </p>
<!-- <br> -->
<a target="_blank" href="#" id="payment-instruction-btn" title="Do Payment!" class="button alt" >
Payment Instruction
Expand Down Expand Up @@ -133,7 +133,10 @@ function execSnapCont(ccDetails){
payButton.innerHTML = "Loading...";
window.location = <?php echo $finish_url;?>;
}

// redirect to thank you page
window.location = <?php echo $finish_url;?>;
return;
// Below code is UNUSED
// Show payment instruction and hide payment button
document.getElementById('payment-instruction-btn').href = result.pdf_url;
document.getElementById('pay-button').style.display = "none";
Expand Down
9 changes: 6 additions & 3 deletions class/payment-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
<a id="pay-button" title="Do Payment!" class="button alt">Loading Payment...</a>

<div id="payment-instruction" style="display:none;">
<h3 class="alert alert-info"> Awaiting Your Payment </h3>
<!-- <h3 class="alert alert-info"> Awaiting Your Payment </h3> -->
<!-- <br> -->
<p> Please complete your payment as instructed </p>
<p> Please complete your payment as instructed. If you have done your payment, please check your email or my "Order" menu for order status. </p>
<!-- <br> -->
<a target="_blank" href="#" id="payment-instruction-btn" title="Do Payment!" class="button alt" >
Payment Instruction
Expand Down Expand Up @@ -128,7 +128,10 @@ function execSnapCont(){
payButton.innerHTML = "Loading...";
window.location = <?php echo $finish_url;?>;
}

// redirect to thank you page
window.location = <?php echo $finish_url;?>;
return;
// Below code is UNUSED
// Show payment instruction and hide payment button
document.getElementById('payment-instruction-btn').href = result.pdf_url;
document.getElementById('pay-button').style.display = "none";
Expand Down
2 changes: 1 addition & 1 deletion midtrans-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://github.com/veritrans/SNAP-Woocommerce
Description: Accept all payment directly on your WooCommerce site in a seamless and
secure checkout environment with <a href="http://midtrans.co.id" target="_blank">Midtrans.co.id</a>
Version: 2.10.0
Version: 2.11.0
Author: Midtrans
Author URI: http://midtrans.co.id
License: GPLv2 or later
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: yocki, rizdaprasetya
Tags: midtrans, snap, payment, payment-gateway, credit-card, commerce, e-commerce, woocommerce, veritrans
Requires at least: 3.9.1
Tested up to: 5.0.0
Stable tag: 2.10.0
Stable tag: 2.11.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -154,6 +154,9 @@ The best way please email to [email protected], but bugs can be reported in o
= 2.10.0 =
* Code cleanup

= 2.11.0 =
* UX improvement for pending payment

== Upgrade Notice ==

= 1.0 =
Expand Down Expand Up @@ -213,6 +216,9 @@ Add use map finish url config field
= 2.10.0 =
* Code cleanup

= 2.11.0 =
* UX improvement for pending payment

== Get Help ==

* [Midtrans registration](https://account.midtrans.com/register)
Expand Down

0 comments on commit f0c34c5

Please sign in to comment.