Developers

Integrate mobile payments and monetize with Mocopay

Our how to make an essay longer with words developer center provides all the details for a simple and smooth integration so you could easil essay buy y add mobile payments with Mocopay.

Quickstart

Next few steps will present you the fastest way for implementing MoCoPay Unity plugin.

Installation

Import MoCoPayUnityPlugin.unitypackage from distributed pachage into your project.

 unity1

Setup

Drag and drop the MoCoPay prefab from the “Assets/Mocopay folder” into your scene. This prefab must be instantiated in every scene that requires MoCoPay processing. Select the MoCoPay object in your scene and enter your service name, API Key and API Secret under the Services dropdown in the inspector panel. This information can be found in your MoCoPay service view in the control box.

Choose the web view type from the drop-down menu:

  • In App: requires either UniWebView (included) or uWebKit depending on platform, displays a native web view inside the app, or as an overlay (NOTE: before using this value read carefully prerequisit chapter)
  • External Broswer: uses the run-time system’s default installed web-browser to display the payment form

unity2

Basic use

From your code create a new payment using:

payment = new Mocopay.Payment("your product ID");

And start processing by calling:

payment.init();

Payments are processed asynchronously. You can either poll payment.Status periodically or assign a callback to payment.OnFinished. To poll the payment.Status enum, in your Update function or a coroutine periodically read the payment.Status value and wait for it to indicate PaymentComplete or PaymentFailed.

Example:

void Update() {
		if (payment!=null && payment.Status == PaymentStatus.PaymentComplete) {
			/*payment succeed, you can examine payment.VerificationInfo for amount, etc. */
			payment = null;
		}
		else if (payment!=null && payment.Status == PaymentStatus.PaymentFailed) {
			/*payment failed, you can examine payment.VerificationInfo for failure reason, etc. */
			payment = null;
}

Or, to use a callback, define a function like:

public void paymentFinished(Mocopay.Payment payment) {
		if (payment.Status == PaymentStatus.PaymentComplete) {
			/*payment succeed, you can examine payment.VerificationInfo for amount, etc. */
		}
		else if (payment.Status == PaymentStatus.PaymentFailed) {
			/*payment failed, you can examine payment.VerificationInfo for failure reason, etc. */
}

Then assign it to the payment before calling payment.init():

       payment.OnFinished = paymentFinished;

Your function will be called once the payment is processed, and you can read its status and other information from the payment object. MocopayDemoScene.unity scene, and MocopayDemo.cs file in delivered package contain a simple example which can help you in your integration.