Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC for reducing login calls on the SDK #146

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PoC for reducing login calls on the SDK
Vincent committed Oct 30, 2020
commit cdb11fb91d6c5fd575f5b1b834b6f5e571a04c2f
37 changes: 37 additions & 0 deletions app/src/main/java/com/sumup/sdksampleapp/MainActivity.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.sumup.android.logging.Log;
import com.sumup.merchant.reader.models.TransactionInfo;
import com.sumup.merchant.reader.api.SumUpAPI;
import com.sumup.merchant.reader.api.SumUpLogin;
@@ -116,6 +117,33 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
case REQUEST_CODE_LOGIN:
if (data != null) {
Bundle extra = data.getExtras();

if (extra.getInt(SumUpAPI.Response.RESULT_CODE)
== SumUpAPI.Response.ResultCode.SUCCESSFUL) {

Log.i("Login successful. Can proceed with checkout.");

// do checkout
SumUpPayment payment = SumUpPayment.builder()
// mandatory parameters
.total(new BigDecimal("1.12")) // minimum 1.00
.currency(SumUpPayment.Currency.EUR)
// optional: add details
.title("Taxi Ride")
.receiptEmail("customer@mail.com")
.receiptSMS("+3531234567890")
// optional: Add metadata
.addAdditionalInfo("AccountId", "taxi0334")
.addAdditionalInfo("From", "Paris")
.addAdditionalInfo("To", "Berlin")
// optional: foreign transaction ID, must be unique!
.foreignTransactionId(UUID.randomUUID().toString()) // can not exceed 128 chars
.build();

SumUpAPI.checkout(MainActivity.this, payment, REQUEST_CODE_PAYMENT);
return;
}

mResultCode.setText("Result code: " + extra.getInt(SumUpAPI.Response.RESULT_CODE));
mResultMessage.setText("Message: " + extra.getString(SumUpAPI.Response.MESSAGE));
}
@@ -125,6 +153,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
Bundle extra = data.getExtras();

if (extra.getInt(SumUpAPI.Response.RESULT_CODE)
== SumUpAPI.Response.ResultCode.ERROR_NOT_LOGGED_IN) {

Log.i("No user logged in. Redirecting to login.");
SumUpLogin sumupLogin = SumUpLogin.builder("7ca84f17-84a5-4140-8df6-6ebeed8540fc").build();
SumUpAPI.openLoginActivity(MainActivity.this, sumupLogin, REQUEST_CODE_LOGIN);
return;
}

mResultCode.setText("Result code: " + extra.getInt(SumUpAPI.Response.RESULT_CODE));
mResultMessage.setText("Message: " + extra.getString(SumUpAPI.Response.MESSAGE));