In App Purchase Technical Overview
This is a technical document intended to help with debugging or custom coding your in app purchases.
In app purchase flow
If you have set everything up correctly, here's what happens in the app.
Step one: User fills out the form fields (name, email, etc), and presses purchase.
The app should say "Purchase successful! Logging you in..."
(if you are using
noLogin, it does not log you in, and everything stops here)
An http POST request is sent to your website at ../wp-json/appp/v1/in-app-purchase with the form fields. This request is handled by the AppPresser In App Purchase plugin.
The fields sent are first, last, email, username, password, transaction_id, and sometimes user_id.
If a user is logged in, no username or password is sent. Instead, we try to get the user_id from local storage and send if it exists.
If a user is logged out, we send all fields except user_id.
Step two: The AppPresser In App Purchase WordPress plugin adds the purchase and logs the user in
The request from step one is handled by our plugin on your WordPress site.
New user: if a username is sent in the request and that username does not exist on the site, a new user is created and logged in.
Existing user: if we send an email but not a username, that means the user is already logged into the app and they exist in WordPress.
Error: if there is an error, we send that back to the app and display the error message.
In all cases, a user meta field of in_app_purchase is set to true. This allows you to check all the users on your site to see who has purchased through the app.
The iap_new_purchase action hook is fired off at this point, which bring us to step three.
Step three: do something with a membership or LMS plugin
The final step is to add the user to a premium membership level, give them access to a course, or whatever.
This is handled by one of our membership integration plugins, which may require some custom code.
This is the hook:
do_action( 'iap_new_purchase', $user_id );
You can see how this hook is used in our example membership plugin integrations here.
If the request to the website is successful, the user is logged into the app so they can view the protected content.