Make Purchase Request
Learn how to make a purchase request
To make one time purchase request in your Android app, follow these simple instructions:
-
Import our library into your project
-
Create PurchaseRequest specifying a APIKEY your service ID
-
Additionally you can set reference parameter on PurchaseRequest by calling setReference(String id) method
-
Create PurchaseManager and attach a new instance of PurchaseListener
-
Start payment by calling PurchaseManager.startPurchase(PurchaseRequest pr, Context context) method.
import c.payments.android.*;
public class LibExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button)findViewById(R.id.buttonPurchase)).setOnClickListener(mPurchaseClick);
}
OnClickListener mPurchaseClick = new OnClickListener() {
@Override
public void onClick(View v) {
PurchaseManager.attachPurchaseListener(new PurchaseListener() {
@Override
public void onPurchaseSuccess(PurchaseResponse paramPurchaseResponse) {
// handle purchase success
}
@Override
public void onPurchaseFailed(PurchaseResponse paramPurchaseResponse) {
// purchase fail
}
@Override
public void onPurchaseCanceled(PurchaseResponse paramPurchaseResponse) {
// purchase canceled by user
}
@Override
public void onPurchaseDialogClosed() {
// purchase dialog closed
}
});
PurchaseRequest pr = new PurchaseRequest(<API-KEY>);
pr.setReference(<YOUR-REFERENCE>); // optional
pr.setPrice(<PRICE>); // optional
pr.setLanguage(<ISO-639-1 code>); // optional
pr.setMsisdn(<MSISDN>); // optional
pr.setOperator(<ISO-639-1 code>); // optional
pr.setCountry(<ISO 3166-1 Alpha 2 code>); // optional
pr.setUserId(<YOUR-USERID>); // optional
pr.setSignature(<GENERATED-SIGNATURE>); // optional
pr.setParam(“mccmnc”,”20102”); // optional
PurchaseManager.startPurchase(pr, LibExample.this);
}
};
Next step...
Updated over 1 year ago