Skip to content

Adding VKPay (Android)🔗

VKPay - a payment system that can be used in stores, provided that third-party payment methods are allowed there.

Attention!

You should not use mobile VKPay in stores that explicitly prohibit the use of additional payment systems, as this may lead to account blocking and removal of the application from the store.

Setup🔗

To start using VKPay it is necessary by analogy with other stores:

  • Create a project on the VK platform website
  • Create a list of products, add descriptions and prices on the site MRGS
  • Add dependencies and configure the project

Creating a project in VK platform🔗

  1. If you don't have a project in VK platform yet, then it must be started, according to the documentation of this platform.
  2. Next, copy the Service Access Key from VK platform and add it to the MRGS console of your project -> Integration -> VK access token

Adding products🔗

You can create a list of products and add descriptions on the MRGS website. Be sure to set the product that the product will be used for VKPay payments by setting the flag of the same name for the product, and specify the prices in rubles above 0 .

Note

The client receives only those products that have the vkpay flag and the prices in rubles are higher 0 . Otherwise, the server will ignore these products.

Adding dependencies🔗

  • Add MRGSVKPay module:
Adding to Unity project (general instruction)
  • Add VK repository to your root gradle file:
allprojects {
    repositories {
        // others
        maven { url "https://artifactory-external.vkpartner.ru/artifactory/superappkit-maven-public/" }
    }
}

Step 1. Add Sources

To add MRGS to a project via the Unity Package Manager (available from Unity 2018+) simply add a scopedRegistries section to the Packages/manifest.json file by adding the following entry:

{
    "dependencies": {
        ...
    },
    "scopedRegistries": [
            {
                "name": "MRGS",
                "url": "https://mrgs-nexus.my.games/repository/mrgs-uninty-plugins/",
                "scopes": [
                    "games.my.mrgs"
                ]
            }
    ]
}

Alternatively, you can click Edit -> Project Settings -> Package Manager -> '+' in scoped registry section, and fill in the fields according to the data above.

Step 2. Add dependency

  • Click Window -> Package Manager -> select 'Packages: MyRegistries' from dropdown list, select package MRGSVKPay from the list, then click "Install"
  • Import the module: using MRGS;
  • Download the latest version of the library. Unzip the archive.
  • (For unitypackage integration) In Unity, click Assets -> Import Package -> Custom Package, and select the games.my.mrgs.vkpay.unitypackage package from the downloaded archive.
  • (For tgz integration) In Unity, click Window -> Package Manager -> '+' -> Add package from tarball, and select the games.my.mrgs.vkpay-<version> package. tgz from the downloaded archive.
  • Import the module: using MRGS;
Adding to Android project
  • Add VK repository to your root gradle file:
allprojects {
    repositories {
        // others
        maven { url "https://artifactory-external.vkpartner.ru/artifactory/superappkit-maven-public/" }
    }
}
  • Add dependencies to your Application gradle file.
dependencies {
    def mrgsVersion = "6.x.x"

    implementation "games.my.mrgs:billing-vkpay:$mrgsVersion"
}

Copy the MRGSVKPay.aar file to the libs directory of your project. Add the necessary dependencies to the build file.gradle

dependencies {
    //...
    implementation(name: 'MRGSVKPay', ext:'aar')

    implementation "com.vk:vksdk-pub:0.110-24426"
    implementation "com.vk:oauth-vk:0.110-24426"
    implementation "com.vk:vkpay-checkout:0.110-24426"
}

VK authentication

VKPay is not compatible with another library for authorization/registration in VK. Make sure that these two libraries do not get into the assembly at the same time, or add the following script to your mainTemplate.gradle file to exclude the old authorization option from compilation:

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        // ... other dependencies
    }
    configurations.implementation {
        exclude group: 'com.vk', module: 'android-sdk-core'
    }

Android sdk-fingerprint is incorrent

If you are using the new apk/bundle signing mechanism in GooglePlay, you should take SHA1 from GooglePlay Console of your project.

Setup project🔗

On the Android platform, it is not possible to configure the VK library through the code (set the keys in the SDK). Therefore, the only way to do this is to configure the project according to the documentation VK platform.

Setup MRGS🔗

The mechanism works similarly to purchases in any mobile store via the MRGSBank module.

Working with accepting payments from a mobile app🔗

A standard approach is used for mobile payments in MRGSBank - loading goods (downloaded from the MRGS website), displaying (using the application), calling the purchase method when clicked, receiving a callback.

You can work with payments using a new class, or billing type at the start of the application:

Working via the MRGSVKPay class🔗

To work with payments, you need to use a new class in the MRGSVKPay module:

MRGSVKPay.Instance;
MRGSVKPay.getInstance();

This class implements the interface MRGSBilling/MRGSBank and therefore they work exactly the same, so you can refer to the documentation for the MRGSBank API.

Specifying billing at the start of the application🔗

Also, the billing type is supported at startup:

using MRGS;

public class MasterController : MonoBehaviour
{
    void Awake()
    {
        MRGServiceParams serviceParams = MRGServiceParams.initWithAppId(appId: APP_ID, appSecret: APP_SECRET);
        // Setting up MRGS params
        // ...

        // Enabling work with VKPay via the MRGSBank class
        serviceParams.BankSubstitution = BankSubstitution.VkPay;

        // Configuring External SDKs and initializing MRGS
        // ...
    }
}
import games.my.mrgs.MRGService;
import games.my.mrgs.MRGServiceParams;
import games.my.mrgs.billing.vkpay.MRGSVKPay;

public class YourApplicationClass extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        final MRGServiceParams serviceParams = MRGServiceParams.init(APP_ID, APP_SECRET, PLATFORM);
        // Setting up MRGS params
        // ...

        // Enabling work with MRGSVKPay via the MRGSBank class
        serviceParams.setBillingSubstitution(MRGSVKPay.BILLING_VKPAY);

        MRGService.service(context, serviceParams, externalSdkParams);
    }
}

In this case, you can carry out further work with payments through the MRGSBank class, as usual.

Nuances of working with payments🔗

Currently, only consumable payments are supported.

Installing a delegate and checking availability🔗

This item is no different from Delegate installation and availability check.

Getting information about available products🔗

This item is no different from Getting information about available products.

The products will be downloaded from the MRGS site, that is, those that you started when setting up the project on the market.

Making a payment🔗

This item is no different from Making a payment, delegates are supported.

Restoring purchases🔗

This mechanism doesn't exist in VKPay.

Making test payments🔗

To test payments, you can get a couple of products with a small amount and test them.


Last update: 2023-10-25
Created: 2022-10-04