Skip to content

Instantly share code, notes, and snippets.

@runemart
Created June 8, 2017 06:44
Show Gist options
  • Save runemart/1ff98004b32c46cbbd052acb64a482cd to your computer and use it in GitHub Desktop.
Save runemart/1ff98004b32c46cbbd052acb64a482cd to your computer and use it in GitHub Desktop.
Mobile pay simple integration
@Click(R.id.povh_mobilepay_view)
protected void onMobilePayClick() {
if (MobilePay.getInstance().isMobilePayInstalled(getApplicationContext())) {
Payment payment = new Payment();
payment.setProductPrice(new BigDecimal(ticketOrderRequest.getSum()));
// TODO Add proper payment details
payment.setOrderId("foobar");
startActivityForResult(MobilePay.getInstance().createPaymentIntent(payment), REQUEST_MOBILEPAY_PAYMENT);
} else {
startActivity(MobilePay.getInstance().createDownloadMobilePayIntent(getApplicationContext()));
}
}
@OnActivityResult(REQUEST_MOBILEPAY_PAYMENT)
protected void onMobilePayResult(int resultCode, Intent data) {
MobilePay.getInstance().handleResult(resultCode, data, new ResultCallback() {
@Override
public void onSuccess(SuccessResult result) {
// TODO: verify with backend and download tickets
}
@Override
public void onFailure(FailureResult result) {
Toast.makeText(PaymentActivity.this, result.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment