Collect customer phone numbers with Checkout
Learn how to collect phone numbers with Checkout.
You can enable phone number collection in Checkout if you need to collect a phone number for shipping or invoicing. Only collect phone numbers if you need them for the transaction. You can enable phone number collection on all payment
and subscription
mode Sessions (phone number collection isn’t supported in setup
mode). This guide assumes that you’ve already integrated Checkout. If you haven’t, see the guide.
Enable phone number collection
To enable phone number collection, set phone_number_collection[enabled]
to true
when creating a Checkout session.
curl https://api.payske.com/v1/checkout/sessions \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d "line_items[0][price_data][unit_amount]"=1000 \
-d "line_items[0][price_data][product_data][name]"=T-shirt \
-d "line_items[0][price_data][currency]"=eur \
-d "line_items[0][quantity]"=2 \
-d "phone_number_collection[enabled]"="true" \
-d mode=payment \
-d success_url="https://example.com/success" \
-d cancel_url="https://example.com/cancel"
# Set your secret key. Remember to switch to your live secret key in production.
# See your keys here: https://account.payske.com/api/key
Payske.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
session = Payske::Checkout::Session.create({
line_items: [{
price_data: {
currency: 'eur',
unit_amount: 1000,
product_data: {
name: 'T-shirt',
},
},
quantity: 2,
}],
phone_number_collection: {
enabled: true
},
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
})
# Set your secret key. Remember to switch to your live secret key in production.
# See your keys here: https://account.payske.com/api/key
payske.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
session = payske.checkout.Session.create(
line_items=[{
'price_data': {
'currency': 'eur',
'unit_amount': 1000,
'product_data': {
'name': 'T-shirt',
},
},
'quantity': 2,
}],
phone_number_collection={
'enabled': True,
},
mode='payment',
success_url='https://example.com/success',
cancel_url='https://example.com/cancel',
)
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://account.payske.com/api/key
\Payske\Payske::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
$session = \Payske\Checkout\Session::create([
'line_items' => [[
'price_data' => [
'currency' => 'eur',
'unit_amount' => 1000,
'product_data' => [
'name' => 'T-shirt',
],
],
'quantity' => 2,
]],
'phone_number_collection' => [
'enabled' => true,
],
'mode' => 'payment',
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
]);
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://account.payske.com/api/key
Payske.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
SessionCreateParams params =
SessionCreateParams.builder()
.setMode(SessionCreateParams.Mode.PAYMENT)
.setSuccessUrl("https://example.com/success")
.setCancelUrl("https://example.com/cancel")
.addLineItem(
SessionCreateParams.LineItem.builder()
.setPriceData(
SessionCreateParams.LineItem.PriceData.builder()
.setCurrency("eur")
.setUnitAmount(1000L)
.setProductData(
SessionCreateParams.LineItem.PriceData.ProductData.builder()
.setName("T-shirt")
.build())
.build())
.setQuantity(1L)
.build())
.setPhoneNumberCollection(
SessionCreateParams.PhoneNumberCollection.builder()
.setEnabled(true)
.build())
.build();
Session session = Session.create(params);
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://account.payske.com/api/key
const payske = require('payske')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
const session = await payske.checkout.sessions.create({
line_items: [{
price_data: {
currency: 'eur',
unit_amount: 1000,
product_data: {
name: 'T-shirt',
},
},
quantity: 2,
}],
phone_number_collection: {
enabled: true,
},
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://account.payske.com/api/key
payske.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &payske.CheckoutSessionParams{
LineItems: []*payske.CheckoutSessionLineItemParams{
&payske.CheckoutSessionLineItemParams{
PriceData: &payske.CheckoutSessionLineItemPriceDataParams{
Currency: payske.String("eur"),
UnitAmount: payske.Int64(1000),
ProductData: &payske.CheckoutSessionLineItemPriceDataProductDataParams{
Name: payske.String("T-shirt"),
},
},
Quantity: payske.Int64(1),
},
},
PhoneNumberCollection: &payske.CheckoutSessionPhoneNumberCollectionParams{
Enabled: payske.Bool(true),
},
Mode: payske.String("payment"),
SuccessURL: payske.String("https://example.com/success"),
CancelURL: payske.String("https://example.com/cancel"),
}
s, _ := session.New(params)
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://account.payske.com/api/key
PayskeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
var options = new SessionCreateOptions
{
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
PriceData = new SessionLineItemPriceDataOptions
{
Currency = "eur",
UnitAmount = 1,
ProductData = new SessionLineItemPriceDataProductDataOptions
{
Name = "T-shirt",
},
},
Quantity = 2,
},
},
PhoneNumberCollection = new SessionPhoneNumberCollectionOptions
{
Enabled = true,
},
Mode = "payment",
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
};
var service = new SessionService();
Session session = service.Create(options);
The above code example creates a Session in payment
mode with phone number collection enabled. To enable phone number collection in subscription
mode, make the same changes highlighted in green to your subscription
mode Session creation request.
With phone number collection enabled, Checkout adds a required phone number field to the payment form. If you’re collecting a shipping address, the phone number field displays under the address fields. Otherwise, Checkout displays the phone number field below the email input. Customers can only enter one phone number per session.
After the session
After the session, you can retrieve customer phone numbers from the resulting Customer, or Checkout Session objects:
Phone number format
When your customer checks out with third-party wallets like Apple Pay, or Google Pay, the phone number format isn’t guaranteed due to limitations on those platforms. Checkout attempts to save phone numbers from third-party wallets in E.164 format when possible. In all other cases, when a customer doesn’t use Apple Pay, or Google Pay, we guarantee phone numbers in E.164 format.
On the Customer: Checkout saves collected phone numbers onto the
phone
property of the Customer object, which you can access programmatically by either fetching the Customer object directly with the API, or by listening for thecustomer.created
event in a webhook. You can also view the customer’s phone number in the dashboard.On the Checkout Session: The customer’s phone number is also saved in the
customer_details
hash of the Checkout Session object, undercustomer_details.phone
. After each successful Checkout Session, Payske emits thecheckout.session.completed
event containing the Checkout Session object (and phone number), which you can listen for in a webhook.