WebToNative
  • Getting started
  • Plugin Setup
    • OneSignal Set Up
    • Google AdMob Setup
    • In App Purchase - iOS Setup
    • In App Purchase - Android Setup
    • Firebase Notification Integration - iOS Setup
  • Social Login Integrations
    • Getting the SHA Key for Google Login
    • Create Google OAuth Client Id
    • Facebook Login Configuration
  • Javascript APIS
    • Getting Started
    • Status Bar
    • Pull To Refresh
    • Close App
    • Device Info
    • Clear App Cache
    • OneSignal Push Notification
    • Download Files
    • Printing Options
    • AdMob
    • Geo Location
    • Load In External Browser
    • Barcode Scan
    • In App Purchase - iOS Integration
    • In App Purchase - Android Integration
    • Social Login
    • Facebook App Events
    • Bottom Navigation
    • Clipboard
    • Screen Control
    • Background Location
    • Native Contacts
    • iOS App Tracking Transparency
    • Google Firebase Analytics
    • Haptic Feedback
    • Google Firebase Notification
    • Apps Flyer
    • App Review
    • Calender - iOS
    • Calendar - Android
    • Biometric Authentication
    • Media Player
    • Notification View
    • Offer Card
    • Cookie Update
    • App Launch Detection
    • Download Manager
    • Dynamic App Icon
    • File Sharing
  • Website Plugins
    • Wordpress
      • Push notification (WooCommerce)
      • In-App Purchase
        • In-App Purchase (IAP) Configuration Guide for iOS and Android
        • In-App Purchase (WooCommerce)
        • In-App Purchase
      • Offercard
      • Biometric Authentication
      • Social Login
      • Webtonative media player
        • WebToNative Radio Player
        • MediaPlayer Native Control
    • Bubble.io
      • Customize Status Bar
      • Device-Based Element Visibility
      • Pull to Refresh (Android)
      • OneSignal Push Notification
        • Set External ID
        • Send Push Notification
        • Set/Remove Email or SMS Phone
        • Set Tag
      • Close App
      • Get Device Info
      • Clear App Cache (Android)
      • Screen Control
      • Facebook Events
        • Regular
        • Purchase
      • AdMob
      • Offercard
      • In-App Purchase
        • In-App Purchase (Android/iOS)
        • Get IAP Canceled Subscription List (iOS)
      • Social Login
      • Biometric Authentication
  • Shopify
    • Social Login
    • In-App Purchase
      • In-app purchase
    • Push Notification
      • Abandoned Cart
    • Status Bar Customization
    • Native Device Visibilty
    • Set Onesignal Tags
    • Pull to Refresh
    • Account Deletion
    • Biometric Authentication
  • Upload Apps
    • Android App
    • Ios App
Powered by GitBook
On this page
  • WTN IAP Plugin for WebtoNative
  • Key Features
  • Configuration
  • Usage
  • How It Works
  • Server-Side Callback Integration
  • Frontend Integration
  • Error Handling
  • For more reference

Was this helpful?

  1. Website Plugins
  2. Wordpress
  3. In-App Purchase

In-App Purchase

PreviousIn-App Purchase (WooCommerce)NextOffercard

Last updated 3 months ago

Was this helpful?

WTN IAP Plugin for WebtoNative

The WTN IAP Plugin is a sub-plugin for WebtoNative that enables easy handling of iOS and Android in-app purchases (IAP). It provides a mechanism to verify purchases with the App Store and Google Play Store and allows developers to consume the verification result via a custom callback function.


Key Features

  • In-App Purchase (IAP) Button: Easily integrate IAP functionality into your WordPress site using a shortcode.

  • Platform Detection: Automatically detects whether the user is on iOS or Android and processes the purchase accordingly.

  • Server-Side Verification: Verifies the purchase receipt with the respective store (App Store or Google Play).

  • Callback Integration: Enables developers to handle the verification result with a custom PHP callback function.


Configuration

  1. Navigate to Settings > WTN IAP (In-App Purchase) in your WordPress admin dashboard.

  1. Configure the following options:

  • App Store Secret Key:

    • Enter the shared secret from your App Store Connect account. This is required for verifying iOS purchases.

  • Callback Function Name:

    • Specify the name of the PHP function that will handle the verification results.


Usage

Shortcode

Use the [wtn_iap] shortcode to add an IAP button to your pages or posts.

Attributes

Attribute
Description
Default Value

google_play_id

The product ID of the in-app purchase on Google Play.

''

app_store_id

The product ID of the in-app purchase on the App Store.

''

product_type

The type of product (INAPP for consumable or SUBS for subscription).

INAPP

is_consumable

Whether the product is consumable (true or false).

false

Example

[wtn_iap google_play_id="com.example.app.product" app_store_id="example_product" product_type="INAPP" is_consumable="true"]

How It Works

  1. IAP Initialization:

    • The user clicks the IAP button.

    • The platform (Android or iOS) is detected using the window.WTN object.

    • The purchase process is initiated using WTN.inAppPurchase.

  2. Purchase Handling:

    • After the user completes the purchase, a receipt is generated.

    • The receipt is sent to the WordPress backend for server-side verification.

  3. Server-Side Verification:

    • The plugin verifies the receipt with the respective store's API.

    • A success or failure message is returned based on the verification result.

  4. Callback Execution:

    • If a custom callback function is configured, it is invoked with the platform and verification data.


Server-Side Callback Integration

Developers can consume the IAP verification result by implementing a custom PHP callback function.

Callback Function Requirements

  • Function Name: The function's name must match the one configured in the plugin settings.

  • Parameters:

    • $platform: The platform of the purchase (ios or android).

    • $receipt_data: An array containing:

      • receipt: The raw receipt data.

      • verification_result: The verification result returned by the respective store's API.

Example Callback Function for Verification

Users must define a callback function in their theme’s functions.php or a custom plugin. This function will process the verification result and take appropriate actions, such as granting access to content or updating the user’s status.

function my_custom_callback($platform, $receipt_data) {
    // Log the platform and data for debugging
    error_log("Platform: $platform");
    error_log("Verification Data: " . print_r($receipt_data, true));

    // Process the verification result
    $receipt = $receipt_data['receipt'];
    $verification_result = $receipt_data['verification_result'];

    if ($verification_result['success']) {
        // Example: Grant access to premium content
        $user_id = get_current_user_id();
        update_user_meta($user_id, 'premium_access', true);
        error_log("User ID $user_id granted premium access.");
    } else {
        error_log("Verification failed: " . $verification_result['message']);
    }
}
add_action('simple_iap_callback', 'my_custom_callback');

Frontend Integration

JavaScript Integration

The plugin includes a JavaScript file (wtn-iap.js) that handles the IAP process on the client side.

  1. IAP Button:

    • When the button is clicked, the WTN.inAppPurchase a method is invoked with the product details.

  2. Purchase Callback:

    • The purchase callback (paymentCallback) processes the response and sends the receipt to the server via an AJAX request.

  3. Server Response Handling:

    • The front end displays appropriate success or error messages based on the server's response.

Example Workflow

  1. The user clicks the "Buy Now" button.

  2. The IAP process starts, and the receipt is obtained.

  3. The receipt is sent to the WordPress backend for verification.

  4. A success or error message is displayed based on the verification result.


Error Handling

Frontend Errors

  • Payment Failure: Alerts the user if the purchase fails.

  • Invalid Response: Logs and displays an error message if the server returns an invalid response.

Backend Errors

  • Missing App Store Secret: Returns an error if the secret key is not configured.

  • Invalid Receipt: Returns an error if the receipt verification fails.

For more reference


This documentation provides a comprehensive guide for using the Simple IAP Plugin and customizing it to meet specific requirements.

In App Purchase - iOS Setup | WebToNative
In App Purchase - iOS Setup
In App Purchase - Android Setup | WebToNative
In App Purchase - Android Setup
In App Purchase - iOS Integration | WebToNative
In App Purchase - iOS Integration
In App Purchase - Android Integration | WebToNative
In App Purchase - Android Integration
Logo
Logo
Logo
Logo