Step 5. Set billing address
GraphQL checkout tutorial
You must always set the billing address to place an order.
Use the setBillingAddressOnCart mutation to set a billing address.
Add a billing address to the cart
Similar to the shipping address, add a billing address to the cart. { CART_ID }
is the unique shopping cart ID from Step 2. Create empty cart. The street address is also different, so we can see that different addresses are being created.
Send the customer’s authorization token in the Authorization
parameter of the header. See Authorization tokens for more information.
Request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
mutation {
setBillingAddressOnCart(
input: {
cart_id: "{ CART_ID }"
billing_address: {
address: {
firstname: "John"
lastname: "Doe"
company: "Company Name"
street: ["64 Strawberry Dr", "Beverly Hills"]
city: "Los Angeles"
region: "CA"
region_id: 12
postcode: "90210"
country_code: "US"
telephone: "123-456-0000"
save_in_address_book: true
}
}
}
) {
cart {
billing_address {
firstname
lastname
company
street
city
region{
code
label
}
postcode
telephone
country {
code
label
}
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"data": {
"setBillingAddressOnCart": {
"cart": {
"billing_address": {
"firstname": "John",
"lastname": "Doe",
"company": "Company Name",
"street": [
"64 Strawberry Dr",
"Beverly Hills"
],
"city": "Los Angeles",
"region": {
"code": "CA",
"label": "California"
},
"postcode": "90210",
"telephone": "123-456-0000",
"country": {
"code": "US",
"label": "US"
}
}
}
}
}
}
Verify this step
-
Sign in as a customer to the website using the email
john.doe@example.com
and passwordb1b2b3l@w+
. -
Go to Checkout.
-
Go to the Review & Payments step. The Billing Address form is populated with the address details you entered.