Skip to content

Commit

Permalink
Push to v1.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoner committed Mar 6, 2023
1 parent d317320 commit 2e6135b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 48 deletions.
6 changes: 5 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate link: https://commerce.bitcanna.io
Tags: payments, cryptocurrency, blockchain
Requires at least: 3.0.1
Tested up to: 6.1.1
Stable tag: 1.0.17
Stable tag: 1.0.18
Requires PHP: 7.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -37,6 +37,10 @@ For our FAQ we'd like to refer you to our [documentation website](https://docs.b
5. After just a couple seconds, the payment will be performed and you can view your transaction.

== Changelog ==
= 1.0.18 =
* Check the payment_method_title to avoid conflicts with other payment methods
* Check the selected_payment_method to remove js call

= 1.0.17 =
* Fix keplr bug
* Change status order
Expand Down
4 changes: 2 additions & 2 deletions cosmos-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Cosmos Pay
* Plugin URI: https://twitter.com/bitcannaglobal
* Description: Easily accept cryptocurrency payments on your WordPress site. Enable multiple currencies from the interconnected Cosmos ecosystem.
* Version: 1.0.17
* Version: 1.0.18
* Author: BitCanna
* Author URI: https://commerce.bitcanna.io
* License: GPL-2.0+
Expand All @@ -35,7 +35,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'COSMOS_WOOCOMMERCE_VERSION', '1.0.17' );
define( 'COSMOS_WOOCOMMERCE_VERSION', '1.0.18' );



Expand Down
102 changes: 57 additions & 45 deletions public/class-cosmos-woocommerce-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function enqueue_styles() {
*
* @since 1.0.0
*/
public function enqueue_scripts() {
public function enqueue_scripts($order_id) {

/**
* This function is provided for demonstration purposes only.
Expand All @@ -95,10 +95,17 @@ public function enqueue_scripts() {
* between the defined hooks and the functions defined in this
* class.
*/
if ( is_checkout() ) {
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/bundle.js', array( 'jquery' ), $this->version, 'all' );
wp_enqueue_script( $this->plugin_name . '_mainscript', plugin_dir_url( __FILE__ ) . 'js/mainscript.js', array( 'jquery' ), $this->version, true );
}
global $woocommerce;

$selected_payment_method_id = $woocommerce->session->get( 'chosen_payment_method' );
$selected_payment_method = $woocommerce->payment_gateways->payment_gateways()[ $selected_payment_method_id ];

if($selected_payment_method->title === 'Cosmos Pay') {
if ( is_checkout() ) {
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/bundle.js', array( 'jquery' ), $this->version, 'all' );
wp_enqueue_script( $this->plugin_name . '_mainscript', plugin_dir_url( __FILE__ ) . 'js/mainscript.js', array( 'jquery' ), $this->version, true );
}
}

}
/**
Expand All @@ -117,51 +124,56 @@ public function cosmos_pay_form( $order_id ) {
$userWoo = $order->user_id;
$orderData = $order->get_data( );
$order_status = $order->get_status( );

$getMemo = wc_get_order_item_meta( $order_id , '_cosmos_memo', true );

if ($order_status !== 'cancelled') {
$order->update_status( 'pending', __( 'Awaiting Cosmos payment', 'wc-gateway-offline' ) );
}

if ( empty( $getMemo ) ) {
// Mark as pending (we're awaiting the payment)
// $order->update_status( 'pending', __( 'Awaiting Cosmos payment', 'wc-gateway-offline' ) );
// Remove cart
WC()->cart->empty_cart();
// Generate Memo
$memoBc = $this->generateRandomString();
wc_update_order_item_meta( $order_id, '_cosmos_memo', esc_attr( $memoBc ) );
$note = 'Memo created: '.esc_attr( $memoBc );
$order->add_order_note( $note , true );
$order->save();
}

if ( $orderData["status"] === 'completed' ) {
if ( is_page( 'checkout' ) ) {
wp_enqueue_script( 'jquery' );
wp_enqueue_script(
'finalBitcannaJs',
plugin_dir_url(__FILE__).'js/finalBitcanna.js'
);

if($order->payment_method_title === 'Cosmos Pay') {
$getMemo = wc_get_order_item_meta( $order_id , '_cosmos_memo', true );

if ($order_status !== 'cancelled') {
$order->update_status( 'pending', __( 'Awaiting Cosmos payment', 'wc-gateway-offline' ) );
}
} else {

$selected_payment_method_id = $woocommerce->session->get( 'chosen_payment_method' );
$selected_payment_method = $woocommerce->payment_gateways->payment_gateways()[ $selected_payment_method_id ];
$configMake = get_option("cosmos_pay_config_approved");

if ($woocommerce->payment_gateways->payment_gateways()[ 'woo-cosmos' ]->enabled === 'yes') {
if ($configMake === 'false' || $configMake === false || empty($selected_payment_method->settings['option_name'])) {
include plugin_dir_path(__FILE__) . "partials/cosmos-payment-config-tpl.php";
} else {
if ( $order_status !== 'cancelled' ) {
include plugin_dir_path(__FILE__) . "partials/cosmos-payment-tpl.php";
} else
include plugin_dir_path(__FILE__) . "partials/cosmos-payment-cancel-tpl.php";
}
if ( empty( $getMemo ) ) {
// Mark as pending (we're awaiting the payment)
// $order->update_status( 'pending', __( 'Awaiting Cosmos payment', 'wc-gateway-offline' ) );
// Remove cart
WC()->cart->empty_cart();
// Generate Memo
$memoBc = $this->generateRandomString();
wc_update_order_item_meta( $order_id, '_cosmos_memo', esc_attr( $memoBc ) );
$note = 'Memo created: '.esc_attr( $memoBc );
$order->add_order_note( $note , true );
$order->save();
}

if ( $orderData["status"] === 'completed' ) {
if ( is_page( 'checkout' ) ) {
wp_enqueue_script( 'jquery' );
wp_enqueue_script(
'finalBitcannaJs',
plugin_dir_url(__FILE__).'js/finalBitcanna.js'
);
}
} else {

$selected_payment_method_id = $woocommerce->session->get( 'chosen_payment_method' );
$selected_payment_method = $woocommerce->payment_gateways->payment_gateways()[ $selected_payment_method_id ];
$configMake = get_option("cosmos_pay_config_approved");

if ($woocommerce->payment_gateways->payment_gateways()[ 'woo-cosmos' ]->enabled === 'yes') {
if ($configMake === 'false' || $configMake === false || empty($selected_payment_method->settings['option_name'])) {
include plugin_dir_path(__FILE__) . "partials/cosmos-payment-config-tpl.php";
} else {
if ( $order_status !== 'cancelled' ) {
include plugin_dir_path(__FILE__) . "partials/cosmos-payment-tpl.php";
} else
include plugin_dir_path(__FILE__) . "partials/cosmos-payment-cancel-tpl.php";
}
}
}
}


}
/**
* Generate function for random memo
Expand Down

0 comments on commit 2e6135b

Please sign in to comment.