In-App Purchase (WooCommerce)

The In-App Purchase (IAP) integration enables seamless payment handling via the Google Play Store (Android) and Apple App Store (iOS) within WooCommerce.

Android IAP
iOS IAP

Admin Setup

  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: (INAPP for one-time purchases or SUBS for subscriptions)

  • Is Consumable: (Checkbox indicating if the product is consumable)

  1. Configure Custom Button Text

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

  1. Go to your WordPress admin dashboard.

  2. Navigate to WooCommerce > IAP Settings (specific section for Webtonative integration).

  3. Configure the following button texts:

  • Cart Button Text: The default is "Buy Now."

  • Processing Button Text: Default is "Processing..."

  • Failed Button Text: The default is "Payment Failed."

  • Payment Completed Button Text: The default is "Payment Completed."

Save the settings after making changes.

3. Setting Up the Webtonative Payment Gateway

Here’s a guide to setting up the App Store Secret Key and configuring the Is Test mode for the Webtonative Payment Gateway in WooCommerce


Step 1: Access WooCommerce Payment Settings

  1. Go to your WordPress admin dashboard.

  2. Navigate to WooCommerce > Settings.

  3. Click on the Payments tab.

Step 2: Enable Webtonative Payment Gateway

  1. Locate the Webtonative Payment Gateway in the list of payment methods.

  2. Toggle the switch to enable the gateway.

  3. Click the Manage button to access the gateway settings.

Step 3: Configure the App Store Secret Key

  1. In the Webtonative Payment Gateway Settings:

    • Enable/Disable: Check the box to enable the payment gateway.

    • App Store Secret: Enter your App Store secret key. This key validates in-app purchases or subscriptions through the Apple App Store.

      • You can obtain this key from your Apple Developer Account. To create or retrieve the secret key, navigate to Users and Access > Integrations > Shared Secret.

  2. Save the secret key securely in the provided field.

Step 4: Enable Test Mode

  1. Check the Is Test option to enable the test mode.

    • When enabled, the gateway will use the sandbox environment to test purchases instead of the live environment.

    • Use this option during development or testing to avoid real charges.

Step 5: Save Changes

  1. Click the Save Changes button at the bottom of the settings page.

  2. Verify that the changes are saved successfully.


Important Notes:

  • App Store Secret Key: Ensure the secret key is up-to-date and matches the credentials in your Apple Developer account.

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


REST API Endpoints

1. Get a Native Product ID

  • Endpoint: POST /webtonative/iap/product

  • Request Parameters:

    • productId (string): WooCommerce Product ID

    • platform (string): ANDROID or IOS

  • Response: Returns native product details like Product ID, Type, and Consumable status.

2. Create WooCommerce Order

  • Endpoint: POST /webtonative/iap/order

  • Request Parameters:

    • productId (string): WooCommerce Product ID

    • platform (string): ANDROID or IOS

    • Additional purchase data specific to the platform.

  • Response: Create an order in WooCommerce with payment details from Google Play or Apple App 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...

  1. Post Meta

  • metadataPurchase details are saved as metadata in WooCommerce orders.

  • Meta Key: _wtn_payment_data

  • It contains a JSON object with transaction details, such as productId, receiptData, platform, and more.

Last updated

Was this helpful?