> For the complete documentation index, see [llms.txt](https://docs.webtonative.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.webtonative.com/website-plugins/wordpress/in-app-purchase/in-app-purchase-woocommerce.md).

# WooCommerce In-App Purchase Guide

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeCOfUQ-oBOhaGog5e2aJir74o4VcOoEnCPlNyKiLbfhzOdIqsSijnwGNwz5sMJydiTPJoOZIULQL9hKmpOnFy9x4TjIrKCN0gIjA_2loF9leInqYcmnvQMFV9DT3eEnqIdwo4x7g?key=8fypB0WwX012kuShdOKyH1VA" alt=""><figcaption><p> Android IAP</p></figcaption></figure>

<figure><img src="/files/fJ81mrNLuPY9DlibVbYS" alt="" width="563"><figcaption><p>iOS IAP</p></figcaption></figure>

## Admin Setup

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXelO3183_HPS1yB16sq3PWSbdFFNtlnt4j3MHRhonwc1IVGGW1wzJSvd3kRqujVCKT83hk1p0o5TbRpWhBg8_Y-gi5YhMkJKzwKeXouai-FQ5CcyntZ2eHp65Gl-kNdkECgJoyToQ?key=8fypB0WwX012kuShdOKyH1VA" alt=""><figcaption></figcaption></figure>

1. **Custom Fields for Products**

When creating or editing WooCommerce products, the following fields are available for configuring in-app purchases:

* **Google Play Product ID**:  ID for the product in Google Play
* **App Store Product ID**:  ID for the product in the App Store
* **Product Type**:  (<mark style="color:green;">INAPP</mark> for one-time purchases or <mark style="color:green;">SUBS</mark> for subscriptions)
* **Is Consumable**:  (Checkbox indicating if the product is consumable)

2. **Configure the IAP Settings**

Admins can customize the text for various buttons displayed during the checkout process in the **WooCommerce IAP Settings** section. To access these settings:

<figure><img src="/files/ELUWVpM89xw8UMEpAwC4" alt=""><figcaption></figcaption></figure>

1. Go to your WordPress admin dashboard.
2. Navigate to **Webtonative > WooCommerce IAP Settings** (specific section for Webtonative integration).
3. **Configure the IAP Settings:**&#x20;

<figure><img src="/files/hLXRXCfkZmTxd1iVFYut" alt=""><figcaption></figcaption></figure>

1. **Configure the IAP Settings**:\
   The following options are available to customize the In-App Purchase functionality:
   * **Enable In-App Purchase**:
     * Check the box labeled "Enable In-App Purchases" to activate in-app purchases for your store.
     * Default: Unchecked (disabled).
   * **Enable Test Mode**:
     * Check the box labeled "Enable Test Mode" to enable test mode for in-app purchases. This is useful for testing transactions without processing real payments.
     * Default: Unchecked (disabled).
   * **App Store Bundle ID:**
     * Enter your App Store Bundle ID. This uniquely identifies your app in the Apple App Store
     * Default: Empty.
     * **Example**: com.example.app
   * **App Store Key ID:**
     * Enter your App Store Key ID. This is used to authenticate with Apple's servers for in-app purchase validation.
     * Default: Empty.
     * **Example**: QVI...
   * **App Store Issuer ID:**
     * Enter your App Store Issuer ID. This is associated with the key issued by Apple for your app.
     * Default: Empty.
     * **Example**: d1956586-...-73185c2e0d
   * **App Store Private Key (.p8):**
     * Paste the content of your .p8 private key file here. This key is used for signing and validating in-app purchase transactions with Apple.
     * Default: Empty.
     * **Example**:&#x20;

       ```
       -----BEGIN PRIVATE KEY-----
       MIG...2DOW...
       cp1c...
       21yu9Sh...
       -----END PRIVATE KEY-----
       ```
   * **Cart Button Text**:
     * Set the text for the cart button that initiates the in-app purchase process.
     * Default: "Buy Now".
   * **Processing Button Text**:
     * Define the text displayed on the button while the payment is being processed.
     * Default: "Processing...".
   * **Failed Button Text**:
     * Specify the text shown on the button if the payment fails.
     * Default: "Payment Failed".
   * **Payment Completed Button Text**:
     * Set the text displayed on the button after a successful payment.
     * Default: "Payment Completed".
2. **Save the Settings**:
   * After configuring the options, click the **Save Settings** button to apply your changes.

***

#### Important Notes:

* **Test Mode**: Remember to uncheck **Is Test** and switch to the live environment before launching your store.

***

## Payment Validation

**Android Payment Validation**

* Data validated includes orderId, purchaseToken, purchaseState, and other parameters received from Google Play.
* A WooCommerce order is created if the purchase is verified successfully.

**iOS Payment Validation**

* Receipt data is validated using the App Store's API (sandbox or production).
* If validated successfully, a WooCommerce order is created and marked as completed.

## Where In-App Purchase Data is Saved

1. **WooCommerce Order Notes**

* Each order created via IAP includes a detailed note with purchase data.
* Example note:\
  Webtonative Payment Data:

  \- Product ID: \<product\_id>

  \- Order ID: \<order\_id>

  \- Platform: \<ANDROID/IOS>

  \- Other purchase details...

2. **Post Meta**

* Metadata Purchase details are saved as metadata in WooCommerce orders.
* Meta Key: <mark style="color:green;">\_wtn\_payment\_data</mark>
* It contains a JSON object with transaction details, such as <mark style="color:green;">productId</mark>, <mark style="color:green;">receiptData</mark>, <mark style="color:green;">platform</mark>, and more.<br>
