Skip to content

Commit

Permalink
init commit - fix the feedbacks from Wordpress
Browse files Browse the repository at this point in the history
  • Loading branch information
safepayment committed Jan 30, 2024
1 parent c188cfb commit 88de25e
Show file tree
Hide file tree
Showing 1,136 changed files with 152,460 additions and 2 deletions.
673 changes: 673 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions README.md

This file was deleted.

Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/images/.DS_Store
Binary file not shown.
Binary file added assets/images/btc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/eth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/mugglepay-logo-c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/usdc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/usdt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions assets/js/blocks/mpwp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(() => {
const { wcSettings, wcBlocksRegistry } = window.wc;

const data = wcSettings.getSetting("mpwp_data");

console.log('data', data)

const mpwpTitle = wp.htmlEntities.decodeEntities(data.title || "");
const decodeDescription = () => wp.htmlEntities.decodeEntities(data.description || "");

const mpwpPaymentMethod = {
name: "mpwp",
ariaLabel: mpwpTitle,
label: window.React.createElement(
() => {
return window.React.createElement(() => mpwpTitle);
},
null
),
content: window.React.createElement(decodeDescription, null),
edit: window.React.createElement(decodeDescription, null),
canMakePayment: () => {
console.log("canMakePaymentcanMakePayment");
console.log("canMakePayment");
return true;
},
supports: {
showSavedCards: false,
showSaveOption: false,
features: data.supports,
},
};

wcBlocksRegistry.registerPaymentMethod(mpwpPaymentMethod);
})();
Binary file added assets/setting.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions class/class-mpwp-gateway-blocks-support.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

if (! defined('ABSPATH')) {
exit;
}

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
use Automattic\WooCommerce\StoreApi\Payments\PaymentContext;
use Automattic\WooCommerce\StoreApi\Payments\PaymentResult;

final class WC_Gateway_MPWP_Blocks_Support extends AbstractPaymentMethodType {
/**
* Payment method name/id/slug.
*
* @var string
*/
protected $name = 'mpwp';


/**
* Initializes the payment method type.
*/
public function initialize() {
$this->settings = get_option( 'woocommerce_mpwp_settings', array() );

add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'failed_payment_notice' ), 8, 2 );
}

/**
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
*
* @return boolean
*/
public function is_active() {
// $payment_gateways_class = WC()->payment_gateways();
// $payment_gateways = $payment_gateways_class->payment_gateways();
// if ( ! isset( $payment_gateways[ $this->name ] ) ) {
// return false;
// }

// return $payment_gateways[ $this->name ]->is_available();

return true;
}

/**
* Returns an array of scripts/handles to be registered for this payment method.
*
* @return array
*/
public function get_payment_method_script_handles() {
$script_url = plugins_url( "/assets/js/blocks/mpwp.js", MPWP_MAIN_FILE );

wp_register_script(
"wc-mpwp-blocks",
$script_url,
array('wc-blocks-checkout', 'react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities', 'wp-i18n'),
'1.2',
true
);
wp_set_script_translations( 'wc-mpwp-blocks', 'mpwp' );
return array( "wc-mpwp-blocks" );
}

/**
* Returns an array of key=>value pairs of data made available to the payment methods script.
*
* @return array
*/
public function get_payment_method_data() {
$payment_gateways_class = WC()->payment_gateways();
$payment_gateways = $payment_gateways_class->payment_gateways();
$gateway = $payment_gateways[ $this->name ];
return array(
'title' => $this->get_setting( 'title' ),
'description' => $this->get_setting( 'description' ),
'supports' => array_filter( $gateway->supports, array( $gateway, 'supports' ) ),
'allow_saved_cards' => is_user_logged_in(),
);
}

/**
* Add failed payment notice to the payment details.
*
* @param PaymentContext $context Holds context for the payment.
* @param PaymentResult $result Result object for the payment.
*/
public function failed_payment_notice( PaymentContext $context, PaymentResult &$result ) {
if ( 'mpwp' === $context->payment_method ) {
// add_action(
// 'wc_gateway_mpwp_process_payment_error',
// function( $failed_notice ) use ( &$result ) {
// $payment_details = $result->payment_details;
// $payment_details['errorMessage'] = wp_strip_all_tags( $failed_notice );
// $result->set_payment_details( $payment_details );
// }
// );
}
}
}
Loading

0 comments on commit 88de25e

Please sign in to comment.