From 384e39ff2dce1d24644d1c2209d82a2639712b27 Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Tue, 19 Mar 2024 19:53:30 +0000 Subject: [PATCH] Bump version to 1.0.53 and add stripePaymentIntent for 3d secure --- plugin.json | 4 +- woonuxt.php | 205 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 138 insertions(+), 71 deletions(-) diff --git a/plugin.json b/plugin.json index 608cb49..07e8ab5 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "name": "woonuxt Settings", - "version": "1.0.52", + "version": "1.0.53", "download_url": "https://github.com/scottyzen/woonuxt-settings/releases/download/1.0.52/woonuxt-settings.zip", "homepage": "https://woonuxt.com/", @@ -13,7 +13,7 @@ "sections": { "description": "WooNuxt is unmatched when it comes to performance and scalability. Reap the benefits of having a online store that out performs all of your competitors.", "installation": "(Recommended) Installation instructions.", - "changelog": "

1.0.52

Bump version.

1.0.51

Inhance Social media fileds and schema.

<

1.0.50

Add SEO settings

1.0.49

Add functionality to increase max query amount if there are more than 100 products

1.0.45

Fix error when WooCommerce is disabled or not installed

" + "changelog": "

1.0.53

Add stripePaymentIntent for 3d secure.

1.0.52

Bump version.

1.0.51

Inhance Social media fileds and schema.

<

1.0.50

Add SEO settings

1.0.49

Add functionality to increase max query amount if there are more than 100 products

1.0.45

Fix error when WooCommerce is disabled or not installed

" }, "icons": { diff --git a/woonuxt.php b/woonuxt.php index eb0211f..a656668 100644 --- a/woonuxt.php +++ b/woonuxt.php @@ -5,7 +5,7 @@ Author: Scott Kennedy Author URI: http://scottyzen.com Plugin URI: https://github.com/scottyzen/woonuxt-settings -Version: 1.0.52 +Version: 1.0.53 Text Domain: woonuxt GitHub Plugin URI: scottyzen/woonuxt-settings GitHub Plugin URI: https://github.com/scottyzen/woonuxt-settings @@ -16,7 +16,7 @@ exit(); } -define('WOONUXT_SETTINGS_VERSION', '1.0.52'); +define('WOONUXT_SETTINGS_VERSION', '1.0.53'); define('MY_WOOCOMMERCE_VERSION', '8.5.2'); define('WP_GRAPHQL_VERSION', '1.20.0'); define('WOO_GRAPHQL_VERSION', '0.19.0'); @@ -138,21 +138,21 @@ function woonuxtUpdateAvailable() function wooNuxtOptionsPageHtml() { - $options = get_option('woonuxt_options'); ?> + $options = get_option('woonuxt_options');?>

WooNuxt

- + - +
+ do_settings_sections('woonuxt'); + submit_button();?>
'; printf('

There is an update available for the WooNuxt Settings Plugin. Click %s to update from version %s to %s

', esc_url($update_url), esc_html($update_text), esc_html($current_version), esc_html($github_version)); - echo ''; ?> + echo '';?> '; $primary_color = isset($options['primary_color']) ? $options['primary_color'] : '#7F54B2'; -?> + ?>
@@ -476,19 +476,19 @@ function global_setting_callback() - $value) : ?> - - - - - - - - + $value): ?> + + + + + + + + @@ -582,44 +582,44 @@ function global_setting_callback() - $value) : ?> - - - - - - - - - + $value): ?> + + + + + + + + + +endif;?> @@ -713,7 +713,7 @@ function global_setting_callback() 'order' => 'DESC', 'meta_key' => '_price', ]); - while ($loop->have_posts()) : + while ($loop->have_posts()): $loop->the_post(); global $product; $options['maxPrice'] = $product->get_price(); @@ -748,6 +748,33 @@ function global_setting_callback() $total_number_of_products = wp_count_posts('product')->publish; return $amount = $total_number_of_products > 100 ? $total_number_of_products : $amount; }, 10, 5); + + register_graphql_field('RootQuery', 'stripePaymentIntent', [ + 'type' => 'PaymentIntent', + 'resolve' => function () { + $amount = floatval(WC()->cart->get_total(false)) * 100; + $currency = get_woocommerce_currency(); + $payment_intent = create_payment_intent($amount, $currency); + + return [ + 'amount' => $amount, + 'currency' => $currency, + 'clientSecret' => $payment_intent['client_secret'], + 'id' => $payment_intent['id'], + 'error' => $payment_intent['error'], + ]; + }, + ]); + + register_graphql_object_type('PaymentIntent', [ + 'fields' => [ + 'amount' => ['type' => 'Int'], + 'currency' => ['type' => 'String'], + 'clientSecret' => ['type' => 'String'], + 'id' => ['type' => 'String'], + 'error' => ['type' => 'String'], + ], + ]); }); /** @@ -762,3 +789,43 @@ function global_setting_callback() wp_die(); }); + +/** + * Creates payment intent using current cart or order and store details. + * + * @param {int} $order_id The id of the order if intent created from Order. + * @throws Exception - If the create intent call returns with an error. + * @return array + */ +// public function create_payment_intent( $order_id = null ) { + +/** + * Stripe + */ +function create_payment_intent($amount, $currency) +{ + // check if WC_Stripe class exists + if (!class_exists('WC_Stripe_API')) { + return new WP_Error('stripe_not_installed', 'Stripe is not installed'); + } + + $payment_intent = WC_Stripe_API::request( + [ + 'amount' => $amount, + 'currency' => $currency, + 'payment_method_types' => ['card'], + 'capture_method' => 'automatic', + ], + 'payment_intents' + ); + + if (!empty($payment_intent->error)) { + throw new Exception($payment_intent->error->message); + } + + return [ + 'id' => $payment_intent->id, + 'client_secret' => $payment_intent->client_secret, + 'error' => $payment_intent->error, + ]; +} \ No newline at end of file