JOHN JOHNNNY

JOHN JOHNNNY

  • NA
  • 190
  • 139.7k

Open another ctivity after payment is made in fortumo in-App

Sep 22 2016 6:26 PM
Hi
 
I have downloaded the sdk and done the integration successfully, but i
want to make my app open GameActivity after a successfull one
time/full upgrade payment.
But my app could not open GameActivity after a successfull payment for
non-consumable item kindly help. see my code below

public class MainActivity extends PaymentActivity {
private static String SERVICE_ID = "
fe57060941a8cad84aa087ad64d01549";
private static String APP_SECRET = "9e92352038b5825948db09da892e2c6e";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

MpUtils.enablePaymentBroadcast(this,
Manifest.permission.PAYMENT_BROADCAST_PERMISSION);

// Restoring non-consumable items
new AsyncTask<Void, Void, Integer>() {

@Override
protected Integer doInBackground(Void... params) {
int medalStatus =
MpUtils.getNonConsumablePaymentStatus(MainActivity.this, SERVICE_ID,
"9e92352038b5825948db09da892e2c6e", "Medal");
return medalStatus;
}

@Override
protected void onPostExecute(Integer result) {
if (result.intValue() == MpUtils.MESSAGE_STATUS_BILLED) {
// We can refresh our UI here to indicate that
"Medal" is billed
// For example unlock some additional level in game
}
}

}.execute();

// TODO Restoring consumable items
// Depends on implementation, we can just save this info on
device or send some request to our server

findViewById(R.id.button1).setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
PaymentRequest.PaymentRequestBuilder builder = new
PaymentRequest.PaymentRequestBuilder();
builder.setService("fe57060941a8cad84aa087ad64d01549",
"9e92352038b5825948db09da892e2c6e");
builder.setDisplayString("Buy Medal"); // shown
on user receipt
builder.setProductName("Medal"); //
non-consumable purchases are restored using this value
builder.setType(MpUtils.PRODUCT_TYPE_NON_CONSUMABLE);
//builder.setConsumable(false); //
non-consumable items can be later restored
builder.setIcon(R.drawable.medal);
makePayment(builder.build());
}
});

findViewById(R.id.button2).setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
PaymentRequest.PaymentRequestBuilder builder = new
PaymentRequest.PaymentRequestBuilder();
builder.setService("fe57060941a8cad84aa087ad64d01549",
"9e92352038b5825948db09da892e2c6e");
builder.setDisplayString("Buy golden eggs"); //
shown on user receipt
builder.setProductName("GoldenEggs"); //
non-consumable purchases are restored using this value
builder.setType(MpUtils.PRODUCT_TYPE_NON_CONSUMABLE);
//builder.setConsumable(true); //
non-consumable items can be later restored
builder.setIcon(R.drawable.gold);
makePayment(builder.build());
}
});
}

@Override
protected void onPaymentCanceled(PaymentResponse arg0) {
super.onPaymentCanceled(arg0);
}

@Override
protected void onPaymentFailed(PaymentResponse arg0) {
super.onPaymentFailed(arg0);
}

@Override
protected void onPaymentPending(PaymentResponse arg0) {
super.onPaymentPending(arg0);
}

@Override
protected void onPaymentSuccess(PaymentResponse paymentResponse) {
super.onPaymentSuccess(paymentResponse);
if (paymentResponse.getServiceId().equals(SERVICE_ID)) {
int creditAmount =
Integer.parseInt(paymentResponse.getCreditAmount());
// Increase amount of credits related to this service
(maybe coins in game)
// TODO Save purchase data (on device or send request to our server)
startActivity(new Intent(MainActivity.this, GameActivity.class));
} else if (paymentResponse.getServiceId().equals(SERVICE_ID)) {
// Unlock functionality related to this service (maybe
additional level in game)
startActivity(new Intent(MainActivity.this, GameActivity.class));
}
}
Reply soon

Answers (2)