Standalone Address Widget

The Address capture Widget uses a prebuilt form to capture an address. Your customer can prefill the form with either an address or a partial address if available. They can then use the autocomplete field to look up their address by searching for key parts such as their postcode, zip code and so on.

Overview

Address-search

Address-manual

The Address capture Widget captures the following fields. These fields are mandatory for your customer to add, and optional for the merchant to provide.

NameDefinitionMandatory/Optional
firstNameFirst name of the customerOptional to provide / Mandatory for the customer
lastNameLast name of the customerOptional to provide / Mandatory for the customer
addressLine1First line of the customer's addressOptional to provide / Mandatory for the customer
addressLine2Secondary optional address lineOptional to provide and for the customer
cityCity of residence of the customerOptional to provide / Mandatory for the customer
stateState of residence of the customerOptional to provide / Mandatory for the customer
postcodeAddress postcode of the customerOptional to provide / Mandatory for the customer
countryCountry of residence of the customerOptional to provide / Mandatory for the customer

iOS

How to initialize the Address widget sheet in iOS

1. Overview

The Address Capture Widget collects your customer's billing location. As a standalone widget it manages all required inputs and validations, and provides an address autocomplete function using Apple MapKit SDK.

The widget displays as a SwiftUI sliding bottom sheet. Once your customer has confirmed their address, the widget returns the Address object back to the application.

The Address Widget view is as follows:

AddressSheetView(address: Address, isPresented: Binding<Bool>, onCompletion: Binding<MobileSDK.Address>)

An example of the widget before any customer details have been populated is as follows. The widget is in a SwiftUI View:

import SwiftUI
import MobileSDK

struct AddressExampleView: View {
    var body: some View {
        AddressWidget { result in
            switch result {
            case .success(let address):
                // Handle the address result
            case .failure(let error): 
                // Handle the error
            }
        }
    }
}

2. Parameter definitions

The following definitions provide a more detailed overview of the parameters included in the Address widget:

MobileSDK.AddressWidget

NameDefinitionTypeMandatory/Optional
addressUsed for passing in the information to the address sheet to pre-populate the address fieldsMobileSDK.AddressOptional
completionCompletion block that returns result. Either Address in case of success, or Error in case of failureResult<Address, Error>) -> VoidMandatory

MobileSDK.Address

NameDefinitionTypeMandatory/Optional
firstNameFirst name of the customerSwift.StringOptional to provide / Mandatory for the user
lastNameLast name of the customerSwift.StringOptional to provide / Mandatory for the user
addressLine1Full address line withSwift.StringOptional to provide / Mandatory for the user
addressLine2Secondary optional address lineSwift.StringOptional to provide and for the user
cityCity of residence of the customerSwift.StringOptional to provide / Mandatory for the user
stateState of residence of the customerSwift.StringOptional to provide / Mandatory for the user
postcodeAddress postcode of the customerSwift.StringOptional to provide / Mandatory for the user
countryCountry of residence of the customerSwift.StringOptional to provide / Mandatory for the user

Android

How to use the AddressDetailsWidget

1. Overview

The Address widget captures billing address details. This section details how to initialize and use the AddressDetailsWidget composable in your application.

The following sample code demonstrates the definition of the AddressDetailsWidget:

@Composable
fun AddressDetailsWidget(
    modifier: Modifier,
    address: BillingAddress?,
    completion: (BillingAddress) -> Unit
) {...}

The following sample code example demonstrates how to use the widget in your application:

// Initialize the AddressDetailsWidget
AddressDetailsWidget(
   modifier = Modifier
        .fillMaxWidth()
        .padding(16.dp), // optional
    address = null, // optional (pre-populate fields)
    completion = { billingAddress ->
        // Handle captured address - Update UI or perform actions
       Log.d("CardDetailsWidget", "Billing address returned. $billingAddress")
    }
)

2. Parameter definitions

This subsection describes the various parameters required by the AddressDetailsWidget composable. It provides information on the purpose of each parameter and its significance in configuring the behavior of the AddressDetailsWidget.

AddressDetailsWidget

NameDefinitionTypeMandatory/Optional
modifierCompose modifier for container modificationsModifierOptional
addressThe preset address to pre-fill the input fields.com.paydock.feature.address.domain.model.BillingAddressOptional
completionCallback function to execute when the address is saved.(BillingAddress) -> UnitMandatory

BillingAddress

NameDefinitionTypeMandatory/Optional
addressLine1The first line of the billing address, typically containing street informationStringOptional to provide / Mandatory for the user
addressLine2The optional second line of the billing address, often used for additional detailsStringOptional to provide and for the user
cityThe city or locality of the billing addressStringOptional to provide / Mandatory for the user
stateThe state or region of the billing addressStringOptional to provide / Mandatory for the user
postalCodeThe Postal or ZIP code of the billing addressStringOptional to provide / Mandatory for the user
countryCountry of residence of the userStringOptional to provide / Mandatory for the user

3. Callback Explanation

Completion Callback

The completion callback is invoked after the address details is captured. It receives a BillingAddress once the address details have been saved.