Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Commit 6db2079

Browse files
committed
add market place call
1 parent e8adb69 commit 6db2079

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

app/src/main/java/com/instamojo/androidsdksample/MainActivity.java

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,40 @@ public void onClick(View v) {
9898
Instamojo.setLogLevel(Log.DEBUG);
9999
}
100100

101+
// this is for the market place
102+
// you should have created the order from your backend and pass back the order id to app for the payment
103+
private void fetchOrder(String accessToken, String orderID){
104+
// Good time to show dialog
105+
Request request = new Request(accessToken, orderID, new OrderRequestCallBack() {
106+
@Override
107+
public void onFinish(final Order order, final Exception error) {
108+
runOnUiThread(new Runnable() {
109+
@Override
110+
public void run() {
111+
dialog.dismiss();
112+
if (error != null) {
113+
if (error instanceof Errors.ConnectionError) {
114+
showToast("No internet connection");
115+
} else if (error instanceof Errors.ServerError) {
116+
showToast("Server Error. Try again");
117+
} else if (error instanceof Errors.AuthenticationError) {
118+
showToast("Access token is invalid or expired. Please Update the token!!");
119+
} else {
120+
showToast(error.toString());
121+
}
122+
return;
123+
}
124+
125+
startPreCreatedUI(order);
126+
}
127+
});
128+
129+
}
130+
});
131+
132+
request.execute();
133+
}
134+
101135
private void createOrder(String accessToken, String transactionID) {
102136
String name = nameBox.getText().toString();
103137
final String email = emailBox.getText().toString();
@@ -327,8 +361,8 @@ public void run() {
327361
*
328362
* @param transactionID Unique identifier of a transaction ID
329363
*/
330-
private void checkPaymentStatus(final String transactionID) {
331-
if (accessToken == null || transactionID == null) {
364+
private void checkPaymentStatus(final String transactionID, final String orderID) {
365+
if (accessToken == null || (transactionID == null && orderID == null)) {
332366
return;
333367
}
334368

@@ -338,11 +372,15 @@ private void checkPaymentStatus(final String transactionID) {
338372

339373
showToast("checking transaction status");
340374
OkHttpClient client = new OkHttpClient();
341-
HttpUrl url = getHttpURLBuilder()
342-
.addPathSegment("status")
343-
.addQueryParameter("transaction_id", transactionID)
344-
.addQueryParameter("env", currentEnv.toLowerCase())
345-
.build();
375+
HttpUrl.Builder builder = getHttpURLBuilder();
376+
builder.addPathSegment("status");
377+
if (transactionID != null){
378+
builder.addQueryParameter("transaction_id", transactionID);
379+
} else {
380+
builder.addQueryParameter("id", orderID);
381+
}
382+
builder.addQueryParameter("env", currentEnv.toLowerCase());
383+
HttpUrl url = builder.build();
346384

347385
okhttp3.Request request = new okhttp3.Request.Builder()
348386
.url(url)
@@ -499,8 +537,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
499537
String paymentID = data.getStringExtra(Constants.PAYMENT_ID);
500538

501539
// Check transactionID, orderID, and orderID for null before using them to check the Payment status.
502-
if (orderID != null && transactionID != null && paymentID != null) {
503-
checkPaymentStatus(transactionID);
540+
if (transactionID != null || paymentID != null) {
541+
checkPaymentStatus(transactionID, orderID);
504542
} else {
505543
showToast("Oops!! Payment was cancelled");
506544
}

0 commit comments

Comments
 (0)