Stripe API recurring payments with Php -
i'm using stripe api 1 time payments, works fine using like:
$stripe = array("secret_key" => "my_secret_key", "publishable_key" => "my_publishable_key"); stripe::setapikey($stripe['secret_key']); try { $charge = stripe_charge::create(array( "amount" => round($_post['amount'] * 100, 0), "currency" => "usd", "card" => array( "number" => 111111111111111111, "exp_month" => 10, "exp_year" => 2017, "cvc" => 321, ), "description" => $_post['item_name'])); $json = json_decode($charge); $amount_charged = round(($json->{'amount'} / 100), 2); //process payment here...... } catch (stripe_carderror $e) { $body = $e->getjsonbody(); print json_encode($json); }
now want able have recurring payments, capturing user credit card info, , running cron job once month. above work fine, or need else. i'm aware stripe has built in feature recurring payments, in case payments each month have different amount.
the thing you're missing in example customer records. see, stripe doesn't allow re-use token. they're one-time use. in order build out functionality you're looking for, you'd need securely store payment details somewhere. if you're pci compliant, could, of course, on own local datastore; however, if want make easy on yourself, build out customer records each user , associated payment methods.
when you're constructing charge normally, you'll use create charge api request.
you're doing , passing token id source
-argument. instead, first make customer , attach payment source creating card. (i recommend doing them 2 separate steps, can better manage customers multiple payment sources.)
then, charge record again, make create charge api request again, instead pass in customer id in customer
-argument , (optionally) pass in source id (card_xxx
) source
-argument. if don't pass in source
-argument, pass customer
-argument, use default payment source.
hope helps!
Comments
Post a Comment