Skip to content

Instantly share code, notes, and snippets.

@srinidhiprabandham
Created December 7, 2017 11:53
Show Gist options
  • Save srinidhiprabandham/fa5c0f6337f827c9cd635e06e5abcaeb to your computer and use it in GitHub Desktop.
Save srinidhiprabandham/fa5c0f6337f827c9cd635e06e5abcaeb to your computer and use it in GitHub Desktop.
package com.games_plaza;
import com.globalcharge.android.PaymentListener;
import com.globalcharge.android.BillingManager;
import com.globalcharge.android.products.Product;
import com.globalcharge.android.Environment;
import android.support.v7.app.AppCompatActivity;
import android.content.pm.PackageManager;
import android.widget.Toast;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Looper;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.ReactActivity;
import java.util.List;
import java.util.Random;
public class PaymentModule extends ReactContextBaseJavaModule {
public PaymentModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "PaymentModule";
}
private class MobilePaymentActivity extends AppCompatActivity implements PaymentListener {
private String message;
private BillingManager billingManager;
private Product selectedProduct;
//The handler is essential for the callbacks to the UI thread.by the BillingManager class.
private Handler mHandler = new Handler();
private long selectedAccount;
private String endUserId, clientAppVersion;
public void onFailure(String message) {
}
public void onProductsReceived(List products) {
Toast.makeText(getReactApplicationContext(), "On Products received called", Toast.LENGTH_LONG).show();
}
public void onProductSelected(Product product) {
}
public void onCancelled() {
}
public void onSuccess(int subscriptionID) {
}
public void onPaymentStateChanged(String state) {
}
public void onSubscriptionCancelSuccess(String a, String b, String c) {
}
public void onSubscriptionCancelFailure(String a, String b, String c) {
}
public void requestSubscription() {
// instantiate the BillingManager with the current context.
boolean isOneStepBilling = true;
billingManager = new BillingManager(getReactApplicationContext(), mHandler);
//TODO remove this line when going to production.
billingManager.setTestUrl("http://inappdev.globalcharge.com:8040/inappservices_silent/rest");
billingManager.setEnvironment(Environment.PRODUCTION);
billingManager.registerPaymentListener(this);
try {
Toast.makeText(getReactApplicationContext(), "Your Selection is registered. Please wait...", Toast.LENGTH_LONG).show();
selectedAccount = 9444999;
endUserId = "testUser1";
clientAppVersion = "0.0.1";
} catch (Exception e) {
// TODO Auto-generated catch block
}
// billingManager.registerPaymentListener(getReactApplicationContext());
/****************************** START IMSI FAKING ****************************************/
// This is code allows you to fake the handset so that it thinks there is a UK SIM in it, and will load UK products from our server,
// this next 3 lines should be removed or disabled before generating the production app
billingManager.setFakeTestMcc("234");
billingManager.setFakeTestMnc("30");
billingManager.setFakeTestImsi("234300902691112");
boolean isPaymentBegan = billingManager.beginPayment(
selectedAccount, endUserId, clientAppVersion,
isOneStepBilling);
if(isPaymentBegan) {
Toast.makeText(getReactApplicationContext(), "Payment began true", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getReactApplicationContext(), "Payment began false", Toast.LENGTH_LONG).show();
}
}
}
// TestToast is a method that can be used to test if the integration b/w java and react is happening.
@ReactMethod
public void TestToast(String message) {
Toast.makeText(getReactApplicationContext(), message, Toast.LENGTH_LONG).show();
}
@ReactMethod
public void onSubscribeClicked() {
MobilePaymentActivity mpa = new MobilePaymentActivity();
mpa.requestSubscription();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment