In App Purchase Plugin Setup

For In App Purchases to work, you need 2 plugins active on your site.

1. The core AppPresser In App Purchase plugin version 2.0.0 or later, downloaded from your account page.
2. A custom membership integration plugin

The second plugin needs to have some custom code, since every membership site uses a different plugin, a different membership level, etc. We have some example code below, and you can email us for help with this.

The In App Purchase Plugin

The core In App Purchase plugin does not require any configuration. Just activate it and you are good to go.

It creates 2 WP-API endpoints: register a new user (wp-json/appp/v2/in-app-purchase-register) and an endpoint to receive webhooks from the validation server (wp-json/appp/v2/in-app-purchase-validate) The validation endpoint receives a webhook that tells your site if the user has purchased, cancelled, or otherwise.

New Purchase

A successful purchase adds this user meta: 

in_app_purchase_ids: Array of product IDs that a user has purchased

A successful purchase calls this action:

do_action( 'iap_new_purchase_request', $user_email, $purchase, $request );

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.

See an example below. Note that we have integration code already done for you for some popular plugins. The code below is just for reference.

add_action( 'iap_new_purchase_request', function( $user_email, $purchase, $request ) {

	$user_email = ( isset( $request['applicationUsername'] ) ? $request['applicationUsername'] : null );

	$user = get_user_by( 'email', $user_email );

	if( !$user || is_wp_error( $user ) ) {
		return new WP_Error( 'rest_user_error',
			__( 'Cannot get user for ' . $user_email, 'apppresser' ),
			array(
				'status' => 404,
			)
		);
	}

	$user_id = $user->ID;

	$product_id = $purchase['productId'];

	// ADD USER TO MEMBERSHIP LEVEL OR COURSE HERE...

}, 10, 3 );

If you are writing this from scratch, you need to add your custom code where it says // ADD USER TO MEMBERSHIP, and then create a custom plugin and activate it on your site. Alternatively, download one of our sample integration plugins below and edit that code instead.

Cancellation

A cancellation will call this action:

do_action( 'iap_subscription_cancel_request', $user_email, $purchase, $request );

You should use that action to remove a user from the premium membership level. Below is some example code, you'll notice it's very similar to the code for a new purchase.  Note that we have integration code already done for you for some popular plugins. The code below is just for reference.

add_action( 'iap_subscription_cancel_request', function( $user_email, $purchase, $request ) {

	$user_email = ( isset( $request['applicationUsername'] ) ? $request['applicationUsername'] : null );

	$user = get_user_by( 'email', $user_email );

	if( !$user || is_wp_error( $user ) ) {
		return new WP_Error( 'rest_user_error',
			__( 'Cannot get user for ' . $user_email, 'apppresser' ),
			array(
				'status' => 404,
			)
		);
	}

	$user_id = $user->ID;

	$product_id = $purchase['productId'];

	// CANCEL MEMBERSHIP LEVEL OR COURSE HERE...

}, 10, 3 );

If you are writing this from scratch, you need to add your custom code where it says // CANCEL MEMBERSHIP, and then create a custom plugin and activate it on your site. Alternatively, download one of our sample integration plugins below and edit that code instead.

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

Example Membership Plugin Integrations

You need to create a custom plugin that has your membership integration code as described above, and add it to your site.

We have some full examples that allow you to only edit a couple lines of code, then install the plugin on your site.

Here is a full example for LearnDash. Edit line 16 with the post ID of your LearnDash course.

Full example for Restrict Content Pro. Edit line 15 with your subscription level ID.

Full example for Memberpress. Edit line 15 with your membership level ID.

Full example for WooCommerce Memberships. Edit line 15 with your membership level ID.

Full example for Paid Memberships Pro. Edit 15 with your membership level ID.

Full example for Indeed Memberships.

That will add a customer to a course or membership level when they purchase, and remove them when they cancel.

To use that plugin, save the file to your computer. Upload it to your wp-content/plugins folder. (Or you can zip the file and upload it via Plugins => Add New => Upload) Activate it as a normal plugin.

This code can be modified for any plugin as needed.

Note on subscription length: When a new user purchases, they are given a long subscription, such as 1 year or 5 years. This is because their subscription will be active until they cancel. We do not use periods such as 30 days because we do not get a reliable renewal notification, instead the user is active until they cancel. If you wish to change this, you can change the code in your membership integration plugin, but it is not recommended.

Testing Purchases

For testing please see the iOS testing or Android testing documentation.