Integrate mobile payments and monetize with Mocopay

Our developer center provides all the details for a simple and smooth integration so you could easily add mobile payments with Mocopay.

Useful tips for advance usage

Extra prefab parameters

For more advanced usage you can set also following MoCoPay prefab parameters:

  • Callback URL – web page to which you want to redirect end user after he has finished his purchase, by default you can leave this blank but if you set this parameter please read text below (Using custom callbackURL)
  • Webview Size– if using in-app web view, X and Y define the position of the top left corner of the webview (measured from the top left corner of the screen), and W and H are width and height of the web view (with 1 being the full width/height of the screen)
  • Hide Webview Until Loaded– weather the in-app webview should be hidden until the first page load completes
  • Transaction Status Update Interval– this is how often the payment processing loop polls MoCoPay servers to update payment status and other details, in seconds
  • Background Shading– a gameobject that will be activated when in-app web view is shown, and disabled when in-app webview is closed, use it if your web-view is not fullscreen and you wish to for example darken your game view until the payment finishes processing
  • Webview Fade Duration– time in seconds it takes for the in-app web view to fade in/out

Payment initialization – extra parameters

Except above stated prefab parameters you can tune your payments by providing MoCoPay more payment initialization parameters. You can set additional payment parameters before calling payment.init(), just assign a value to any parameter you want to use:

  • ImageURL– product image URL for MoCoPay payment form (if not set image will not be presented or default one from the service configuration will be used)
  • MobileCountryCode– mobile country code ( will be used for optimization of payment flow and it is recommended to read this info from users SIM card and to forward it in initPayment
  • MobileNetworkCode– mobile network code ( will be used for optimization of payment flow and it is recommended to read this info from users SIM card and to forward it in initPayment
  • UserId– free formed buyer identifier, useful if you want to track user in further payment process since it will be communicated by MoCoPay in each payment session status and notification
  • Phone– buyer mobile phone number, will be used for optimization of payment flow and it is recommended to read this info from users SIM card and to forward it in this step
  • Language– preferred user language code (ISO 639-1), will be used for payment form language optimization and better user expirience
  • NotifyURL– notification URL for payment notifications, can be optionally sent and will override the default one configured in control box
  • ReferenceId– free form string which will be sent back to the application in each notification and payment status for this user
  • CallbackURL– call-back URL where Buyer is redirected after payment process has been finished, if you use this you must set it inside Unity in the mocopay prefab, even if you already set it in the mocopay control box also please read text below (Using custom callbackURL)

Using custom callbackURL

If you are using a custom callbackURL you must define it in the MoCoPay prefab even if you already defined it in your MoCoPay control panel. In addition to custom callbackURL, if you are also using an in-app web view, the webview will not close automatically on the end of payment process. You can close the webview in one of two ways:

  1. either call MoCoPayHelper.Webview.close() from your Unity code
  2. or have a link to “mocopay://close” on the page you redirect to, the webview will close when the user clicks the link

Adding more callback listeners

You can listen to additional callbacks. All of these use the delegate described earlier:

  • OnStatusChange– triggers every time the payment status changes
  • OnInitialized– triggers once the payment is initialized and a payment URL is generated
  • OnFinished– triggers once the processing is done, regardles of the outcome
  • OnSuccess– triggers once the processing is done if the payment was succesful
  • OnFailure– triggers once the processing is done if the payment was not succesful, or if there was any preocessing error

If you use in-app web view, you can listen to these callbacks through MoCoPayHelper.WebView:

  • OnPageLoad– triggers every time a page is done loading
  • OnClose– triggers once the webview is closed
  • OnOpen– triggers once the webview opens

These callbacks use the following delegate:

void WebviewUpdateEventHandler(Webview view);

Verifying started payments

You can verify any previous payment using one of the static verification methods of the Payment class:

Mocopay.Payment.VerifyBySID( “sessionId”, onVerified ); 
Mocopay.Payment.VerifyByUID( “userId”, onVerified ); 
Mocopay.Payment.VerifyByTID( “transactionId”, onVerified );

You can get a Payment object from these functions like this:

Mocopay.Payment payment = Mocopay.Payment.VerifyBySID( “sessionId” );

And then periodically check payment.VerificationInfo. Once payment.VerificationInfo is not null, it will contain detailed transaction data.


void Update() {
		if (payment!=null && payment.VerificationInfo!=null) {
			/*examine payment.VerificationInfo for status, amount, etc. */
			payment = null;

Or you can provide a callback function like:

       public void paymentDataReceived(Payment payment, PaymentVerificationData data) {
             /*examine the data object for status, amount, etc. */

And start verification like this:

Mocopay.Payment.VerifyBySID( “sessionId”, paymentDataReceived);

Your function will be called once the verification data is received from MoCoPay servers.

Resuming your application properly

If you use the external browser on a mobile platform it is possible for your app to restart once the user returns to it, which means the payment will not register as processed automatically. Therefore it is advised to use:

Mocopay.Payment payment = Mocopay.Payment.GetIncompletePayment();

on application start to check if there was a payment that didn’t finish processing. If the return value is not null, you can resume the last payment with:


We recommend setting payment.AutoAdvance to false on Windows Phone apps before resuming, as the app could get stuck auto switching back to browser every time you return to it, this is due to the way Windows Phone handles app switching.

Also make sure to check the first returned status on app start, in case it’s an old transaction the status will be either IdentifyExpired or AuthorizeExpired.

Payment.VerificationInfo and Payment.VerificationInfo.Transactions structure

Payment.VerificationInfo contains all the data described in under Payment Session notifications

Payment.VerificationInfo.Transactions is a System.Collections.Generic.List of individual transactions belonging to this payment. Each TransactionData element contains all the data described in under Payment Transaction notifications

That link also contains descriptions of all possible Payment and Transaction statuses.