I am using this code to create Stripe checkout:
$checkout_session = \Stripe\Checkout\Session::create([
'customer_email' => 'my_test_email#gmail.com',
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'unit_amount' => 1000,
'product_data' => [
'name' => 'Balance top-up',
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'client_reference_id' => $clientReferenceId,
'success_url' => 'https://example.com/user-deposit/?result=success',
'cancel_url' => 'https://example.com/user-deposit/?result=failed',
'metadata' => [
'user_id' => '1',
],
]);
Everything works fine, but if I try to pay with ApplePay from the mobile browser - I got such an error (although everything is fine with this card and the billing address is filled in in the Apple account settings):
What should I do? In fact, I don't want to ask my users for the billing address, could I use some stored info (like country and city) to pass to this API request, or perhaps I could somehow force Stripe to do not ask for billing/shipping addresses (I do not sell goods, just for top-up an internal balance in my service)?
Related
I'm trying to use Stripe Checkout for a subscription service.
Using the PHP SDK
Session::create([
'customer' => $user->stripeCustomerId,
'payment_method_types' => ['card'],
'line_items' => [[
'price' => 'price_0MACBYAGG6RS7KP5c1fNa6v9',
'quantity' => $amount,
]],
'subscription_data' => [
'metadata' => [
'message' => $message,
],
],
'mode' => 'subscription',
'success_url' => UrlHelper::url('?session_id={CHECKOUT_SESSION_ID}'),
'cancel_url' => UrlHelper::url('?cancel=true'),
]);
but metadata is never attached as per the docs https://support.stripe.com/questions/using-metadata-with-checkout-sessions?locale=en-GB
I have a single charge option that passes:
'payment_intent_data' => [
'metadata' => [
'message' => $message,
],
],
and that attaches perfectly. What am I missing?
Using subscription_data[metadata] (API ref) as you've done is the way this is intended to work. Have you confirmed in your request logs that the metadata was included in your request as you expect? It's possible your $message might be empty in the subscription case.
If your Checkout session request did include the subscription_data metadata as expected, then you should also see this on the subscription object after the customer completes the Checkout session. Where are you looking at the resulting subscription which makes you conclude that it does not have metadata?
Turns out that I was looking in the wrong place. The meta data is not attached to each payment but on the actual subscription itself.
I am working on this code which is from the Stripe website
URL : https://stripe.com/docs/checkout/integration-builder
this is directly from the website and works fine for me
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'unit_amount' => 2000,
'product_data' => [
'name' => 'Stubborn Attachments',
'images' => ["https://i.imgur.com/EHyR2nP.png"],
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/success.html',
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
]);
However when I change the code to the below to try to get the dollar and cents working ( using either unit_amount as in the example ... or unit_amount_decimal as suggested by this page https://stripe.com/docs/billing/subscriptions/decimal-amounts ) then there are issues which I dont really understand, particularly the error returned when using unit_amount_decimal because it appears that there's no way to do decimal places in Stripe ... which hopefully is not the case.
How would I do this if not as they suggest on that page ... which seems to not work?
same code with 2000.55 instead of 2000
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'unit_amount_decimal' => 2000.55,
'product_data' => [
'name' => 'Stubborn Attachments',
'images' => ["https://i.imgur.com/EHyR2nP.png"],
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/success.html',
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
]);
network tab errors
using unit_amount Invalid integer: 2000.55
using unit_amount_decimal Checkout does not currently support usd prices with more than 2 decimal places in line_items[0]. You passed 2000.55 corresponding to $20.0055, which is not supported.
The second error seems to be suggesting that this is not possible, yet this makes no sense since products are not always even dollar amounts.
Stripe measures amounts in the smallest unit of a currency - for example cents for USD:
'unit_amount' => 2000, //2000 cents or $20
'unit_amount' => 2050, //2050 cents or $20.50
If you need to use a decimal amount of the smallest unit - e.g. 1.5 cents per action then use 'unit_amount_decimal'
'unit_amount_decimal' => 1.5 // 1.5ยข or $0.015 per action
I am using Stripe Checkout API to direct a website user to make payment.
Is there a way to pass a shipping address to the hosted checkout page so it's gathered from the referrer rather then Stripe themselves?
function createSession()
{
require 'vendor/autoload.php';
\Stripe\Stripe::setApiKey('[API_KEY_REDACTED]');
$YOUR_DOMAIN = '[SITE_URL_REDACTED]';
// Calculate price
$price = 50;
$checkout_session = \Stripe\Checkout\Session::create([
'billing_address_collection' => 'required',
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'gbp',
'unit_amount' => $price,
'product_data' => [
'name' => 'Product'
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/success',
'cancel_url' => $YOUR_DOMAIN . '/cancel',
]);
return json_encode(['id' => $checkout_session->id]);
}
You can add the following line to make Stripe ask for a shipping address, but I want to pass this from the referrer instead.
'shipping_address_collection' => [
'allowed_countries' => ['US', 'CA'],
],
To do this you would create a Customer and provide their shipping address, then provide that existing Customer when creating the Checkout session:
$checkout_session = \Stripe\Checkout\Session::create([
'customer' => 'cus_123',
...
]);
When transferring money to a connected account on Stripe using this code
// // Create a PaymentIntent:
$method = \Stripe\PaymentMethod::create([
'type' => 'card',
'card' => [
'number' => '4242424242424242',
'exp_month' => 12,
'exp_year' => 2020,
'cvc' => '314',
],
]);
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => $AMOUNT1,
'currency' => 'nzd',
'payment_method_types' => ['card'],
'payment_method' => $method->id,
'customer' => CUSTOMER_ID,
'transfer_group' => '{ORDER'.$_SESSION['order_id'].'}',
]);
// Create a Transfer to a connected account (later):
$transfer = \Stripe\Transfer::create([
'amount' => $AMOUNT2,
'currency' => 'nzd',
'destination' => $ACC_ID,
'transfer_group' => '{ORDER'.$_SESSION['order_id'].'}',
]);
The payment stores on the connected account's dashboard and says its completed but when it stores on my Payments tab it says that the payment is incomplete and that the buyer has not completed the payment
Prev1
Prev2
You need to confirm the payment intent, either by providing confirm=true at creation or by making a call to /confirm.
You're creating a transfer from your account to the connected one, which succeeds, and a payment that you never complete.
trying to understand, why i'm getting error (developer took money and gone)
I'm trying to buy a stuff, and once I click BUY, I receive this error Missing required param: success_url.
I'm using Laravel.
but in code, I can see that, success_url exists.
\Stripe\Stripe::setApiKey(Setting::get('stripe_secret_key'));
$session = \Stripe\Checkout\Session::create(
[
'payment_method_types' => ['card'],
'line_items' => [
[
'name' => 'Test',
'description' => 'Test2: '.implode(', ', $vouchersNames),
'amount' => $total * 100,
'currency' => 'eur',
'quantity' => 1,
],
],
'success_url' => env('APP_URL').'buy_vouchers_done?session_id={CHECKOUT_SESSION_ID}&vouchers='.urlencode(implode(',', $vouchers->pluck('id')->toArray())),
'cancel_url' => env('APP_URL'),
]);
Where is a problem? Thank you!