How can I use Stripe to delay charging a customer until a physical item is shipped?

我的梦境 提交于 2019-12-03 03:03:20

After further research, it seems there's no way to delay capturing a charge past the 7 day authorization window.

But here's one way to delay a charge:

  1. Tokenize a credit card using the stripe.js library
  2. Create a new stripe customer passing in the token as the "card" param

An example from the Stripe FAQ: https://support.stripe.com/questions/can-i-save-a-card-and-charge-it-later

Note that the longer you wait between tokenizing a card and actually charging it, the more likely your charge will be declined for various reasons (expired card, lack of funds, fraud, etc). This also adds a layer of complexity (and lost sales) since you'll need to ask a buyer to resubmit payment info.

I'd still like to confirm that a certain amount can be charged (like a "preauthorization"), but this lets me at least charge the card at a later date.

Celery has built a service to help you do this with Stripe. They are very easy to use, but note that they charge 2% per transaction.

actually you can save user token and pay later with tracking info

# get the credit card details submitted by the form or app
token = params[:stripeToken]

# create a Customer
customer = Stripe::Customer.create(
  card: token,
  description: 'description for payinguser@example.com',
  email: 'payinguser@example.com'
)

# charge the Customer instead of the card
Stripe::Charge.create(
    amount: 1000, # in cents
    currency: 'usd',
    customer: customer.id
)

# save the customer ID in your database so you can use it later
save_stripe_customer_id(user, customer.id)

# later
customer_id = get_stripe_customer_id(user)

Stripe::Charge.create(
    amount: 1500, # $15.00 this time
    currency: 'usd',
    customer: customer_id
)

Stripe release a delay method to place a hold without charging. https://stripe.com/docs/payments/payment-intents/use-cases#separate-auth-capture

<?php

require_once('stripe-php/init.php');
\Stripe\Stripe::setApiKey('your stripe key'); 
$token  = $_POST['stripeToken'];

$stripeinfo = \Stripe\Token::retrieve($token);
 
     $email = $stripeinfo->email;
   
   
   $customer = \Stripe\Customer::create(array(
    "source" => $token,
    "email" => $email)
);

?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!