Apple & Google Pay Submission
OJS supports submitting Apple Pay and Google Pay independently of a specific processor. You can optionally specify which processor to use, or let OJS default to the first available one.
Checking available payment methods
Use the getAvailablePaymentMethods()
method to check what payment methods are currently available and which processors support them.
const availablePaymentMethods = await form.getAvailablePaymentMethods();
You can check the available processors in method.processors
. The result is an array like:
{
name: SubmitMethods;
processors: ("stripe" | "airwallex" | "authorize_net" | "adyen" | "paypal" | "pockyt" | "loop")[];
isAvailable: boolean;
}[]
Submitting Apple Pay/Google Pay
Basic submission
If Apple Pay is available, you can submit Apple Pay/Google Pay with:
form.generalSubmit('apple-pay'); // or 'google-pay'
If you don’t specify a processor, OJS will us the first available one.
Specifying a processor
To explicitly submit through a specific processor (e.g., Stripe):
form.generalSubmit('apple-pay', { processor: 'stripe' });
Randomize processor selection
If multiple processors support the method, you can randomize processor choice. This can be helpful for A/B testing, load distribution, or failover scenarios.
form.generalSubmit(SubmitMethods.applePay, {
processor: Math.random() < 0.5 ?
'stripe' : 'airwallex',
});
Apple pay integration notes
Apple Pay requires that you call applePay.startFlow()
directly within a user gesture handler such as a click
or onClick
. This is enforced by the browser — violating it will result in Apple Pay failing silently or throwing an error.
To ensure a successful integration, follow these requirements:
✅ Do’s
-
Call
applePay.startFlow()
immediately inside a user-triggered event (e.g., aclick
oronClick
). -
Ensure the event handler runs on the main thread (i.e., don't
await
anything before callingstartFlow
). -
Keep the triggering element (like a button) visible and mounted during the Apple Pay session.
❌ Don’ts
-
Wrap
startFlow()
inuseEffect
,setTimeout
, or any async flow not triggered by a user. -
Do async work (like API calls) before calling
startFlow()
. -
Unmount or hide the button while Apple Pay is still processing.
Example
<button id="apple-pay-btn">Pay with Apple Pay</button>
<script>
const button = document.getElementById('apple-pay-btn');
button.addEventListener('click', () => {
// ✅ Called immediately in user gesture
openpay.applePay.startFlow();
});
</script>