Skip to content

Commit

Permalink
Merge pull request #269 from checkout/fix/order-status-defaults
Browse files Browse the repository at this point in the history
Add default value to order status fetch method
  • Loading branch information
SanketChodavadiya authored May 24, 2022
2 parents 5065cbd + 45e8028 commit da4ae44
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function create_payment( WC_Order $order, $arg, $subscription = nu
private static function get_request_param( WC_Order $order, $arg, $subscription = null ) {
global $woocommerce, $wp_version;

$auto_capture = WC_Admin_Settings::get_option( 'ckocom_card_autocap' ) == 1 ? true : false;
$auto_capture = WC_Admin_Settings::get_option( 'ckocom_card_autocap', 1 ) == 1;
$amount = $order->get_total();
$amount_cents = WC_Checkoutcom_Utility::valueToDecimal( $amount, $order->get_currency() );
$three_d = WC_Admin_Settings::get_option( 'ckocom_card_threed' ) == 1 && $subscription == null ? true : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function process_payment( $order_id )
}


$status = WC_Admin_Settings::get_option('ckocom_order_authorised');
$status = WC_Admin_Settings::get_option('ckocom_order_authorised', 'on-hold');
$message = "";

if ($result['source']['type'] == self::PAYMENT_METHOD) {
Expand All @@ -66,7 +66,7 @@ public function process_payment( $order_id )
$message = __("Checkout.com - Fawry payment " ."</br>". " Action ID : {$result['id']} - Fawry reference number : {$result['source']['reference_number']} ", 'wc_checkout_com');

if ($result['status'] == 'Captured') {
$status = WC_Admin_Settings::get_option('ckocom_order_captured');
$status = WC_Admin_Settings::get_option('ckocom_order_captured', 'processing');
$message = __("Checkout.com Payment Captured " ."</br>". " Action ID - {$result['id']} ", 'wc_checkout_com');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function process_payment( $order_id ) {
return;
}

$status = WC_Admin_Settings::get_option( 'ckocom_order_authorised' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_authorised', 'on-hold' );
$message = '';

if ( ! empty( $result['source'] ) && self::PAYMENT_METHOD === $result['source']['type'] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,13 @@ public function process_payment( $order_id ) {
update_post_meta( $order_id, '_cko_payment_id', $result['id'] );

// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option( 'ckocom_order_authorised' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_authorised', 'on-hold' );
$message = __( "Checkout.com Payment Authorised " . "</br>" . " Action ID : {$result['action_id']} ", 'wc_checkout_com' );

// check if payment was flagged
if ( $result['risk']['flagged'] ) {
// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option( 'ckocom_order_flagged' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_flagged', 'flagged' );
$message = __( "Checkout.com Payment Flagged " . "</br>" . " Action ID : {$result['action_id']} ", 'wc_checkout_com' );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,14 @@ public function process_payment( $order_id )
update_post_meta( $order_id, '_cko_payment_id', $result['id'] );

// Get cko auth status configured in admin.
$status = WC_Admin_Settings::get_option( 'ckocom_order_authorised' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_authorised', 'on-hold' );
$message = sprintf( esc_html__( 'Checkout.com Payment Authorised - Action ID : %s', 'wc_checkout_com' ), $result['action_id'] );


// Check if payment was flagged.
if ( $result['risk']['flagged'] ) {
// Get cko auth status configured in admin.
$status = WC_Admin_Settings::get_option( 'ckocom_order_flagged' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_flagged', 'flagged' );
$message = sprintf( esc_html__( 'Checkout.com Payment Flagged - Action ID : %s', 'wc_checkout_com' ), $result['action_id'] );
}

Expand Down Expand Up @@ -498,24 +498,24 @@ public function callback_handler()
update_post_meta($order_id, '_cko_payment_id', $result['id']);

// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_authorised');
$status = WC_Admin_Settings::get_option('ckocom_order_authorised', 'on-hold');
$message = __("Checkout.com Payment Authorised " ."</br>". " Action ID : {$action['0']['id']} ", 'wc_checkout_com');

// check if payment was flagged
if ($result['risk']['flagged']) {
// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_flagged');
$status = WC_Admin_Settings::get_option('ckocom_order_flagged', 'flagged');
$message = __("Checkout.com Payment Flagged " ."</br>". " Action ID : {$action['0']['id']} ", 'wc_checkout_com');
}

if ( 'Canceled' === $result['status'] ) {
$status = WC_Admin_Settings::get_option( 'ckocom_order_void' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_void', 'cancelled' );
$message = __( "Checkout.com Payment Canceled" . "</br>" . " Action ID : {$action['0']['id']} ", 'wc_checkout_com' );
}

if ($result['status'] == 'Captured') {
update_post_meta($order_id, 'cko_payment_captured', true);
$status = WC_Admin_Settings::get_option('ckocom_order_captured');
$status = WC_Admin_Settings::get_option('ckocom_order_captured', 'processing');
$message = __("Checkout.com Payment Captured" ."</br>". " Action ID : {$action['0']['id']} ", 'wc_checkout_com');
}

Expand Down Expand Up @@ -719,12 +719,12 @@ public function process_refund($order_id, $amount = null, $reason = '')
update_post_meta($order_id, 'cko_payment_refunded', true);

// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_refunded');
$status = WC_Admin_Settings::get_option('ckocom_order_refunded', 'refunded');
$message = __("Checkout.com Payment refunded from Admin " ."</br>". " Action ID : {$result['action_id']} ", 'wc_checkout_com');

if(isset($_SESSION['cko-refund-is-less'])){
if($_SESSION['cko-refund-is-less']){
$status = WC_Admin_Settings::get_option('ckocom_order_captured');
$status = WC_Admin_Settings::get_option('ckocom_order_captured', 'processing');
$order->add_order_note( __("Checkout.com Payment Partially refunded from Admin " ."</br>". " Action ID : {$result['action_id']}", 'wc_checkout_com') );

unset($_SESSION['cko-refund-is-less']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ public function process_payment( $order_id )
update_post_meta($order_id, '_cko_payment_id', $result['id']);

// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_authorised');
$status = WC_Admin_Settings::get_option('ckocom_order_authorised', 'on-hold');
$message = __("Checkout.com Payment Authorised " ."</br>". " Action ID : {$result['action_id']} ", 'wc_checkout_com');

// check if payment was flagged
if ($result['risk']['flagged']) {
// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_flagged');
$status = WC_Admin_Settings::get_option('ckocom_order_flagged', 'flagged');
$message = __("Checkout.com Payment Flagged " ."</br>". " Action ID : {$result['action_id']} ", 'wc_checkout_com');
}

Expand Down Expand Up @@ -372,12 +372,12 @@ public function process_refund($order_id, $amount = null, $reason = '')
update_post_meta($order_id, '_transaction_id', $result['action_id']);

// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_refunded');
$status = WC_Admin_Settings::get_option('ckocom_order_refunded', 'refunded');
$message = __("Checkout.com Payment refunded " ."</br>". " Action ID : {$result['action_id']} ", 'wc_checkout_com');

if(isset($_SESSION['cko-refund-is-less'])){
if($_SESSION['cko-refund-is-less']){
$status = WC_Admin_Settings::get_option('ckocom_order_captured');
$status = WC_Admin_Settings::get_option('ckocom_order_captured', 'processing');
$order->add_order_note( __("Checkout.com Payment Partially refunded " ."</br>". " Action ID : {$result['action_id']}", 'wc_checkout_com') );

unset($_SESSION['cko-refund-is-less']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function authorize_payment($data)
}

$already_authorized = get_post_meta($order_id, 'cko_payment_authorized', true);
$auth_status = WC_Admin_Settings::get_option('ckocom_order_authorised');
$auth_status = WC_Admin_Settings::get_option('ckocom_order_authorised', 'on-hold');
$message = 'Webhook received from checkout.com. Payment Authorized';

// Add note to order if Authorized already
Expand Down Expand Up @@ -82,7 +82,7 @@ public static function card_verified($data)
update_post_meta($order_id, '_transaction_id', $action_id);

// Get cko capture status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_captured');
$status = WC_Admin_Settings::get_option('ckocom_order_captured', 'processing');

// update status of the order
$order->update_status($status);
Expand Down Expand Up @@ -144,7 +144,7 @@ public static function capture_payment($data)
update_post_meta($order_id, 'cko_payment_captured', true);

// Get cko capture status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_captured');
$status = WC_Admin_Settings::get_option('ckocom_order_captured', 'processing');
$order_message = __("Checkout.com Payment Captured " ."</br>". " Action ID : {$action_id} ", 'wc_checkout_com');

// Check if webhook amount is less than order amount
Expand Down Expand Up @@ -226,7 +226,7 @@ public static function void_payment($data)
update_post_meta($order_id, 'cko_payment_voided', true);

// Get cko capture status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_void');
$status = WC_Admin_Settings::get_option('ckocom_order_void', 'cancelled');
$order_message = __("Checkout.com Payment Voided " ."</br>". " Action ID : {$action_id} ", 'wc_checkout_com');

// add notes for the order and update status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public static function update_order_status($payment_result, $renewal_order, $ord
}

// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_authorised');
$status = WC_Admin_Settings::get_option('ckocom_order_authorised', 'on-hold');
$message = __("Checkout.com Payment Authorised " ."</br>". " Action ID : {$payment_result['action_id']} ", 'wc_checkout_com');

// check if payment was flagged
if ($payment_result['risk']['flagged']) {
// Get cko auth status configured in admin
$status = WC_Admin_Settings::get_option('ckocom_order_flagged');
$status = WC_Admin_Settings::get_option('ckocom_order_flagged', 'flagged');
$message = __("Checkout.com Payment Flagged " ."</br>". " Action ID : {$payment_result['action_id']} ", 'wc_checkout_com');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ function cko_refund() {
function action_woocommerce_order_item_add_action_buttons( $order ) {

$order_status = $order->get_status();
$auth_status = str_replace('wc-', '', WC_Admin_Settings::get_option('ckocom_order_authorised'));
$capture_status = str_replace('wc-', '', WC_Admin_Settings::get_option('ckocom_order_captured'));
$auth_status = str_replace('wc-', '', WC_Admin_Settings::get_option('ckocom_order_authorised', 'on-hold'));
$capture_status = str_replace('wc-', '', WC_Admin_Settings::get_option('ckocom_order_captured', 'processing'));

if($order->get_payment_method() == 'wc_checkout_com_cards'
|| $order->get_payment_method() == 'wc_checkout_com_google_pay') {
Expand Down Expand Up @@ -328,7 +328,7 @@ function renew_save_again( $post_id, $post, $update ) {
update_post_meta( sanitize_text_field( $_POST['post_ID'] ), 'cko_payment_captured', true );

// Get cko capture status configured in admin.
$status = WC_Admin_Settings::get_option( 'ckocom_order_captured' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_captured', 'processing' );
$message = sprintf( esc_html__( "Checkout.com Payment Captured from Admin - Action ID : %s", 'wc_checkout_com' ), $result['action_id'] );

// add notes for the order and update status.
Expand All @@ -353,7 +353,7 @@ function renew_save_again( $post_id, $post, $update ) {
update_post_meta( sanitize_text_field( $_POST['post_ID'] ), 'cko_payment_voided', true );

// Get cko capture status configured in admin.
$status = WC_Admin_Settings::get_option( 'ckocom_order_void' );
$status = WC_Admin_Settings::get_option( 'ckocom_order_void', 'cancelled' );
$message = sprintf( esc_html__( "Checkout.com Payment Voided from Admin - Action ID : %s", 'wc_checkout_com' ), $result['action_id'] );

// add notes for the order and update status.
Expand Down

0 comments on commit da4ae44

Please sign in to comment.