id= 'woo_ipay88'; $this->has_fields = false; $this->method_title = 'ipay88 payment processing'; $this->method_description = 'Process ipay88 payment trough woocommerce. custom plugin made to fit the needs.'; $this->init_form_fields(); $this->init_settings(); // after init_settins(); $this->title = 'ipay88 Payment Gateway'; $this->merchantID = $this->get_option( 'merchantID' ); $this->merchantKey = $this->get_option('merchantKey'); $this->pageID = $this->get_option('paymentPageID'); add_action('woocommerce_update_options_payment_gateways_'.$this->id, array(&$this, 'process_admin_options')); } public function init_form_fields(){ $pages = get_pages(); $poption = []; foreach($pages as $page): $poption[$page->ID] = $page->post_title; endforeach; $currencyOptions = FaizDriver::getSupportedCurrencies(); $this->form_fields = [ 'enabled' => [ 'title' => __( 'Enable/Disable ', 'aics' ), 'type' => 'checkbox', 'label' => __( 'Enable ipay88 gateway', 'aics' ), 'default' => 'yes' ], 'testingPayment' => [ 'title' => __( 'Testing or Live', 'aics' ), 'type' => 'checkbox', 'label' => __( 'Testing payment? (check if testing)', 'aics' ), 'default' => 'no' ], 'merchantID' => [ 'title' => __( 'Merchant ID', 'aics' ), 'type' => 'text', 'default' => '0000000' ], 'merchantKey' => [ 'title' => __( 'Merchant Key', 'aics' ), 'type' => 'text', 'default' => '0000000' ], 'ipay88Currency'=>[ 'title'=> __('Choose Currency ', 'aics'), 'type'=>'select', 'description'=> __('Only 2 currency supported for now. Send me tech specs to add more ;) ', 'aics'), 'default'=>'MYR', 'options'=>$currencyOptions ], 'paymentPageID' =>[ 'title'=> __( 'Choose The Page That Set For Payment Template', 'aics' ), 'type'=>'select', 'description'=> __('list of wordpress pages to choose as payment page', 'aics'), 'default'=>'1', 'options'=>$poption ], 'backendURL'=> [ 'title'=> __('Enable Backend URL', 'aics'), 'type' => 'select', 'label'=> __('enable or disable the backend URL feature', 'aics'), 'default'=>'no', 'options'=>['yes'=>'Enable', 'no'=>'Disable'] ] ]; } public function process_payment( $order_id ){ global $woocommerce; $order = wc_get_order( $order_id ); $payment_page = get_permalink($this->pageID).'?oid='.$order_id; return [ 'result' => 'success', 'redirect' => $payment_page ]; } // only call this when want to generate form. public function preparePayment($order_id){ $test_pay = $this->settings['testingPayment']; $testing = false; if($this->settings['testingPayment'] == 'yes'): $testing = true; endif; $currency = $this->settings['ipay88Currency']; $post_url = FaizDriver::getGatewayURL($currency, $testing); $order = wc_get_order( $order_id ); $amount = $order->get_total(); if($test_pay == 'yes'): $amount = '1.00'; endif; $amount = number_format((float)$amount, 2, '.', ''); $order_items = $order->get_items(); $item = ''; foreach($order_items as $key=>$oi): $item_name = $oi['name']; if($item != ''): $item .= $item_name.', '; else: $item .= $item_name; endif; endforeach; $current_user = wp_get_current_user(); if(isset($current_user->ID) && !empty($current_user->ID)): $user_phone = get_user_meta($current_user->ID, 'billing_phone', true); $user_fullname = $current_user->user_firstname.' '.$current_user->user_user_lastname; $user_email = $current_user->user_email; else: $user_phone = $order->get_billing_phone(); $user_fullname = $order->get_billing_first_name().' '.$order->get_billing_last_name(); $user_email = $order->get_billing_email(); endif; $format_amt = $this->formatAmount($amount); $the_string = $this->merchantKey.$this->merchantID.$order_id.$format_amt.$currency; $the_hash = $this->iPay88_signature($the_string); $response_url = get_permalink($this->pageID); $backend_url = $this->get_option('backendURL'); $site_url = site_url(); ?>
merchantKey.$this->merchantID.$payid.$refno.$amnt_final.$cur.$status; $signed = $this->iPay88_signature($combined); if($status == '1' && $signed == $ret_sign): //echo 'sign ok'; $order = new WC_Order( $refno ); $order->update_status('wc-completed', __( 'Completed', 'woocommerce' )); $order->payment_complete(); $redirect = $order->get_checkout_order_received_url(); wp_redirect($redirect); exit; else: $order = new WC_Order( $refno ); $order->update_status('failed', __( 'Failed', 'woocommerce' )); //$woocommerce->cart->empty_cart(); wp_redirect($this->get_return_url( $order )); exit; endif; endif; } public function backendResponse($data){ global $woocommerce; $echo = 'RECEIVEOK'; if(isset($data['MerchantCode']) && isset($data['PaymentId']) && isset($data['RefNo']) && isset($data['Amount']) && isset($data['Currency']) && isset($data['Signature']) && isset($data['Status'])): $mcode = $data['MerchantCode']; $payid = $data['PaymentId']; $refno = $data['RefNo']; $amt_txt = $data['Amount']; $cur = $data['Currency']; $ret_sign = $data['Signature']; $status = $data['Status']; $amnt = str_replace(',', '', $amt_txt); $amnt_final = str_replace('.', '', $amnt); $combined = $this->merchantKey.$this->merchantID.$payid.$refno.$amnt_final.$cur.$status; $signed = $this->iPay88_signature($combined); if($status == '1' && $signed == $ret_sign): //echo 'sign ok'; $order = new WC_Order( $refno ); $order->update_status('wc-completed', __( 'Completed', 'woocommerce' )); $order->payment_complete(); echo $echo;exit; else: //echo 'payment failed.'; $order = new WC_Order( $refno ); $order->update_status('failed', __( 'Failed. Signature does not match', 'woocommerce' )); echo $echo;exit; endif; endif; } }