Changeset 3370044
- Timestamp:
- 09/30/2025 12:15:49 AM (4 months ago)
- Location:
- chama/trunk
- Files:
-
- 6 edited
-
assets/js/chama-subscription.js (modified) (4 diffs)
-
chama.php (modified) (2 diffs)
-
inc/options.php (modified) (1 diff)
-
inc/protection.php (modified) (2 diffs)
-
inc/template-functions.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
chama/trunk/assets/js/chama-subscription.js
r3327875 r3370044 84 84 payment_element.mount('#chama-payment-element'); 85 85 86 /*=============================================HANDLE FORM SUBMISSION=============================================*/ 86 /*============================================= 87 HANDLE FORM SUBMISSION 88 =============================================*/ 87 89 const payment_form = document.querySelector('.chama-payment-form'); 88 90 89 91 payment_form.addEventListener('submit', async (e) => { 90 //display loader91 $('.chama-loader-wrapper').css('display', 'flex')92 // Avoid a full page POST request.93 92 e.preventDefault(); 94 var base_rest_url = $('#chama_base_rest_url').val(); 95 var confirmation_url = $('#chama_confirmation_url').val(); 96 var email = $('#chama_email').val(); 97 var nonce = $('#_wpnonce').val(); 98 var description = $('#chama_description').val(); 99 var transaction_type = $('#chama_type').val(); 100 var tier_id = $('#chama_tier_id').val(); 101 var product_id = $('#chama_product_id').val(); 102 var price_id = $('#chama_price_id').val(); 103 var full_name = null; 104 var billing_details = null; 105 var captcha_response = null; 106 var input_amount = $('#chama_subscription_amount').val(); 93 94 // Show loader 95 $('.chama-loader-wrapper').css('display', 'flex'); 96 97 // Disable button 98 const payBtn = payment_form.querySelector('.chama-pay-button'); 99 payBtn.disabled = true; 100 $('.chama-pay-button').addClass('chama-disabled-button'); 101 102 // Collect values 103 const base_rest_url = $('#chama_base_rest_url').val(); 104 let confirmation_url = $('#chama_confirmation_url').val(); 105 const email = $('#chama_email').val(); 106 const nonce = $('#_wpnonce').val(); 107 const description = $('#chama_description').val(); 108 const transaction_type = $('#chama_type').val(); 109 const tier_id = $('#chama_tier_id').val(); 110 const product_id = $('#chama_product_id').val(); 111 const price_id = $('#chama_price_id').val(); 112 const input_amount = $('#chama_subscription_amount').val(); 107 113 108 114 const form_data = { … … 112 118 'tier_id': tier_id, 113 119 }; 114 // Disable the form from submitting twice. 115 payment_form.querySelector('.chama-pay-button').disabled = true; 116 $('.chama-pay-button').addClass('chama-disabled-button'); 117 118 // Trigger form validation and wallet collection 119 const { error: submitError } = await elements.submit(); 120 if (submitError) { 121 handle_error(submitError.message); 122 $('.chama-loader-wrapper').css('display', 'none'); 123 return; 124 } 125 126 // server validation 127 const { status, message } = await $.ajax({ 128 url: base_rest_url + "v1/stripe/validate", 129 type: "POST", 130 data: form_data, 131 error: function (data) { 132 var response = JSON.parse(data.responseText); 133 134 $('#chama-payment-errors').html(response.message); 135 $('#chama-payment-errors').addClass('show'); 136 // Re-enable the form so the customer can resubmit. 137 payment_form.querySelector('.chama-pay-button').disabled = false; 138 $('.chama-pay-button').removeClass('chama-disabled-button'); 139 $('.chama-loader-wrapper').css('display', 'none'); 120 121 try { 122 // Validate form with Stripe backend 123 const { error: submitError } = await elements.submit(); 124 if (submitError) throw new Error(submitError.message); 125 126 let validateResponse; 127 try { 128 validateResponse = await $.ajax({ 129 url: base_rest_url + "v1/stripe/validate", 130 type: "POST", 131 data: form_data, 132 }); 133 } catch (xhr) { 134 showError(xhr.responseText || "Validation failed."); 140 135 return; 141 136 } 142 }); 143 144 if (status == 'passed') { 145 //create payment intent 146 147 137 138 const { status, message } = validateResponse; 139 if (status !== 'passed') { 140 showError(message || "Validation did not pass."); 141 return; 142 } 143 144 // Build billing details 145 let full_name = null; 146 let billing_details = { email: email }; 148 147 if ($('#chama_first_name').val() && $('#chama_last_name').val()) { 149 148 full_name = $('#chama_first_name').val() + ' ' + $('#chama_last_name').val(); 150 billing_details = { 151 email: email, 152 name: full_name, 153 }; 154 } 155 else { 156 billing_details = { 157 email: email 158 } 159 } 160 var values = { 149 billing_details.name = full_name; 150 } 151 152 // Prepare subscription values 153 let values = { 161 154 '_wpnonce': nonce, 162 155 'base_amount': input_amount, … … 171 164 }; 172 165 if ($('#chama-captcha-response').val()) { 173 captcha_response = $('#chama-captcha-response').val(); 174 values.captcha_response = captcha_response; 175 } 176 const { type, clientSecret, subscriptionId, receiptId, paymentIntent } = await $.ajax({ 177 url: base_rest_url + "v1/stripe/subscription", 178 type: "POST", 179 data: values, 180 error: function (data) { 181 $('#chama-payment-errors').html(data.responseText); 182 $('#chama-payment-errors').addClass('show'); 183 $('.chama-loader-wrapper').css('display', 'none'); 184 return; 185 } 186 }); 187 166 values.captcha_response = $('#chama-captcha-response').val(); 167 } 168 169 // Create subscription 170 let subscriptionResponse; 171 try { 172 subscriptionResponse = await $.ajax({ 173 url: base_rest_url + "v1/stripe/subscription", 174 type: "POST", 175 data: values, 176 }); 177 } catch (xhr) { 178 showError(xhr.responseText || "Subscription request failed."); 179 return; 180 } 181 182 const { type, clientSecret, subscriptionId, receiptId, paymentIntent } = subscriptionResponse; 183 184 // Handle Stripe confirmation 188 185 const confirmIntent = type === "setup" ? stripe.confirmSetup : stripe.confirmPayment; 189 186 if (subscriptionId) { 190 confirmation_url = confirmation_url +'&subscription_id=' + subscriptionId + '&receipt_id=' + receiptId + '&payment_intent=' + paymentIntent;187 confirmation_url += '&subscription_id=' + subscriptionId + '&receipt_id=' + receiptId + '&payment_intent=' + paymentIntent; 191 188 } 192 189 if (clientSecret) { … … 196 193 confirmParams: { 197 194 return_url: confirmation_url, 198 payment_method_data: { 199 billing_details: billing_details 200 } 195 payment_method_data: { billing_details } 201 196 }, 202 197 }); 203 198 204 //error happened 205 if (error) { 206 handle_error(error.message); 207 // Re-enable the form so the customer can resubmit. 208 payment_form.querySelector('.chama-pay-button').disabled = false; 209 $('.chama-pay-button').removeClass('chama-disabled-button'); 210 $('.chama-loader-wrapper').css('display', 'none'); 211 return; 212 } 213 } 214 } 215 216 199 if (error) throw new Error(error.message); 200 } 201 202 } catch (err) { 203 // Any JS/Stripe thrown errors 204 showError(err.message || "An unexpected error occurred."); 205 } finally { 206 // Always hide loader and re-enable form 207 $('.chama-loader-wrapper').css('display', 'none'); 208 payBtn.disabled = false; 209 $('.chama-pay-button').removeClass('chama-disabled-button'); 210 } 217 211 }); 212 213 /*============================================= 214 HELPER: show error messages 215 =============================================*/ 216 function showError(msg) { 217 $('#chama-payment-errors').html(msg); 218 $('#chama-payment-errors').addClass('show'); 219 $('.chama-loader-wrapper').css('display', 'none'); 220 const payBtn = document.querySelector('.chama-pay-button'); 221 if (payBtn) { 222 payBtn.disabled = false; 223 $('.chama-pay-button').removeClass('chama-disabled-button'); 224 } 225 } 226 218 227 219 228 }); -
chama/trunk/chama.php
r3348724 r3370044 4 4 * Plugin URI: https://www.chamawp.com 5 5 * Description: Monetize your content with donations, paid subscriptions, crowdfunding and commissions. 6 * Version: 1.0.1 06 * Version: 1.0.11 7 7 * Author: Leetoo 8 8 * Author URI: https://leetoo.net/ … … 34 34 35 35 if (! defined('CHAMA_VERSION')) { 36 define('CHAMA_VERSION', '1.0.1 0');36 define('CHAMA_VERSION', '1.0.11'); 37 37 } 38 38 if (! defined('CHAMAWP_URL')) { -
chama/trunk/inc/options.php
r3348724 r3370044 1102 1102 '', 1103 1103 function () { 1104 echo '<h2 >Header Styles</h2><hr style="margin:1em 0;">';1104 echo '<h2 style="color:#2271b1; text-transform:uppercase;">Header Styles</h2><hr style="margin:1em 0;">'; 1105 1105 }, 1106 1106 $page_slug -
chama/trunk/inc/protection.php
r3347183 r3370044 451 451 } 452 452 // $meta_data_to_filter = array('desktop_comic_editor', 'comic_blog_post_editor', 'mobile_comic_2nd_language_editor', 'comic_2nd_language_blog_post_editor', 'desktop_comic_2nd_language_editor', 'transcript'); 453 $meta_data_to_filter = ['desktop_comic_editor', 'mobile_comic_2nd_language_editor', 'desktop_comic_2nd_language_editor', 'transcript' ];453 $meta_data_to_filter = ['desktop_comic_editor', 'mobile_comic_2nd_language_editor', 'desktop_comic_2nd_language_editor', 'transcript', 'manga_chapter_pages']; 454 454 if (! in_array($meta_key, $meta_data_to_filter)) { 455 455 return $metadata; … … 457 457 $post_type = get_post_type($post_id); 458 458 459 if ( $post_type !== 'comic') {460 return $metadata;459 if ( $post_type !== 'comic' && $post_type !== 'manga_chapter' ) { 460 return $metadata; 461 461 } 462 462 return chama_restrict_metadata($metadata, $post_id); -
chama/trunk/inc/template-functions.php
r3348711 r3370044 1807 1807 return new WP_REST_Response($e->getError()->message, 400); 1808 1808 } catch (Exception $e) { 1809 return new WP_REST_Response( 'An error occured with the payment processor', 500);1809 return new WP_REST_Response($e->getMessage(), 500); 1810 1810 } 1811 1811 return new WP_REST_Response(['clientSecret' => $payment_intent->client_secret, 'receiptId' => $receipt_id], 200); 1812 1812 } else { 1813 return new WP_REST_Response( 'An error occured with the payment processor', 500);1813 return new WP_REST_Response($e->getMessage(), 500); 1814 1814 } 1815 1815 … … 1851 1851 return new WP_REST_Response($e->getError()->message, 400); 1852 1852 } catch (Exception $e) { 1853 return new WP_REST_Response( 'An error occured with the payment processor', 500);1853 return new WP_REST_Response($e->getMessage(), 500); 1854 1854 } 1855 1855 return new WP_REST_Response(['clientSecret' => $setup_intent->client_secret, 'setupIntent' => $setup_intent_id], 200); 1856 1856 } else { 1857 return new WP_REST_Response( 'An error occured with the payment processor', 500);1857 return new WP_REST_Response($e->getMessage(), 500); 1858 1858 } 1859 1859 … … 2108 2108 return new WP_REST_Response($e->getError()->message, 400); 2109 2109 } catch (Exception $e) { 2110 return new WP_REST_Response( 'An error occured with the payment processor', 500);2110 return new WP_REST_Response($e->getMessage(), 500); 2111 2111 } 2112 2112 if ($subscription->pending_setup_intent !== null) { … … 2130 2130 } 2131 2131 } else { 2132 return new WP_REST_Response( 'An error occured with the payment processor', 500);2132 return new WP_REST_Response($e->getMessage(), 500); 2133 2133 } 2134 2134 -
chama/trunk/readme.txt
r3348728 r3370044 7 7 Tested up to: 6.8 8 8 Requires PHP: 7.4 9 Stable tag: 1.0.1 09 Stable tag: 1.0.11 10 10 Text Domain: chama 11 11 License: GPLv3 or later … … 82 82 83 83 == Changelog == 84 85 = 1.0.11 - 2025-09-29 = 86 * UPDATE: Added support for the Manga Chapter post in Toocheke 84 87 85 88 = 1.0.10 - 2025-08-22 =
Note: See TracChangeset
for help on using the changeset viewer.