web api interface
PaymentAddress
Secure context
The PaymentAddress interface of the Payment Request API is used to store shipping or payment address information.
It may be useful to refer to the Universal Postal Union website’s Addressing S42 standard materials, which provide information about international standards for postal addresses.
Instance properties
addressLineRead only Deprecated- : An array of strings providing each line of the address not included among the other properties. The exact size and content varies by country or location and can include, for example, a street name, house number, apartment number, rural delivery route, descriptive instructions, or post office box number.
countryRead only Deprecated- : A string specifying the country in which the address is located, using the ISO-3166-1 alpha-2 standard. The string is always given in its canonical upper-case form. Some examples of valid
countryvalues:"US","GB","CN", or"JP".
- : A string specifying the country in which the address is located, using the ISO-3166-1 alpha-2 standard. The string is always given in its canonical upper-case form. Some examples of valid
cityRead only Deprecated- : A string which contains the city or town portion of the address.
dependentLocalityRead only Deprecated- : A string giving the dependent locality or sublocality within a city, for example, a neighborhood, borough, district, or UK dependent locality.
organizationRead only Deprecated- : A string specifying the name of the organization, firm, company, or institution at the payment address.
phoneRead only Deprecated- : A string specifying the telephone number of the recipient or contact person.
postalCodeRead only Deprecated- : A string specifying a code used by a jurisdiction for mail routing, for example, the ZIP code in the United States or the PIN code in India.
recipientRead only Deprecated- : A string giving the name of the recipient, purchaser, or contact person at the payment address.
regionRead only Deprecated- : A string containing the top level administrative subdivision of the country, for example a state, province, oblast, or prefecture.
sortingCodeRead only Deprecated- : A string providing a postal sorting code such as is used in France.
[!NOTE] Properties for which values were not specified contain empty strings.
Instance methods
toJSON()Deprecated- : A standard serializer that returns a JSON representation of the
PaymentAddressobject’s properties.
- : A standard serializer that returns a JSON representation of the
Examples
In the following example, the PaymentRequest() constructor is used to create a new payment request, which takes three objects as parameters — one containing details of the payment methods that can be used for the payment, one containing details of the actual order (such as items bought and shipping options), and an optional object containing further options.
The first of these three (supportedInstruments in the example below) contains a data property that has to conform to the structure defined by the payment method.
const supportedInstruments = [
{
supportedMethods: "https://example.com/pay",
},
];
const details = {
total: { label: "Donation", amount: { currency: "USD", value: "65.00" } },
displayItems: [
{
label: "Original donation amount",
amount: { currency: "USD", value: "65.00" },
},
],
shippingOptions: [
{
id: "standard",
label: "Standard shipping",
amount: { currency: "USD", value: "0.00" },
selected: true,
},
],
};
const options = { requestShipping: true };
async function doPaymentRequest() {
const request = new PaymentRequest(supportedInstruments, details, options);
// Add event listeners here.
// Call show() to trigger the browser's payment flow.
const response = await request.show();
// Process payment.
const json = response.toJSON();
const httpResponse = await fetch("/pay/", { method: "POST", body: json });
const result = httpResponse.ok ? "success" : "failure";
await response.complete(result);
}
doPaymentRequest();
Once the payment flow has been triggered using show() and the promise resolves successfully, the PaymentResponse object available from the fulfilled promise (instrumentResponse above) will have a details property containing response details. This has to conform to the structure defined by the payment method provider.