How to collect billing address through Stripe Payment Request Button - stripe-payments

I'm creating a payment request like this:
const paymentRequest = stripe.paymentRequest({
country: config.stripeCountry,
currency: config.currency,
total: {
label: 'Total',
amount: parseInt((paymentAmounts.totalAmount * 100).toFixed())
},
requestShipping: true,
requestPayerEmail: true,
requestPayerName: true,
// It seems this one is not working
shippingOptions: config.shippingOptions
})
Now I'd like to collect a customer's billing address. But the doc says:
Requesting the payer’s name, email, or phone is optional, but highly
recommended, as it also results in collecting their billing address
for Apple Pay. The billing address can be used to perform address
verification and block fraudulent payments. For all other payment
methods, the billing address is automatically collected when
available.
So how shall I collect their billing address with the payer's name, email or phone?

For Apple Pay, requesting one of name, email, or phone (which you're already doing via requestPayerEmail and requestPayerName) triggers billing address to be collected. For other payment methods, you don't have to do anything.
In other words, you're all set as-is.
https://stripe.com/docs/stripe-js/reference#stripe-payment-request
We highly recommend you collect at least one of name, email, or phone as this also results in collection of billing address for Apple Pay. The billing address can be used to perform address verification and block fraudulent payments. For all other payment methods, the billing address is automatically collected when available.

Related

Angular/node.js Stripe Checkout Integration (1 account to facilitate payments from third party payer to third party receiver)

Man, I have been at this for some days and can't find a good solution to this. I want to use my account (via public key and private key) to facilitate payments from one account to another (nothing will be going into my account). On the front-end I have:
checkout(amount) {
const strikeCheckout = (<any>window).StripeCheckout.configure({
key: environment.PRODUCTION==='true'?stripeLiveClientId:stripeTestClientId,
locale: 'auto',
token: (stripeToken: any) => {
if(stripeToken){
console.log(stripeToken)
this.createCharge(stripeToken,amount)
}
}
});
strikeCheckout.open({
name: 'Camel Stripe',
description: 'Stripe Checkout',
amount: amount
});
}
Just a small snipet, but essentially this just captures the credit card and email and ensures it is a valid credit card and then makes a stripe token. I then pass this token to the node backend and do:
stripe.paymentIntents.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
}).then(charge => {
return res.json({ success: true, message: 'Success', result: charge })
}).catch(error => {
res.status(400).json({ success: false, status: 400, message: error });
});
//})
};
No matter how I structure it, it always end's up getting the payment to my account, the account with the public/private key. Does anyone know a way I can use this token since it has the necessary information, and send the money to another account?
You can't accept payments and move the funds into a completely different Stripe account unless you're using Connect.
To piggy back on Paul's comment, after much research on Stripe Connect I wanted to share my findings. Please note this is specific to my use case and is using angular/express.
Connect offers multi-party payments, meaning you can receive funds from 1 user, then route them into another users account. You will need a stripe connect account. After that you connect an account, aka create account. They offer 3 account types all these account types need to be
Custom: basically is if you don't want the account you're routing to to see anything stripe related, meaning it is white labeled and the user has no dashboard or view of what is going on in the background.
Standard(the one I chose): this account will have a full stripe dashboard, it has all the functionality that an account would have that you make on your own. You will get a unique account id relevant to your specific connect account environment, on their end, they will have multiple account ids depending on how many other connects they are connected to, or if it is an already existing account. You will need to use this api to get the link to have them verify information before they are integrated into your connect environment account link api
Express: they will have a slimmed down version of a dashboard, it is similar to standard with less functionality
At this point you're ready to start routing payments. I did angular on the front-end, here is an example basically this simply creates a stripeToken, which is a verification that the card data is valid. You need to pass this to a backend to make use of it, this will not create any charges.
On the backend, I used express, you use the charge api You pass the stripeToken as the source attribute. One important step is to add the stripe account id you see in your connected accounts dashboard. It should look similar to:
stripe.charges.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
},{
stripeAccount:'{{acctId}}'
})
This should be sufficient to get your payments routing to the necessary account while leveraging a simple UI checkout.
One thing to note about the charges API, this is an older API and has less functionality. For my use case (US CA only with only card payments) it is sufficient. If you have a more complicated use case, or maybe your app is for heavy prod use to many users you should look into payment intents.

Stripe adding paymentMethod to trial subscription and later validate credit card

I'm working on stripe integration with react node.js
While creating a subscription without trial, I have no issues, and all use-cases are much simple.
But, I'm trying to create free trial without collecting credit card details, later when trial expired, I would like to collect credit card details
Server side: Creating Trial Subscription without payment method:
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: priceId }],
trial_end: expiredAt.unix(),
expand: ['latest_invoice.payment_intent'],
});
ClientSide: Later when trial expired, I would like to collect credit card details(paymentMethod), check if user action is required due to failures or 3ds and update the subscription by updating the customer's default payment_method:
const updateCustomerDefaultPaymentMethod = await stripe.customers.update(
customerId,
{
invoice_settings: {
default_payment_method: req.body.paymentMethodId,
},
}
);
How can I update the subscription to perform paymentIntent or charge the user, and return to client same subscription object with status 'in_complete' same as when creating subscription without trial_period?
Currently when running my code, I keep getting status='active' because the first invoice is in status='paid' with price of '0$'.
In the case of a free trial, creating a subscription won't result in an initial payment, and Stripe will instead create a SetupIntent under the hood for you automatically. This SetupIntent is meant to be used when collecting the customer's payment method. So at any point during the trial, the customer would need to return to your app to enter their credit card details, which you would then save using the SetupIntent:
subscription.pending_setup_intent
Confirm the SetupIntent with the collected card details
Once the payment method is setup and saved to the customer (as the default payment method for invoices) it will be used to pay for the subscription's first invoice when the trial ends. The first payment after a trial is considered an off-session payment (last FAQ), so if that payment fails Stripe will attempt to recollect the payment using the usual smart retries and dunning functionality.
In a nutshell, you need to use the SetupIntent that's created (and attached to the subscription) to save the user's payment information.

Stripe invoice for one time charge

I'm trying to create a one-time charge in Stripe, I have already added all my products to Stripe, and I'm creating an order and charge like this:
const order = await stripe.orders.create({
customer: customer.id,
currency: 'usd',
items: [
'sku_0001',
'sku_0002',
],
email: 'test#test.com',
});
const charge = await stripe.orders.pay(order.id, {
customer: customer.id,
email: 'test#test.com',
});
However, on the invoice send my Stripe, it only shows one item, with description: Payment for order or_1GTmxxxxxxQjbLdncktm0.
How can I have all the ordered items show up on the invoice, or at the very least, something a bit more descriptive. My customers have no idea what this order ID means, or what they have paid for.
If you're developing a new integration, I'd advise against using Orders, since it is deprecated.
The best solution depends on what you're trying to do, beyond the invoice mechanics. One great option is to use Checkout for one-time payments to charge your customers. It does not leverage the products directly, but you can use that same data on your server to populate the line items.
Your other option is to create the Invoice directly, by adding line items to your customer. When you do this, and choose to send an email invoice, your customer will see a hosted invoice page with all invoiced items included.

How to set commission fee on stripe while Creating Separate Charges and Transfers?

How to set commission for Buyer & Seller both using stripe connect. I am using https://stripe.com/docs/connect/charges-transfers.
we want to hold money on our stripe account until job completed by seller. The amount is submitted by client(buyer) to out stripe platform .then, on job completing, it would be transferred to seller stripe account. (how to set commission for both while creating charge by the client(buyer) to our stripe platform account )?
input : Only pass application_fee without accountId
let chargeEntity = await stripe.charges.create({
amount,
//description: "Sample Charge",
source: sourceTokenId,
currency: currency,
customer: customerId,
application_fee_amount:application_fee,
//on_behalf_of:accountId
});
output :
"message": "Can only apply an application_fee when the request is made on behalf of another account (using an OAuth key, the Stripe-Account header, or the destination parameter)."
If you're using separate charges and transfers, there's no ability to pass an application fee.
Instead, simply withhold the funds you'd like to keep on your platform when you create the transfer, calling stripe.transfers.create. For example, if you created a charge for $100, only transfer $90, your platform retains $10 (minus any Stripe fees on the original $100 charge).
If you would rather use application_fee_amount, look at the destination payment flow; you could create the charge with destination but pass capture: false and then capture funds once work is completed.
https://stripe.com/docs/connect/destination-charges#application-fee

Must stripe destinations by account ids in order to make a charge

Is there anyway to make a customer be the recipient of a charge? From everything I see, it appears that the platform would have to create a stripe account for any individual that may receive charges on the platform. The following code works as long as the destination is a stripe account. Inside destination, I would like to be able to make the destination a customer instead of a stripe account, but I get errors when changing the destination[account] to destination[customer] as well as when I use a customer id in destination[account].
var arbitrary_charge = 100;
stripe.charges.create({
amount: arbitrary charge,
currency: "usd",
customer: stripe_customer_key,
destination: {
amount: .8*arbitrary_charge, //https://stripe.com/docs/connect/destination-charges
account: "acct_xxxxxxxxxxxx"
},
}).then(function(charge) {
console.log(charge)
})
There's no way to make a Customer the destination.
When developing a Platform there are two functions you're generally interested in, paying out and taking payments.
Stripe divides these functions up into separate object types: Accounts and Customers, respectively. You may have a case where you want to pay out AND take payments, in which case you'll usually want to create both a Customer and Account object for a given entity. Stripe also added a feature recently that allows you to debit from some Accounts.
to charge the customer and credit it to the connected account you have to do something like this
charge = Stripe::Charge.create({
amount: amount,
currency: "usd",
card: token.id,
description: "Charge for #{email}",
receipt_email: email,
}, {stripe_account: stripe_user_id})
stripe_user_id is the account id of the connected account of format "acct_xxxxxxxxxxxx"

Resources