Plugin Directory

Changeset 3370044


Ignore:
Timestamp:
09/30/2025 12:15:49 AM (4 months ago)
Author:
chamawp
Message:

readme.txt

Location:
chama/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • chama/trunk/assets/js/chama-subscription.js

    r3327875 r3370044  
    8484  payment_element.mount('#chama-payment-element');
    8585
    86   /*=============================================HANDLE FORM SUBMISSION=============================================*/
     86  /*=============================================
     87  HANDLE FORM SUBMISSION
     88  =============================================*/
    8789  const payment_form = document.querySelector('.chama-payment-form');
    8890
    8991  payment_form.addEventListener('submit', async (e) => {
    90      //display loader
    91      $('.chama-loader-wrapper').css('display', 'flex')
    92     // Avoid a full page POST request.
    9392    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();
    107113
    108114    const form_data = {
     
    112118      'tier_id': tier_id,
    113119    };
    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.");
    140135        return;
    141136      }
    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 };
    148147      if ($('#chama_first_name').val() && $('#chama_last_name').val()) {
    149148        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 = {
    161154        '_wpnonce': nonce,
    162155        'base_amount': input_amount,
     
    171164      };
    172165      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
    188185      const confirmIntent = type === "setup" ? stripe.confirmSetup : stripe.confirmPayment;
    189186      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;
    191188      }
    192189      if (clientSecret) {
     
    196193          confirmParams: {
    197194            return_url: confirmation_url,
    198             payment_method_data: {
    199               billing_details: billing_details
    200             }
     195            payment_method_data: { billing_details }
    201196          },
    202197        });
    203198
    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    }
    217211  });
     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
    218227
    219228});
  • chama/trunk/chama.php

    r3348724 r3370044  
    44     * Plugin URI:  https://www.chamawp.com
    55     * Description: Monetize your content with donations, paid subscriptions, crowdfunding and commissions.
    6      * Version:     1.0.10
     6     * Version:     1.0.11
    77     * Author:      Leetoo
    88     * Author URI:  https://leetoo.net/
     
    3434
    3535                if (! defined('CHAMA_VERSION')) {
    36                     define('CHAMA_VERSION', '1.0.10');
     36                    define('CHAMA_VERSION', '1.0.11');
    3737                }
    3838                if (! defined('CHAMAWP_URL')) {
  • chama/trunk/inc/options.php

    r3348724 r3370044  
    11021102            '',
    11031103            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;">';
    11051105            },
    11061106            $page_slug
  • chama/trunk/inc/protection.php

    r3347183 r3370044  
    451451                }
    452452                // $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'];
    454454                if (! in_array($meta_key, $meta_data_to_filter)) {
    455455                    return $metadata;
     
    457457                $post_type = get_post_type($post_id);
    458458
    459                 if ($post_type !== 'comic') {
    460                     return $metadata;
     459                if ( $post_type !== 'comic' && $post_type !== 'manga_chapter' ) {
     460                return $metadata;
    461461                }
    462462                return chama_restrict_metadata($metadata, $post_id);
  • chama/trunk/inc/template-functions.php

    r3348711 r3370044  
    18071807                    return new WP_REST_Response($e->getError()->message, 400);
    18081808                } 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);
    18101810                }
    18111811                return new WP_REST_Response(['clientSecret' => $payment_intent->client_secret, 'receiptId' => $receipt_id], 200);
    18121812            } else {
    1813                 return new WP_REST_Response('An error occured with the payment processor', 500);
     1813                return new WP_REST_Response($e->getMessage(), 500);
    18141814            }
    18151815
     
    18511851                    return new WP_REST_Response($e->getError()->message, 400);
    18521852                } 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);
    18541854                }
    18551855                return new WP_REST_Response(['clientSecret' => $setup_intent->client_secret, 'setupIntent' => $setup_intent_id], 200);
    18561856            } else {
    1857                 return new WP_REST_Response('An error occured with the payment processor', 500);
     1857                return new WP_REST_Response($e->getMessage(), 500);
    18581858            }
    18591859
     
    21082108                    return new WP_REST_Response($e->getError()->message, 400);
    21092109                } 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);
    21112111                }
    21122112                if ($subscription->pending_setup_intent !== null) {
     
    21302130                }
    21312131            } else {
    2132                 return new WP_REST_Response('An error occured with the payment processor', 500);
     2132                return new WP_REST_Response($e->getMessage(), 500);
    21332133            }
    21342134
  • chama/trunk/readme.txt

    r3348728 r3370044  
    77Tested up to: 6.8
    88Requires PHP: 7.4
    9 Stable tag: 1.0.10
     9Stable tag: 1.0.11
    1010Text Domain: chama
    1111License: GPLv3 or later
     
    8282
    8383== Changelog ==
     84
     85= 1.0.11 - 2025-09-29 =
     86* UPDATE: Added support for the Manga Chapter post in Toocheke
    8487
    8588= 1.0.10 - 2025-08-22 =
Note: See TracChangeset for help on using the changeset viewer.