We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26063
    • 20 Posts
    I would like to to integrate Stripe Credit Card processing into a ModX Evo site. Would appreciate any suggestions on how to place the PHP scrips the Stripe into forms.
      • 4385
      • 372 Posts
      I came by the forum to find an answer to something else, but I wanted to stop by a give you an answer.
      I wrote this for evo 3 years ago as a proof of concept. Looks like it still works.

      [[MODxStripe? &PublishableKey=`ok_we34Ghh353lpgAsd343eGT33`]]
      
      [[!FormIt?
         &hooks=`FormItStripe,redirect`
         &emailTpl=`MyEmailChunk`
         &emailTo=`[email protected]`
         &redirectTo=`1`
      ]]
      
      [[$form?]]
      


      you will need to create the properties for the FormItStripe or hardcode your key.

      MODxStripe
      <?php
      $PublishableKey = $scriptProperties['PublishableKey'];
      
      $modx->regClientStartupScript('https://js.stripe.com/v1/');
      $modx->regClientStartupScript('https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js');
      $modx->regClientStartupHTMLBlock('<script type="text/javascript">Stripe.setPublishableKey(\'' . $PublishableKey . '\');</script>');
      $modx->regClientStartupScript(MODX_ASSETS_URL.'js/jquery.stripe.js');
      


      FormItStripe
      <?php
      require_once $modx->getOption('core_path').'components/Stripe/lib/Stripe.php';
      Stripe::setApiKey($scriptProperties['apiKey'];);
      
      // get the credit card details submitted by the form
      $amount = $hook->getValue('totalAmount');
      $token = $hook->getValue('stripeToken');
      
      // create the charge on Stripe's servers - this will charge the user's card
      $charge = Stripe_Charge::create(array(
        "amount" => $amount, // amount in cents, again
        "currency" => "usd",
        "card" => $token,
        "description" => "[email protected]")
      );
      return true;
      


      form chunk
      <h1>Charge $15 with Stripe</h1>
      <!-- to display errors returned by createToken -->
      <span class="payment-errors"></span>
      <form action="[[~[[*id]]]]" method="post" id="payment-form" class="form">
      <input type="hidden" name="totalAmount" value="1500" />
          <div class="form-row">
              <label>Card Number</label>
              <input type="text" size="20" autocomplete="off" class="card-number" value="4242424242424242"/>
          </div>
          <div class="form-row">
              <label>CVC</label>
              <input type="text" size="4" autocomplete="off" class="card-cvc" value="345"/>
          </div>
          <div class="form-row">
              <label>Expiration (MM/YYYY)</label>
              <input type="text" size="2" class="card-expiry-month" value="08"/>
              <span> / </span>
              <input type="text" size="4" class="card-expiry-year" value="2013"/>
          </div>
          <button type="submit" class="submit-button">Submit Payment</button>
      </form>
      
        DropboxUploader -- Upload files to a Dropbox account.
        DIG -- Dynamic Image Generator
        gus -- Google URL Shortener
        makeQR -- Uses google chart api to make QR codes.
        MODxTweeter -- Update your twitter status on publish.