> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/coda-links/link-users-out-to-coda-hosted-payment-page/link-to-web-payment-on-ios-us.md).

# Link to web payment on iOS - US  🇺🇸

iOS in the US permits the use of standard "naked" hyperlinks without requiring integration with Apple's StoreKit APIs for external linkouts. Thus, launching Coda Links in iOS is a highly streamlined process.

Below is the step-by-step guide for linking US users to from an iOS App to your Coda-hosted Payment Page:

## Prerequisites

Ensure that you have followed the steps in [Set up payments](/codapay/getting-started/set-up-payments.md), and obtained a API Key that can be used with our Codapay APIs.

This is the standard integration that allows you to call Codapay's Payment Init API, which returns a unique web checkout URL.

## Step 1: Get a Payment Link from Coda's Payment API

<figure><img src="/files/Nr7pDHsBnfbLtCGuNJbp" alt="" width="357"><figcaption></figcaption></figure>

A summary of the **Payment Init API** specs are as follows:

> For the full list of supported request & response parameters, refer to [Initiate a payment request](/codapay/hosted-payment-page-integration/initiate-a-payment-request.md)

<table><thead><tr><th width="129.625">Environment</th><th>Endpoint URL | Method: POST</th></tr></thead><tbody><tr><td>Sandbox</td><td>https://sandbox.codapayments.com/airtime/api/restful/v2.0/Payment<strong>/init.json</strong></td></tr><tr><td>Production</td><td>https://airtime.codapayments.com/airtime/api/restful/v2.0/Payment<strong>/init.json</strong></td></tr></tbody></table>

{% tabs %}
{% tab title="Sample Request" %}

```json
{
    "initRequest": {
        "country": 158,
        "payType": 82,
        "apiKey": "live_****************************",  //Obtained from Coda Portal
        "projectId": 21                                 //Obtained from Coda Portal
        "orderId": "12321312321314",                    //Your internal order identifier
        "currency": 901,
        "items": [
            {
                "code": "1",
                "name": "Test Item",
                "price": 3.99
            }
        ],
        "profile": {
            "entry": [
                {
                    "key": "user_id",
                    "value": "105"
                }
            ]
        }
    }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Sample Successful Response" %}

```json
{
    "initResult": {
        "resultCode": 0,
        "txnId": 7714940366302672840,
        "redirectUrl": "https://airtime.codapayments.com/airtime/begin?txn_id=7144594637002072212&browser_type=mobile-web&utm_source=facebook”
    }
}
```

{% endtab %}

{% tab title="Sample Failed Response" %}

```json
{
    "initResult": {
        "resultCode": 103,
        "resultDesc": "This transaction has been cancelled. No charges were made. (error:103)",
        "txnId": 0
    }
}
```

{% endtab %}
{% endtabs %}

**2. Launch the URL:**\
Simply invoke standard iOS networking methods to launch the URL in an **external browser**.

> For optimal functionality, open the URL in an external browser rather than an in-app webview, as certain e-wallet payment features may be limited in webviews.

<details>

<summary>SwiftUI Sample</summary>

```swift
import SwiftUI

struct ContentView: View {
    @Environment(\.openURL) var openURL

    var body: some View {
        Button("Visit Apple") {
            if let url = URL(string: "https://www.apple.com") {
                openURL(url) // Opens in the default external browser (usually Safari)
            }
        }
    }
}
```

</details>

<details>

<summary>UIKit Sample</summary>

```swift
import UIKit

if let url = URL(string: "https://www.apple.com") {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
```

</details>

<figure><img src="/files/cb2O2DplahFEf9Lda3sW" alt="" width="188"><figcaption></figcaption></figure>

## Step 2: Receive a payment success notification from Coda

1. Coda will send a notification to your **Complete Notification URL** (configured on Coda Portal during [Set up payments](/codapay/getting-started/set-up-payments.md)). This notification is sent to you when the user has successfully completed their payment on Coda-hosted Payment Page.

{% tabs %}
{% tab title="Sample notification for non-USD payment" %}

```
// Sample for non-USD payment
https://<your_webhook_url>?
  TxnId=7715121708032676249
  OrderId=365f5Z619951c1a4b8
  TotalPrice=1.00
  PaymentType=237
  ResultCode=0
  Checksum=6b6c5e0f835f9f1442726bed3aedc3c9
  PayTaxRate=8.00 
  PayCurrency=MYR 
  PayAmount=1.00 
  OriginAmount=1.00 
  OriginCurrency=MYR 
  SubTotalPrice=0.93
```

{% endtab %}

{% tab title="Sample notification for USD payment" %}

```
// Sample for USD payment, converted to local currency
https://<your_complete_notification_url>?
  TxnId=7715122576202672831
  OrderId=365f5Z619951c1a4b8
  TotalPrice=1.17
  PaymentType=237
  ResultCode=0
  Checksum=10741fa6be7e6f2b189f029b3f8a0963
+ USDPrice=0.30
  PayTaxRate=8.00
  PayCurrency=MYR
  PayAmount=1.17
  OriginAmount=0.30
  OriginCurrency=USD
  SubTotalPrice=1.08
```

{% endtab %}
{% endtabs %}

2. You need to respond to the notification from Coda with an **acknowledgement**, to confirm that it has been successfully received.&#x20;
   1. If your application processes the notification successfully, respond with `ResultCode=0`
   2. Otherwise, return an error code.

> If no response is received, the notification will be re-sent 3 times at 5-minute intervals. If all attempts fail, an email alert will be triggered. To subscribe to this email alert notifications, go to the [Coda Portal](https://portal.coda.co) > Team > Manage Access > Tick "Transaction Notification" > Save Changes

## Step 3: Double check the transaction status with Payment Result Inquiry API (Recommended)

We highly recommend that you call the [InquiryPaymentResult API](https://coda-payments.gitbook.io/coda-private-technical-documentation/codapay/hosted-payment-page-integration/check-a-transaction-status) after receiving the notification, to confirm the status of the payment once more. This will help reconcile the transaction status between your system and Coda's before releasing the purchased item to the user. The details are as follows:

<table data-full-width="true"><thead><tr><th width="135.43359375">Environment</th><th width="800">Endpoint URL | Method: POST</th></tr></thead><tbody><tr><td>Sandbox</td><td>https://sandbox.codapayments.com/airtime/api/restful/v2.0/Payment<strong>/inquiryPaymentResult.json</strong></td></tr><tr><td>Production</td><td>https://airtime.codapayments.com/airtime/api/restful/v2.0/Payment/<strong>/inquiryPaymentResult.json</strong></td></tr></tbody></table>

{% tabs %}
{% tab title="Sample Request" %}

```json
{    
    "inquiryPaymentRequest":
    {
        "apiKey": "live_****************************",
        "country": 702 //This field is only needed for v2.0 API
        "projectId": 21 //This field is only needed for v2.0 API
        "txnId" : "7144594637002072212",
        "needStatusFinal": "true"
    }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Sample response for non-USD payment" %}

```json
// Sample for non-USD payment
{
    "paymentResult": {
        "orderId": "365f5Z619951c1a4b8",
        "originAmount": 1,
        "originCurrency": "MYR", 
        "payAmount": 1, 
        "payCurrency": "MYR", 
        "payTaxRate": 8, 
        "profile": {
            "entry": [
                {
                    "key": "PaymentType",
                    "value": 237
                },
                {
                    "key": "isStatusFinal",
                    "value": true
                },
                {
                    "key": "channelId",
                    "value": 237
                },
                {
                    "key": "status",
                    "value": "success"
                }
            ]
        },
        "resultCode": 0,
        "resultDesc": "Success",
        "subTotalPrice": 0.93, 
        "totalPrice": 1, // Always the same as payAmount
        "txnId": 7715121708032676249
    }
}
```

{% endtab %}

{% tab title="Sample response for USD payment" %}

```json
// Sample for USD payment, converted to local currency
{
    "paymentResult": {
        "orderId": "365f5Z619951c1a4b8",
        "originAmount": 0.3, 
        "originCurrency": "USD", 
        "payAmount": 1.17, 
        "payCurrency": "MYR", 
        "payTaxRate": 8, 
        "profile": {
            "entry": [
                {
                    "key": "PaymentType",
                    "value": 237
                },
                {
                    "key": "isStatusFinal",
                    "value": true
                },
                {
                    "key": "channelId",
                    "value": 237
                },
                {
                    "key": "status",
                    "value": "success"
                }
            ]
        },
        "resultCode": 0,
        "subTotalPrice": 1.08,
        "totalPrice": 1.17, // Always the same as payAmount
        "txnId": 7715122576202672831
    }
}
```

{% endtab %}
{% endtabs %}

> For the full list of supported request & response parameters, refer to [Check a transaction status](/codapay/hosted-payment-page-integration/check-a-transaction-status.md)

## Step 4: Post-Purchase UX & Deep Linking

<figure><img src="/files/Qzw345Vw5VlX1N75rp0I" alt="" width="222"><figcaption></figcaption></figure>

1. **Item Fulfillment:** When the payment succeeds, Coda Webstore completes the payment and automatically sends a server-to-server item fulfillment request to your backend. This should already be covered in the Webstore basic setup. No changes required here
2. **User can click to go back to App via deep link:** \
   To ensure this redirection happens smoothly, you must provide Coda with a deep link that can redirect users back to your iOS app upon a successful purchase.
   1. This link can be configured in Coda Portal under **Complete Landing Page URL.** If you have already configured this during [Set up payments](/codapay/getting-started/set-up-payments.md), no change is required.
   2. Once the user is deep-linked back to your app, they should seamlessly receive their items. In addition, your app can display a purchase success screen with confetti animations!

> Refer to [Redirecting users from Coda Links back to your app](/coda-links/redirecting-users-from-coda-links-back-to-your-app.md)to learn how to setup back-to-app redirection correctly for your iOS App.

2. **User can explore Webstore's offers & LiveOps campaigns**
   * If you have a Coda Webstore published, the post-purchase screen will display your best Webstore offers to the user automatically, encouraging them to explore & become a loyal direct-to-webstore customer.
   * Find out how here: [How to enable LiveOps on post-purchase screen](/coda-links/link-users-out-to-coda-hosted-payment-page/how-to-enable-liveops-on-post-purchase-screen.md)&#x20;

{% hint style="success" icon="seedling" %}
**Why having LiveOps features on Coda Links is crucial for your long-term revenue**

* **Linkouts are not free:** Including in the US, Google and Apple are fighting tooth and nail to impose fees on external purchases to protect their revenue streams. For instance, Google charges up to a 20% commission on purchases made within 24 hours of a user following an external payment link. Similarly, Apple imposes a 15% commission on website sales initiated within 7 days of an end user tapping an out-of-app link. If users stick exclusively to linkout payments directly from the app, publisher margins will continuously be undercut by these fees with no way out.
* **Webstore loyalty builds long-term profitability:** Converting purchasers from in-app to webstore should be the ultimate goal. Publishers can use elements on the linkout success page to convert users into direct webstore customers, which makes the long-term cost per transaction significantly lower. When users build a habit of going directly to out-of-app channels like a webstore, they bypass the in-app link altogether. These direct visits make their future purchases completely out-of-reach for the app platforms, meaning all fee savings go straight to the publisher's bottom line.
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coda.co/coda-links/link-users-out-to-coda-hosted-payment-page/link-to-web-payment-on-ios-us.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
