Intent Call for Single-Click Checkout (InApp Payments)

Quickly share your Android Code Snippets here...

Intent Call for Single-Click Checkout (InApp Payments)

Postby iflyfar » Mon Jan 31, 2011 11:32 pm

//This sample provided below will initiate the intent call from your own Android application to the Single-Click Checkout mobile payments application. Should the Single-Click Checkout application not reside on the device another intent call will be made to open a browser session. You will need to register at singleclickcheckout.com to secure an account before the code sample below will work.



static final int TRANSACTION_CANCELLED = 0;
static final int TRANSACTION_FAILED = 1;
static final int TRANSACTION_SUCCESS = 2;
static final String SHORT_CODE = "short_code";
/*
* Launch the Single Click Checkout Approve Intent -- Start a Transaction
*/
private OnClickListener button_click = new OnClickListener()
{
public void onClick(View v)
{
// Update the text box
text.setText(text.getText().toString().concat("\nAttempting purchase using short code: " + SHORT_CODE));
// Create a new intent to launch the checkout screen
Intent checkout_intent = new Intent();
// Let this intent know that you want to call the
// SingleClick checkout
checkout_intent.setComponent(new ComponentName("com.billingrevolution.singleclick.checkout", "com.billingrevolution.singleclick.checkout.Approve"));
// The only required option is a short-code link or ID
checkout_intent.putExtra("short_code", SHORT_CODE);
// Additional optional details are supplied.
checkout_intent.putExtra("mtid", "abczyx");
checkout_intent.putExtra("mcid", "098hjk");
// Try to collect funds from the user
try
{
18
Single-Click Checkout Developers Guide – Billing Revolution Copyright 2011
// We use *ForResult so that our onActivityResult handler gets called once the transaction is complete
startActivityForResult(checkout_intent, 1);
}
catch (ActivityNotFoundException e)
{
// SCC not installed, fail back to browser based checkout
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://singleclick.mobi/" + SHORT_CODE)));
}
}
};
/*
* This is the callback routine that gets called by Single Click Checkout after the transaction has completed.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (resultCode)
{
case TRANSACTION_CANCELLED:
text.setText(text.getText().toString().concat("\nReturned Status: CANCELLED"));
break;
case TRANSACTION_FAILED:
text.setText(text.getText().toString().concat("\nReturned Status: FAILED"));
break;
case TRANSACTION_SUCCESS:
text.setText(text.getText().toString().concat("\nReturned Status: SUCCESS"));
break;
default:
break;
}
}
iflyfar
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 31, 2011 11:25 pm

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 2 guests