Additional features for working with payments in the SDK on Android (Google Play)🔗
Opening a Subscription Manager🔗
Some stores allow the user to manage their subscriptions (Google, Amazon, Huawei), and some stores require you to add this feature to your application (Google). To open the subscription manager, that is, redirect the user to the store in the desired section, it is enough to use the following function:
import games.my.mrgs.billing.MRGSBilling;
MRGSBilling.getInstance().openSubscriptionManager(Activity);
Support for promotional codes🔗
MRGS supports working with promotional codes for content creators - when using it, the creator receives a bonus. Systems will be added upon request.
To check for the presence of a promotional code entered by the user, you can use the following method:
import games.my.mrgs.billing.MRGSBilling;
MRGSBilling.getInstance().checkPromoCode("PromoTest", (valid, error) ->
{
if (valid) {
// Apply for later purchases
}
});
Then, when starting the payment, you need to add a promotional code to the payment parameters:
import games.my.mrgs.billing.MRGSBilling;
final MRGSBillingEntities.MRGSBankPurchaseRequest request = new MRGSBillingEntities.MRGSBankPurchaseRequest("test.product.id");
request.setPromoCode("PromoTest");
After a successful purchase and payment verification, MRGS will report the use of the promotional code to the service (then the content creator who issued the promotional code receives a bonus).
Subscription change🔗
The user can change one subscription to another. For example, from a monthly payment to an annual one. To do this, use the changeItem method. The first parameter must specify the new subscription, the second parameter - the old one.
import games.my.mrgs.billing.MRGSBilling;
import games.my.mrgs.billing.MRGSBillingEntities.MRGSBankPurchaseRequest;
// The subscription that the user wants to switch to
final String newSubscription = "games.my.mrgs.newsubs";
// The subscription the user wants to switch from
final String oldSubscription = "games.my.mrgs.oldsubs";
final MRGSBankPurchaseRequest request = new MRGSBankPurchaseRequest(newSubscription);
request.setOldSubscriptionIdentifier(oldSubscription);
MRGSBilling.getInstance().buyItem(request);
Read more about subscription change on the Google Billing website.
Subscription discounts🔗
In the Google Play console, you can set a discount on the first purchase of a subscription and the period, during which this initial price will be debited. For example, a subscription costs 100 rubles per month, and for the first three months you can specify a price of 50 rubles per month. In order to check whether a subscription discount is available to the user on the client, it is necessary to check the price in the introductoryPrice field of the MRGSPurchaseItem class.
import android.text.TextUtils;
import androidx.annotation.NonNull;
import games.my.mrgs.MRGSLog;
import games.my.mrgs.billing.MRGSBillingDelegate;
import games.my.mrgs.billing.MRGSBillingEntities.MRGSBankProductsResponse;
import games.my.mrgs.billing.MRGSBillingProduct;
final MRGSBillingDelegate listener = new MRGSBillingDelegate() {
@Override
public void onReceiveProductsResponse(@NonNull MRGSBankProductsResponse response) {
for (MRGSBillingProduct product : response.getValidItems()) {
if (!TextUtils.isEmpty(product.getIntroductoryPrice())) {
MRGSLog.d("Has introductory price: " + product.getIntroductoryPrice());
MRGSLog.d("Introductory period: " + product.getIntroductoryPeriod());
}
}
}
};
Promo code redemption🔗
You can give out a specific product in the game by the promo code redemption. Promo codes can be created in the Google Play console, read more in the Google Billing documentation.
To redeem a promo code in the application, use the redeemPromoCode method.
import games.my.mrgs.billing.MRGSBilling;
MRGSBilling.getInstance().redeemPromoCode("XXXXXXXXXXXX");
Karaganda Fraud Prevention API🔗
In order to help Google detect fraud before it happens you can use the following methods: setObfuscatedAccountId and setObfuscatedProfileId
import games.my.mrgs.billing.MRGSBilling;
import games.my.mrgs.billing.MRGSBillingEntities.MRGSBankPurchaseRequest;
final MRGSBankPurchaseRequest purchaseRequest = new MRGSBankPurchaseRequest(<sku>, <developerPayload>);
purchaseRequest.setObfuscatedAccountId(<obfuscatedAccountId>);
purchaseRequest.setObfuscatedProfileId(<ObfuscatedProfileId>);
MRGSBilling.getInstance().buyItem(purchaseRequest);
In case you do not set this identifier, MRGS will automatically set its value as a hash from the user set to us at startup
Subscriptions are not currently supported
Payment support in external application stores🔗
Apart from Google billing, MRGS supports working with the Samsung, Amazon application stores and Huawei/AppTouch store.
Adding Samsung payments🔗
- Download the latest version of the library from the website Android.
- Extract the files from the archive.
- Add the IAP5Helper.aar library to your project.
- Upon the MRGS initialization set the "samsung" billing type.
import games.my.mrgs.MRGSExternalSDKParams;
import games.my.mrgs.MRGSExternalSDKParams.SamsungBillingParams;
import games.my.mrgs.MRGSExternalSDKParams.SamsungBillingParams.OperationMode;
import games.my.mrgs.MRGSPlatform;
import games.my.mrgs.MRGService;
import games.my.mrgs.MRGServiceParams;
public class YourApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
// Available MRGSPlatform: AMAZON, ANDROID, HUAWEI, SAMSUNG and FACEBOOK_CLOUD
final MRGServiceParams params = MRGServiceParams.init(<MRGS_APP_ID>, <CLIENT_SECRET>, MRGSPlatform.AMAZON);
// Setting Samsung SDK
final MRGSExternalSDKParams externalSDKParams = MRGSExternalSDKParams.newInstance();
// Available OperationMode: TEST_FAILURE, PRODUCTION, TEST
externalSDKParams.samsungBillingParams = SamsungBillingParams.init(OperationMode.PRODUCTION);
MRGService.service(context, params, externalSDKParams);
}
}
Adding Amazon payments🔗
- Download the latest version of the library from the website Android.
- Extract the files from the archive.
- Add the in-app-purchasing-2.0.61.jar library to your project.
- Upon the MRGS initialization set the "amazon" billing type.
import games.my.mrgs.MRGSPlatform;
import games.my.mrgs.MRGService;
import games.my.mrgs.MRGServiceParams;
public class YourApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
// Available MRGSPlatform: AMAZON, ANDROID, HUAWEI, SAMSUNG and FACEBOOK_CLOUD
final MRGServiceParams params = MRGServiceParams.init(<MRGS_APP_ID>, <CLIENT_SECRET>, MRGSPlatform.AMAZON);
MRGService.service(context, params);
}
}
Adding Huawei/AppTouch payments🔗
- Add the library according to the documentation
- Upon the MRGS initialization set the "huawei" billing type.
import games.my.mrgs.MRGSPlatform;
import games.my.mrgs.MRGService;
import games.my.mrgs.MRGServiceParams;
public class YourApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
// Available MRGSPlatform: AMAZON, ANDROID, HUAWEI, SAMSUNG and FACEBOOK_CLOUD
final MRGServiceParams params = MRGServiceParams.init(<MRGS_APP_ID>, <CLIENT_SECRET>, MRGSPlatform.HUAWEI);
MRGService.service(context, params);
}
}
Created: 2020-02-17