In App Purchase Plugin Setup

To setup in app purchases, the AppPresser In App Purchase plugin is required to be installed and activated on your site. (Make sure you also create your purchases on the app store, and add the purchase form to your app)

For testing you can turn on logging in the AppPresser settings under the "Log" tab. That will log any API calls. To leave the log on for more than 1 hour, add this code to your wp-config.php

define('APP_LOG_FORCE_ON', true);

Make sure to remove it when you are done to save server resources.

The plugin creates 4 WP-API endpoints: new purchase or restored purchase, receive iOS subscription notifications, validate Android receipts, and check subscription status.

A successful purchase adds this user meta:
in_app_purchase, boolean
in_app_purchase_transaction_id, string

A successful purchase calls this action:

do_action( 'iap_new_purchase', $user_id );

The subscription is validated through the iOS Subscription Notification API, and manually for Android. A valid subscription check calls this action:

do_action( 'iap_subscription_renew', $user_id );

You should use that hook to check if a member is in the appropriate level in your plugin, and add them if they are not. Note that this will be called for new purchases and renewals.

An invalid receipt for Android or iOS cancellation will call this action:

do_action( 'iap_subscription_cancel', $user_id );

You should use that action to remove a user from the premium membership level.

If there is a problem a user can always use the restore purchase checkbox in the app.

Example Membership Plugin Integrations

Here is an example of how to create the code that adds a user to your membership plugin when they purchase, and removes them when they cancel. This code can be modified for any plugin as needed.

MemberPress Example Code