UWP SDK Payments

Attention:

Win10 version of the product can only access the UWP SDK, if you need to access please check the [Untiy Porting for Windows 10], [Cocos Porting for Windows 10], For more information, please refer to [Untiy Porting for Windows 10],[Cocos Porting for Windows 10]

According to Microsoft Store policy, developers can only use Microsoft Store In-App Purchase API interface.

Introduction

This article describes how to interface with the payment interface of Miracle Games SDK and open the payment window.

Before calling the payment interface, make sure you have completed the initialisation of the SDK [ Refer to]。

Currently there are a total of two payment methods, which are divided into Microsoft Pay and MG Pay. At the end of the access to the SDK, the Microsoft payment method must wait until the game is on the shelves before the real Microsoft payment can be made.

This interface is unified management by MiracleGames, if you need to open the payment function, you need to contact MG staff in advance to assist in opening the

User payment flow chart

User Payment

C#CPP

public async void ShowPayChannel()
{
	try
	{
		if (!MiracleGames.ApplicationManager.SetupCompletedSuccessfully)//test if initialisation is complete
			return;
		// goodsKey: the key of the product, generated by MiracleGames when creating the product. 
		// message: a custom parameter, urlencode it before passing it in, if you pass it in, you will get it after completing the order.
		// callbackid: the unique identifier of the callback address, created in the MG backend.
		// Last bool parameter, ture: Microsoft Payment false: third party payment.	 
		var result = await MiracleGames.PaymentManager.OpenPayChannelAsync(GoodsKey, message, callbackid, false);
		if (result.ReturnValue)//detect whether the payment operation is completed or not
		{
		   
		}
		else
		{
			var msg = new MessageDialog("Cancel payment.");
			await msg.ShowAsync();
		}
	}
	catch (Exception){}//Implement exception handling to prevent game crashes.
}


Platform::String ^ MainPage::PurchaseGoodsMicrosoft(Platform::String^ goodsKey, Platform::String^ message)
{	
	try
	{
	if (!MiracleGames::ApplicationManager::SetupCompletedSuccessfully)//test if initialisation is complete
	return;
	// goodsKey: the key of the product, generated by MiracleGames when creating the product. 
	// message: a custom parameter, urlencode it before passing it in, if you pass it in, you will get it after completing the order.
	// callbackid: the unique identifier of the callback address, created in the MG backend.
	// Last bool parameter, ture: Microsoft Payment false: third party payment.	 
	concurrency::create_task(MiracleGames::PaymentManager::OpenPayChannelAsync(goodsKey, message, callbackid, true))
		.then([](MiracleGames::Services::Core::Common::AsyncProcessResult^ result)
		{
			if (result->ReturnValue)//detect whether the payment operation is completed or not
			{
				
			}
			else
			{
				// Cancel payment.
			
			}	
	});
	return "1";
	}
	catch (...){}//Implement exception handling to prevent game crashes.
}

Server-side callback to developer server after successful payment

Server-side callback to the game client after successful payment

If the game has a server to receive the callbacks, there is no need to access this feature, and you can directly access the payment callbacks on the server side.

	
try
{
	Loaded += ref new RoutedEventHandler([this](Object^, RoutedEventArgs^)//Client-side payment callbacks
	{
	MiracleGames::PaymentManager::AssetsChanged += ref new EventHandler(
		[&](Object^o, MiracleGames::AssetsChangedEventArgs^ args)//detect if there are any outstanding orders
		{

			int cnt = args->GetAssetsCount();
			for (int i = 0; i < cnt; i++)//traverse the order information
			{
				auto item = args->GetAssetElementAt(i);
				
				if (item)
				{
					auto nm = item->DigitalGoods->Name->ToString();
					auto id = item->Id;
					auto comment = item->Comment;
					auto type= args->EventType;

					switch (type)
					{
					case 0:
						concurrency::create_task(item->ReportFulfillmentAsync()).then([=](MiracleGames::Services::Core::Common::AsyncProcessResult^ result) {
							if (result->ReturnValue)
							{
								//Report order completed, send props
								auto meg = item->Comment;
								SendMessageToU3D(2, comment);
							}
							});
						break;

					case 1:
						concurrency::create_task(item->ReportFulfillmentAsync()).then([=](MiracleGames::Services::Core::Common::AsyncProcessResult^ result) {
							if (result->ReturnValue)
							{
								//Report order completed, send props
								SendMessageToU3D(2, "Replacement props");
							}
							});
						break;
					default:
						break;
					}
				}
			}
		});
	});
}
catch (...){}//Implement exception handling to prevent game crashes.

Video Demonstration - Payments