roshanbi
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: css help wordpressIn fact I checked the css by right click on page and inspect.
I had to set the border to non.
.woocommerce form.checkout_coupon, .woocommerce form.login, .woocommerce form.register { border: none; padding: 20px; margin: 2em 0; text-align: left; border-radius: 5px; }
Thanks,
Roshan
Forum: Fixing WordPress
In reply to: php in wordpress pageI want to add a form in html where the values have php GET parameters set to them.
<html> <body> <form action="https://pay.mytmoney.mu/Mt/web/payments" method="POST"> <input name="appId" value="<?php echo $_GET[ 'appID' ]; ?>"/> <input name="merTradeNo" value="<?php echo $_GET[ 'merTradeNo' ]; ?>"/> <input name="payload" value="<?php echo $_GET[ 'encryptedPayload' ]; ?>"/> <input name="paymentType" value="<?php echo $_GET[ 'paymentType' ]; ?>"/> <input name="sign" value="<?php echo $_GET[ 'sign' ]; ?>"/> <p><input type="submit" value="Pay By my.t money"/></p> </form>
Forum: Fixing WordPress
In reply to: PHP GET parameterThanks.
Forum: Fixing WordPress
In reply to: authentication errorOK thanks, will check with them
Forum: Fixing WordPress
In reply to: authentication errorOK thanks
Forum: Fixing WordPress
In reply to: authentication errorit is a custom plugin.
Forum: Fixing WordPress
In reply to: encryption errorPlease find below the full code.
<?php /** * * Copyright: (c) 2015-2016 SkyVerge, Inc. ([email protected]) and WooCommerce * * This offline gateway forks the WooCommerce core "Cheque" payment gateway to create another offline payment method. */ defined( 'ABSPATH' ) or exit; // Make sure WooCommerce is active if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { return; } /** * Add the gateway to WC Available Gateways * * @since 1.0.0 * @param array $gateways all available WC gateways * @return array $gateways all WC gateways + offline gateway */ function wc_offline_add_to_gateways( $gateways ) { $gateways[] = 'WC_Gateway_Offline'; return $gateways; } add_filter( 'woocommerce_payment_gateways', 'wc_offline_add_to_gateways' ); /** * Adds plugin page links * * @since 1.0.0 * @param array $links all plugin links * @return array $links all plugin links + our custom links (i.e., "Settings") */ function wc_offline_gateway_plugin_links( $links ) { $plugin_links = array( '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=offline_gateway' ) . '">' . __( 'Configure', 'wc-gateway-offline' ) . '</a>' ); return array_merge( $plugin_links, $links ); } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_offline_gateway_plugin_links' ); /** * Offline Payment Gateway * * Provides an Offline Payment Gateway; mainly for testing purposes. * We load it later to ensure WC is loaded first since we're extending it. * * @class WC_Gateway_Offline * @extends WC_Payment_Gateway * @version 1.0.0 * @package WooCommerce/Classes/Payment * @author SkyVerge */ add_action( 'plugins_loaded', 'wc_offline_gateway_init', 11 ); function wc_offline_gateway_init() { class WC_Gateway_Offline extends WC_Payment_Gateway { /** * Constructor for the gateway. */ public function __construct() { $this->id = 'offline_gateway'; $this->icon = apply_filters('woocommerce_offline_icon', ''); $this->has_fields = false; $this->method_title = __( 'Offline', 'wc-gateway-offline' ); $this->method_description = __( 'Allows offline payments. Very handy if you use your cheque gateway for another payment method, and can help with testing. Orders are marked as "on-hold" when received.', 'wc-gateway-offline' ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->instructions = $this->get_option( 'instructions', $this->description ); // Actions add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); // Customer Emails add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); } /** * Initialize Gateway Settings Form Fields */ public function init_form_fields() { $this->form_fields = apply_filters( 'wc_offline_form_fields', array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'wc-gateway-offline' ), 'type' => 'checkbox', 'label' => __( 'Enable Offline Payment', 'wc-gateway-offline' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'wc-gateway-offline' ), 'type' => 'text', 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'wc-gateway-offline' ), 'default' => __( 'Myt Money', 'wc-gateway-offline' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'wc-gateway-offline' ), 'type' => 'textarea', 'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-gateway-offline' ), 'default' => __( 'Myt Money', 'wc-gateway-offline' ), 'desc_tip' => true, ), 'instructions' => array( 'title' => __( 'Instructions', 'wc-gateway-offline' ), 'type' => 'textarea', 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'wc-gateway-offline' ), 'default' => '', 'desc_tip' => true, ), ) ); } /** * Output for the order received page. */ public function thankyou_page() { if ( $this->instructions ) { echo wpautop( wptexturize( $this->instructions ) ); } } /** * Add content to the WC emails. * * @access public * @param WC_Order $order * @param bool $sent_to_admin * @param bool $plain_text */ public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method && $order->has_status( 'on-hold' ) ) { echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; } } /** * Process the payment and return the result * * @param int $order_id * @return array */ public function process_payment( $order_id ) { global $woocommerce; // Get this Order's information so that we know // who to charge and how much $customer_order = new WC_Order( $order_id ); // Are we testing right now or is it a real transaction $environment = ( $this->environment == "yes" ) ? 'TRUE' : 'FALSE'; // Decide which URL to post to $environment_url = ( "FALSE" == $environment ) ? 'https://transportation.local/wordpress/redirect': 'https://transportation.local/wordpress/redirect'; $appID="1000000661"; $merTradeNo = 1234; $paymentType="S"; $publicKey="MIICIy9pMNhp1HKbZeRuwzPGFY9ch0xeLZqy5T2owQxki19tDzJICB5JMyBz1rNhaRc4ZYGM6Qxg3hOqZLQSbgM5o37WNjbmlPk5vtGRKBcmPbdamef1iEjWGqZth+bJUbG3zjkpyPOgtR1++/dCRi0meBtW9BXecmYktqPaUROgKmH8DJ2/alMRSiUxR9mWJTPJgmmeHYBMWTkKeDLcl2Rhlriz5hB8SvGLOqBsCAwEAAQ=="; $apiKey="BH+0NAQRMiQyvF1KvOoZlA=="; $notifyURL="https://www.myt.mu"; $returnURL="https://www.myt.mu"; $remark="This is a test payment"; $lang="en"; // This is where the fun stuff begins $payload = array( "totalPrice" => $totalAmount_CNY, "totalPrice" => $customer_order->order_total ); //encrypt payload $payload=json_encode($payload); $rsa= new phpseclib\Crypt\RSA(); $rsa->setHash('sha1'); $rsa->setMGFHash('sha1'); $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS1); $rsa->loadKey($publickey); $encryptedPayload=base64_encode($rsa->encrypt($payload)); $signaturedata="appID&merTradeNo=$merTradeNo$merTradeNo&payload=$encryptedPayload&paymentType=$paymentType"; $sign=base64_encode(hash_hmac('sha512',$signaturedata,$apiKey,true)); // Send this payload to Authorize.net for processing $response = wp_remote_post( $environment_url, array( 'method' => 'POST', 'body' => http_build_query( $sign ), 'timeout' => 90, 'sslverify' => false, ) ); if ( is_wp_error( $response ) ) throw new Exception( __( 'We are currently experiencing problems trying to connect to this payment gateway. Sorry for the inconvenience.', 'spyr-authorizenet-aim' ) ); if ( empty( $response['body'] ) ) throw new Exception( __( 'Authorize.net\'s Response was empty.', 'spyr-authorizenet-aim' ) ); // Retrieve the body's resopnse if no errors found $response_body = wp_remote_retrieve_body( $response ); // Parse the response into something we can read foreach ( preg_split( "/\r?\n/", $response_body ) as $line ) { $resp = explode( "|", $line ); } // Get the values we need $r['response_code'] = $resp[0]; $r['response_sub_code'] = $resp[1]; $r['response_reason_code'] = $resp[2]; $r['response_reason_text'] = $resp[3]; // Test the code to know if the transaction went through or not. // 1 or 4 means the transaction was a success if ( ( $r['response_code'] == 1 ) || ( $r['response_code'] == 4 ) ) { // Payment has been successful $customer_order->add_order_note( __( 'Authorize.net payment completed.', 'spyr-authorizenet-aim' ) ); // Mark order as Paid $customer_order->payment_complete(); // Empty the cart (Very important step) $woocommerce->cart->empty_cart(); // Redirect to thank you page return array( 'result' => 'success', 'redirect' => $this->get_return_url( $customer_order ), ); } else { // Transaction was not succesful // Add notice to the cart wc_add_notice( $r['response_reason_text'], 'error' ); // Add note to the order for your reference $customer_order->add_order_note( 'Error: '. $r['response_reason_text'] ); } } //function below calculates total and sets in a variable. Added on 1 July 2022 @roshanbi protected function calculate_totals() { $this->set_total( 'total', round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + wc_round_tax_total( array_sum( $this->get_merged_taxes( true ) ), 0 ), 0 ) ); $this->cart->set_total_tax( array_sum( $this->get_merged_taxes( false ) ) ); // Allow plugins to hook and alter totals before final total is calculated. if ( has_action( 'woocommerce_calculate_totals' ) ) { do_action( 'woocommerce_calculate_totals', $this->cart ); } // Allow plugins to filter the grand total, and sum the cart totals in case of modifications. $this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) ); } } // end \WC_Gateway_Offline class }
Sure, will check with them.
Regards,
Roshan
Forum: Fixing WordPress
In reply to: path of wordpress page URLFor the wordpress page which you see in the picture, where do I locate it’s PHP file?
Forum: Fixing WordPress
In reply to: call pluginHi,
can you please validate below?
//initiate payment $response = $moovpay->purchase($appID,$merTradeNo,$encryptedPayload,$paymentType,$sign); $fh = fopen(plugin_dir_path(__FILE__).'redirect.php', 'w+'); fwrite($fh, $response); fclose($fh); $redirect_url = plugin_dir_url(__FILE__).'redirect.php'; return array( 'result' => 'success', 'redirect' => $redirect_url );
Thanks,
Roshan
Forum: Fixing WordPress
In reply to: add code to existing wordpress pageHello Farid,
I would like to create a payment plugin on Woocommerce. I have attached the mytmoney.php file. The plugin shall redirect to another page (redirect).
Please find below the flow
https://snipboard.io/vSgh01.jpg
https://snipboard.io/hivauL.jpg1. can you please validate the code? is there a simpler way?
2. Where should I add the redirect page?
mytmoney.php:
<?php defined( 'ABSPATH' ) or exit; // Make sure WooCommerce is active if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { return; } function wc_offline_add_to_gateways( $gateways ) { $gateways[] = 'WC_Gateway_Offline'; return $gateways; } add_filter( 'woocommerce_payment_gateways', 'wc_offline_add_to_gateways' ); function wc_offline_gateway_plugin_links( $links ) { $plugin_links = array( '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=offline_gateway' ) . '">' . __( 'Configure', 'wc-gateway-offline' ) . '</a>' ); return array_merge( $plugin_links, $links ); } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_offline_gateway_plugin_links' ); /** * Offline Payment Gateway * */ add_action( 'plugins_loaded', 'wc_offline_gateway_init', 11 ); function wc_offline_gateway_init() { class WC_Gateway_Offline extends WC_Payment_Gateway { /** * Constructor for the gateway. */ public function __construct() { $this->id = 'offline_gateway'; $this->icon = apply_filters('woocommerce_offline_icon', ''); $this->has_fields = false; $this->method_title = __( 'Offline', 'wc-gateway-offline' ); $this->method_description = __( 'Allows offline payments. Very handy if you use your cheque gateway for another payment method, and can help with testing. Orders are marked as "on-hold" when received.', 'wc-gateway-offline' ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->instructions = $this->get_option( 'instructions', $this->description ); // Actions add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); // Customer Emails add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); } /** * Initialize Gateway Settings Form Fields */ public function init_form_fields() { $this->form_fields = apply_filters( 'wc_offline_form_fields', array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'wc-gateway-offline' ), 'type' => 'checkbox', 'label' => __( 'Enable Offline Payment', 'wc-gateway-offline' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'wc-gateway-offline' ), 'type' => 'text', 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'wc-gateway-offline' ), 'default' => __( 'Myt Money', 'wc-gateway-offline' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'wc-gateway-offline' ), 'type' => 'textarea', 'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-gateway-offline' ), 'default' => __( 'Please remit payment to Store Name upon pickup or delivery.', 'wc-gateway-offline' ), 'desc_tip' => true, ), 'instructions' => array( 'title' => __( 'Instructions', 'wc-gateway-offline' ), 'type' => 'textarea', 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'wc-gateway-offline' ), 'default' => '', 'desc_tip' => true, ), ) ); } /** * Output for the order received page. */ public function thankyou_page() { if ( $this->instructions ) { echo wpautop( wptexturize( $this->instructions ) ); } } /** * Add content to the WC emails. * * @access public * @param WC_Order $order * @param bool $sent_to_admin * @param bool $plain_text */ public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method && $order->has_status( 'on-hold' ) ) { echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; } } /** * Process the payment and return the result * * @param int $order_id * @return array */ public function process_payment( $order_id ) { $order = wc_get_order( $order_id ); //test merTradeNo added on 1 July 2022 @roshanbi $merTradeNo->billing_first_name ." ".$merTradeNo->billing_last_name .", ".$merTradeNo->billing_address_1.$merTradeNo->billing_address_2 . ", " .$merTradeNo->billing_postcode." ". $merTradeNo->billing_city. ", ". $merTradeNo->billing_state; // Mark as on-hold (we're awaiting the payment) $order->update_status( 'on-hold', __( 'Awaiting offline payment', 'wc-gateway-offline' ) ); // Reduce stock levels $order->reduce_order_stock(); // Remove cart WC()->cart->empty_cart(); // Return thankyou redirect return array( 'result' => 'success', 'redirect' => $this->get_return_url( $order ) ); //total amount added on 1 July 2022 1:52 pm $totalAmount = $order->get_total(); //RSA and payload details added on 1 July 2022 /*$totalAmount="0.01" */ $appID="1000000661"; /*$merTradeNo=""; */ $paymentType="S"; $publicKey="MbZeRuwzPGFY9c=="; $apiKey="BH+0FycxCOvF1KvOoZlA=="; $payload=array( "totalPrice"=>$totalAmount, "currency"=>$merTradeNo, "notifyURL"=>"https://www.myt.mu", "returnURL"=>"https://www.myt.mu", "remark"=>"This is a test payment", lang=>"en" ); //code to generate signature $payload=json_encode($payload); $rsa= new \wamp642\www\transportation\wordpress\wp-content\phpseclib\phpseclib\Crypt\RSA(); $rsa->setHash('sha1'); $rsa->setMGFHash('sha1'); $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS1); $rsa->loadKey($publickey); $encryptedPayload=base64_encode($rsa->encrypt($payload)); $signaturedata="appID&merTradeNo=$merTradeNo$merTradeNo&payload=$encryptedPayload&paymentType=$paymentType"; $sign=base64_encode(hash_hmac('sha512',$signaturedata,$apiKey,true)); //initiate payment $response = $moovpay->purchase($appID,$merTradeNo,$encryptedPayload,$paymentType,$sign); $fh = fopen(plugin_dir_path(__FILE__).'redirect.php', 'w+'); fwrite($fh, $response); fclose($fh); $redirect_url = plugin_dir_url(__FILE__).'redirect.php'; return array( 'result' => 'success', 'redirect' => $redirect_url ); } //function below calculates total and sets in a variable. Added on 1 July 2022 @roshanbi protected function calculate_totals() { $this->set_total( 'total', round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + wc_round_tax_total( array_sum( $this->get_merged_taxes( true ) ), 0 ), 0 ) ); $this->cart->set_total_tax( array_sum( $this->get_merged_taxes( false ) ) ); // Allow plugins to hook and alter totals before final total is calculated. if ( has_action( 'woocommerce_calculate_totals' ) ) { do_action( 'woocommerce_calculate_totals', $this->cart ); } // Allow plugins to filter the grand total, and sum the cart totals in case of modifications. $this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) ); } public function webhook() { header( 'HTTP/1.1 200 OK' ); $order_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : null; $nonce = isset($_REQUEST['nonce']) ? $_REQUEST['nonce'] : null; if (is_null($order_id)) return; if (is_null($nonce)) return; if (wc_get_order_item_meta($order_id,'ipn_nonce')!=$nonce) return; $order = wc_get_order( $order_id ); $order->payment_complete(); wc_reduce_stock_levels($order_id); } } // end \WC_Gateway_Offline class }
Redirect.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="https://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <form id="redirectForm" action="https://gateway.mytmoney.mu/web/payments" method="post"> <input type="hidden" name="appId" value="<?php echo $_GET[ 'appID' ]; ?>"/> <input type="hidden" name="merTradeNo" value="<?php echo $_GET[ 'merTradeNo' ]; ?>"/> <input type="hidden" name="payload" value="<?php echo $_GET[ 'encryptedPayload' ]; ?>"/> <input type="hidden" name="paymentType" value="<?php echo $_GET[ 'paymentType' ]; ?>"/> <input type="hidden" name="sign" value="<?php echo $_GET[ 'sign' ]; ?>"/> <p><input type="submit" value="Pay By my.t money"/></p> </form> <form action="https://transaportation.local/my-account" method="post"> <input type="hidden" name="merTradeNo" value=MT001/> <input type="hidden" name="TradeNo" value="123456"/> <input type="hidden" name="tradeStatus" value="S"/> <input type="hidden" name="msg" value="SUCCESS"/> <input type="hidden" name="resultcode" value="000"/> <input type="hidden" name="sign" value=""/> </form> <script type="text/javascript"> document.all.redirectForm.submit(); </script> </body> </html>
Thanks,
Roshan
Forum: Fixing WordPress
In reply to: redirect page locationRedirect.php entry:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="https://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <form id="redirectForm" action="https://gateway.mytmoney.mu/web/payments" method="post"> <input type="hidden" name="appId" value="<?php echo $_GET[ 'appID' ]; ?>"/> <input type="hidden" name="merTradeNo" value="<?php echo $_GET[ 'merTradeNo' ]; ?>"/> <input type="hidden" name="payload" value="<?php echo $_GET[ 'encryptedPayload' ]; ?>"/> <input type="hidden" name="paymentType" value="<?php echo $_GET[ 'paymentType' ]; ?>"/> <input type="hidden" name="sign" value="<?php echo $_GET[ 'sign' ]; ?>"/> <p><input type="submit" value="Pay By my.t money"/></p> </form> <form action="https://transaportation.local/my-account" method="post"> <input type="hidden" name="merTradeNo" value=MT001/> <input type="hidden" name="TradeNo" value="123456"/> <input type="hidden" name="tradeStatus" value="S"/> <input type="hidden" name="msg" value="SUCCESS"/> <input type="hidden" name="resultcode" value="000"/> <input type="hidden" name="sign" value=""/> </form> <script type="text/javascript"> document.all.redirectForm.submit(); </script> </body> </html>
Forum: Fixing WordPress
In reply to: redirect page locationThanks for the update. Please find below plugin code. Kindly advise what change needs to be amended.
<?php defined( 'ABSPATH' ) or exit; // Make sure WooCommerce is active if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { return; } function wc_offline_add_to_gateways( $gateways ) { $gateways[] = 'WC_Gateway_Offline'; return $gateways; } add_filter( 'woocommerce_payment_gateways', 'wc_offline_add_to_gateways' ); /** * Adds plugin page links * * @since 1.0.0 * @param array $links all plugin links * @return array $links all plugin links + our custom links (i.e., "Settings") */ function wc_offline_gateway_plugin_links( $links ) { $plugin_links = array( '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=offline_gateway' ) . '">' . __( 'Configure', 'wc-gateway-offline' ) . '</a>' ); return array_merge( $plugin_links, $links ); } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_offline_gateway_plugin_links' ); /** * Offline Payment Gateway * * Provides an Offline Payment Gateway; mainly for testing purposes. * We load it later to ensure WC is loaded first since we're extending it. * * @class WC_Gateway_Offline * @extends WC_Payment_Gateway * @version 1.0.0 * @package WooCommerce/Classes/Payment * @author Roshan */ add_action( 'plugins_loaded', 'wc_offline_gateway_init', 11 ); function wc_offline_gateway_init() { class WC_Gateway_Offline extends WC_Payment_Gateway { /** * Constructor for the gateway. */ public function __construct() { $this->id = 'offline_gateway'; $this->icon = apply_filters('woocommerce_offline_icon', ''); $this->has_fields = false; $this->method_title = __( 'Offline', 'wc-gateway-offline' ); $this->method_description = __( 'Allows offline payments. Very handy if you use your cheque gateway for another payment method, and can help with testing. Orders are marked as "on-hold" when received.', 'wc-gateway-offline' ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->instructions = $this->get_option( 'instructions', $this->description ); // Actions add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); // Customer Emails add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); } /** * Initialize Gateway Settings Form Fields */ public function init_form_fields() { $this->form_fields = apply_filters( 'wc_offline_form_fields', array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'wc-gateway-offline' ), 'type' => 'checkbox', 'label' => __( 'Enable Offline Payment', 'wc-gateway-offline' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'wc-gateway-offline' ), 'type' => 'text', 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'wc-gateway-offline' ), 'default' => __( 'Myt Money', 'wc-gateway-offline' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'wc-gateway-offline' ), 'type' => 'textarea', 'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-gateway-offline' ), 'default' => __( 'Please remit payment to Store Name upon pickup or delivery.', 'wc-gateway-offline' ), 'desc_tip' => true, ), 'instructions' => array( 'title' => __( 'Instructions', 'wc-gateway-offline' ), 'type' => 'textarea', 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'wc-gateway-offline' ), 'default' => '', 'desc_tip' => true, ), ) ); } /** * Output for the order received page. */ public function thankyou_page() { if ( $this->instructions ) { echo wpautop( wptexturize( $this->instructions ) ); } } /** * Add content to the WC emails. * * @access public * @param WC_Order $order * @param bool $sent_to_admin * @param bool $plain_text */ public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method && $order->has_status( 'on-hold' ) ) { echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; } } /** * Process the payment and return the result * * @param int $order_id * @return array */ public function process_payment( $order_id ) { $order = wc_get_order( $order_id ); //test merTradeNo added on 1 July 2022 @roshanbi $merTradeNo->billing_first_name ." ".$merTradeNo->billing_last_name .", ".$merTradeNo->billing_address_1.$merTradeNo->billing_address_2 . ", " .$merTradeNo->billing_postcode." ". $merTradeNo->billing_city. ", ". $merTradeNo->billing_state; // Mark as on-hold (we're awaiting the payment) $order->update_status( 'on-hold', __( 'Awaiting offline payment', 'wc-gateway-offline' ) ); // Reduce stock levels $order->reduce_order_stock(); // Remove cart WC()->cart->empty_cart(); // Return thankyou redirect return array( 'result' => 'success', 'redirect' => $this->get_return_url( $order ) ); //total amount added on 1 July 2022 1:52 pm $totalAmount = $order->get_total(); //RSA and payload details added on 1 July 2022 /*$totalAmount="0.01" */ $appID="1000000661"; /*$merTradeNo=""; */ $paymentType="S"; $publicKey="MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAkdWER3RVjey3ZXeggAUFm5UI/+e1zJLQ=="; $apiKey="BH+0F1KvOoZlA=="; $payload=array( "totalPrice"=>$totalAmount, "currency"=>$merTradeNo, "notifyURL"=>"https://www.myt.mu", "returnURL"=>"https://www.myt.mu", "remark"=>"This is a test payment", lang=>"en" ); //code to generate signature $payload=json_encode($payload); $rsa= new \wamp642\www\transportation\wordpress\wp-content\phpseclib\phpseclib\Crypt\RSA(); $rsa->setHash('sha1'); $rsa->setMGFHash('sha1'); $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS1); $rsa->loadKey($publickey); $encryptedPayload=base64_encode($rsa->encrypt($payload)); $signaturedata="appID&merTradeNo=$merTradeNo$merTradeNo&payload=$encryptedPayload&paymentType=$paymentType"; $sign=base64_encode(hash_hmac('sha512',$signaturedata,$apiKey,true)); //initiate payment $response = $moovpay->purchase($appID,$merTradeNo,$encryptedPayload,$paymentType,$sign); $fh = fopen(plugin_dir_path(__FILE__).'redirect.php', 'w+'); fwrite($fh, $response); fclose($fh); $redirect_url = plugin_dir_url(__FILE__).'redirect.php'; return array( 'result' => 'success', 'redirect' => $redirect_url ); } //function below calculates total and sets in a variable. Added on 1 July 2022 @roshanbi protected function calculate_totals() { $this->set_total( 'total', round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + wc_round_tax_total( array_sum( $this->get_merged_taxes( true ) ), 0 ), 0 ) ); $this->cart->set_total_tax( array_sum( $this->get_merged_taxes( false ) ) ); // Allow plugins to hook and alter totals before final total is calculated. if ( has_action( 'woocommerce_calculate_totals' ) ) { do_action( 'woocommerce_calculate_totals', $this->cart ); } // Allow plugins to filter the grand total, and sum the cart totals in case of modifications. $this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) ); } public function webhook() { header( 'HTTP/1.1 200 OK' ); $order_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : null; $nonce = isset($_REQUEST['nonce']) ? $_REQUEST['nonce'] : null; if (is_null($order_id)) return; if (is_null($nonce)) return; if (wc_get_order_item_meta($order_id,'ipn_nonce')!=$nonce) return; $order = wc_get_order( $order_id ); $order->payment_complete(); wc_reduce_stock_levels($order_id); } } // end \WC_Gateway_Offline class }
Thanks,
Roshan
Forum: Fixing WordPress
In reply to: concatenate fieldsexample we could add the orderid as below? is the syntax correct? what if one of the fields is null?
$merTradeNo->order_id .” “.$merTradeNo->billing_first_name .” “.$merTradeNo->billing_last_name .”, “.$merTradeNo->billing_address_1.$merTradeNo->billing_address_2 . “, ” .$merTradeNo->billing_postcode.” “. $merTradeNo->billing_city. “, “. $merTradeNo->billing_state;
Regards,
Roshan
Forum: Plugins
In reply to: [WooCommerce] woocomerce payment pluginShall I add below code to the plugins PHP section and set $totalAmount to $this?
protected function calculate_totals() {
$this->set_total( ‘total’, round( $this->get_total( ‘items_total’, true ) + $this->get_total( ‘fees_total’, true ) + $this->get_total( ‘shipping_total’, true ) + wc_round_tax_total( array_sum( $this->get_merged_taxes( true ) ), 0 ), 0 ) );
$this->cart->set_total_tax( array_sum( $this->get_merged_taxes( false ) ) );// Allow plugins to hook and alter totals before final total is calculated.
if ( has_action( ‘woocommerce_calculate_totals’ ) ) {
do_action( ‘woocommerce_calculate_totals’, $this->cart );
}// Allow plugins to filter the grand total, and sum the cart totals in case of modifications.
$this->cart->set_total( max( 0, apply_filters( ‘woocommerce_calculated_total’, $this->get_total( ‘total’ ), $this->cart ) ) );
}Forum: Fixing WordPress
In reply to: woocomerce payment pluginShall I add below code to the plugins PHP section and set $totalAmount to $this?
protected function calculate_totals() { $this->set_total( 'total', round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + wc_round_tax_total( array_sum( $this->get_merged_taxes( true ) ), 0 ), 0 ) ); $this->cart->set_total_tax( array_sum( $this->get_merged_taxes( false ) ) ); // Allow plugins to hook and alter totals before final total is calculated. if ( has_action( 'woocommerce_calculate_totals' ) ) { do_action( 'woocommerce_calculate_totals', $this->cart ); } // Allow plugins to filter the grand total, and sum the cart totals in case of modifications. $this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) ); }
- This reply was modified 2 years, 4 months ago by roshanbi.