title: Using Coupon Codes with Stripe
body: <p>I have a site that is using <a href="https://stripe.com/" rel="nofollow">Stripe</a> to process a subscription payments. There is only one type of subscription. 
  I followed <a href="http://net.tutsplus.com/tutorials/tools-and-tips/so-you-want-to-accept-credit-cards-online/" rel="nofollow">this tutorial</a> on NetTuts to do the initial setup.
  Had a form working fine processing subscriptions and everything worked. Client requested a coupon code. Stripe supports this so I set out trying to add a coupon code to the existing form.</p>
  
  <p>I set up coupon codes in Stripe, set my testing keys and switched to test mode in stripe. 
  I'm performing a couple of checks in my code:</p>
  
  <ol>
  <li>Check to see whether a coupon was entered, if not create a new customer object without a coupon option</li>
  <li>Check to see whether the Coupon is valid, if not return an error</li>
  </ol>
  
  <p>If there has been a coupon entered and it is valid, then pass the matching Stripe coupon object as an option when creating a new customer.</p>
  
  <pre><code> if(isset($couponCode) &amp;&amp; strlen($couponCode) &gt; 0) {
    $using_discount = true;
    try {
          $coupon = Stripe_Coupon::retrieve($couponCode);
          if($coupon !== NULL) {
             $cCode = $coupon;
          }
          // if we got here, the coupon is valid
  
       } catch (Exception $e) {
  
          // an exception was caught, so the code is invalid
          $message = $e-&gt;getMessage();
          returnErrorWithMessage($message);
  
       }
  
  
  }
  
  try
  { 
    if($using_discount == true) {
      $customer = Stripe_Customer::create(array(
            "card" =&gt; $token,
            "plan" =&gt; "basic_plan",
            "email" =&gt; $email,
            "coupon" =&gt; $cCode
         ));
    }
    else {
          $customer = Stripe_Customer::create(array(
            "card" =&gt; $token,
            "plan" =&gt; "basic_plan",
            "email" =&gt; $email
         ));
    }
  </code></pre>
  
  <p>$couponCode is populated with the form field correctly the same way all other fields are populated, I've triple checked that it is being pulled correctly.</p>
  
  <p>When I try to submit the form without a coupon code, it charges the full amount and passes through Stripe correctly.</p>
  
  <p>However if I enter either a valid OR invalid coupon code, it does not pass a coupon object with the customer object when creating a new customer object and charges the full amount when passing through Stripe.</p>
  
  <p>I've looked at the code for hours and can't seem to figure out why it is always failing to recognize the discount code and pass the matching coupon object to Stripe.</p>