代码之家  ›  专栏  ›  技术社区  ›  Nrc

条纹。每月订阅

  •  0
  • Nrc  · 技术社区  · 7 年前

    我想用Stripe和PHP实现每月订阅。我遵照指示: https://stripe.com/docs/recipes/subscription-signup#creating-the-signup-form-using-checkout

    2-Index.php:

    <form action="create_subscription.php" method="POST">
      <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="pk_test_SomeNumbersAndLetters"
        data-image="images/stripe.png"
        data-name="F. subscription"
        data-description="9.99 montly fee"
        data-amount="999"
        data-label="Sign Me Up!">
      </script>
    </form>
    

    3-创建\u subscription.php。我安装了Composer,我想,它工作得很好

    require_once('vendor/autoload.php');
    \Stripe\Stripe::setApiKey("sk_test_SomeNumbersAndLetters");
    
    try
    {
      $customer = \Stripe\Customer::create(array(
        'email' => $_POST['stripeEmail'],
        'source'  => $_POST['stripeToken'],
      ));
    
      $subscription = \Stripe\Subscription::create(array(
        'customer' => $customer->id,
        'items' => array(array('plan' => 'weekly_box')),
      ));
    
      header('Location: thankyou.php');
      exit;
    }
    catch(Exception $e)
    {
      header('Location:oops.php');
      error_log("unable to sign up customer:" . $_POST['stripeEmail'].
        ", error:" . $e->getMessage());
    }
    

    如果我明白的话,我必须更改计划的id。我应该把它放哪儿?
    如果我明白的话,我还得换脱衣舞和脱衣舞邮件。如果是的话,我从哪里得到的,我必须把它放在哪里?

    2 回复  |  直到 7 年前
        1
  •  0
  •   Justin T.    7 年前

    “如果我明白,我必须更改计划的id。我应该把它放哪儿?”

    'items' => array(array('plan' => 'PLAN_ID_HERE'))...
    

    -你不需要改变这些,让它们保持原样 $_POST['stripeEmail'] $_POST['stripeToken'] 这些参数将从Checkout应用程序中拉入。

    确保使用正确的“测试”数据/API键进行测试,然后在准备好使其生效后,用正确的“活动”数据/API键替换它们。

        2
  •  0
  •   Nrc    7 年前