We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42146
    • 73 Posts
    I'm not finding anything my searching for a answer.

    I know things can be done more efficiently with modx. i dont really want a bunch of .php files roaming around when they could just be snippits.... but i'm lost on how to do this....

    implementing stripe.com payments from https://gist.github.com/maccman/2f110e12237b4d83ae8c

    Subscribe resource. aka index.php in the link...
    <?php require_once('./config.php'); ?>
     
    <form action="charge.php" method="post">
      <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
              data-key="<?php echo $stripe['publishable_key']; ?>"
              data-amount="5000" data-description="One year's subscription"></script>
    </form>



    config.php
    <?php
    require_once('./lib/Stripe.php');
     
    $stripe = array(
      secret_key      => getenv('secret_key'),
      publishable_key => getenv('publishable_key')
    );
     
    Stripe::setApiKey($stripe['secret_key']);
    ?>


    charge.php
    <?php
      require_once(dirname(__FILE__) . '/config.php');
     
      $token  = $_POST['stripeToken'];
     
      $customer = Stripe_Customer::create(array(
          'email' => '[email protected]',
          'card'  => $token
      ));
     
      $charge = Stripe_Charge::create(array(
          'customer' => $customer->id,
          'amount'   => 5000,
          'currency' => 'usd'
      ));
     
      echo '<h1>Successfully charged $5!</h1>';
    ?>




    my thought is all these require_once(dirname(__FILE__) . '/config.php'); could then just call a snippit with the code in there... As that seems more the modx way... just dont know the right way to call it...

      • 42146
      • 73 Posts
      $modx->runSnippet('snippet name', array('param-x'=>2));


      worked for me.. thanks jsewill from irc.


      noticed i posted in the wrong fourm section sorry if someone wanted to move it..
        • 36426
        • 197 Posts
        Hi I'm trying to set this up also with Stripe.

        I've tried as you suggest:

        $modx->runSnippet('StripeConfig', array('param-x'=>2));


        and then the payment form below that, but it doesn't work.

        Where does this $modx->runSnippet code go? Thanks for any help...
          Yorkshire UK based hosting provider: https://www.simulant.uk