Integrating Payments Into Your App
With the mCashier SDK, you can integrate mCashier right into your own app.
The mCashier SDK will show ready-made views that guide the merchant through the payment process and shows a summary in the end.
We're happy to help you with the integration. If you have any questions, please contact
Customer Support.
Before starting the integration, order a card reader by applying for a mCashier account at mcashier.ch. If this is not possible for you (e.g., because you do not have an organization for which you can request a merchant account), please
contact us.
The PayButton installation requires setting compileSdkVersion 25 in your build.gradle file.
Add our repository to your project's build.gradle file:
allprojects {
repositories {
jcenter()
maven {
url "https://repo.visa.com/mpos-releases/"
}
}
}
Add the following exclusion rules to your module's build.gradle file, inside the Android section:
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'LICENSE.txt'
}
Add the libraries to the dependencies section of your module's build.gradle file:
dependencies {
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'io.payworks:mpos.android.ui:2.61.0'
compile 'io.payworks:mpos.java.accessories.miura:2.61.0'
compile 'io.payworks:mpos.android.comlinks.bluetooth:2.61.0'
}
Initialize an instance of the MposUi before using it:
MposUi mposUi = MposUi.initialize(this, ProviderMode.LIVE, ApplicationName.MCASHIER, "YOUR-INTEGRATOR-IDENTIFIER");
mposUi.getConfiguration().setSummaryFeatures(EnumSet.of(MposUiConfiguration.SummaryFeature.SEND_RECEIPT_VIA_EMAIL));
Make sure to insert your integratorIdentifier. You receive your integratorIdentifier when you sign up for the SDK, or by
sending us an email.
You can then access the initialized instance with the following:
MposUi mposUi = MposUi.getInitializedInstance();
MposUi mposUi = MposUi.getInitializedInstance();
TransactionParameters transactionParameters = new TransactionParameters.Builder()
.charge(new BigDecimal("5.00"), io.mpos.transactions.Currency.EUR)
.subject("Bouquet of Flowers")
.customIdentifier("yourReferenceForTheTransaction")
.build();
Intent intent = mposUi.createTransactionIntent(transactionParameters);
startActivityForResult(intent, MposUi.REQUEST_CODE_PAYMENT);
The result of the payment is delivered to your activity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MposUi.REQUEST_CODE_PAYMENT) {
if (resultCode == MposUi.RESULT_CODE_APPROVED) {
// Transaction was approved
Toast.makeText(this, "Transaction approved", Toast.LENGTH_LONG).show();
} else {
// Card was declined, or transaction was aborted, or failed
// (e.g. no internet or accessory not found)
Toast.makeText(this, "Transaction was declined, aborted, or failed",
Toast.LENGTH_LONG).show();
}
// Grab the processed transaction in case you need it
// (e.g. the transaction identifier for a refund).
// Keep in mind that the returned transaction might be null
// (e.g. if it could not be registered).
Transaction transaction = MposUi.getInitializedInstance().getTransaction();
}
}
To refund a transaction, you need the transaction.identifier:
MposUi mposUi = MposUi.getInitializedInstance();
TransactionParameters refundParameters = new TransactionParameters.Builder()
.refund("TRANSACTION-IDENTIFIER>")
.build();
Intent refundIntent = mposUi.createTransactionIntent(refundParameters);
startActivityForResult(intent, MposUi.REQUEST_CODE_PAYMENT);
The result of the refund is delivered the same way as in the payment process.
To show a transaction summary, use the transaction.identifier of the transaction.
MposUi mposUi = MposUi.getInitializedInstance();
Intent summaryIntent = mposUi.createTransactionSummaryIntent(mLastTransactionIdentifier);
startActivityForResult(summaryIntent, MposUi.REQUEST_CODE_SHOW_SUMMARY);
To show the Settings screen that enables the user to log out and access to help:
MposUi mposUi = MposUi.getInitializedInstance();
Intent intent = mposUi.createSettingsIntent();
startActivityForResult(intent, MposUi.REQUEST_CODE_SETTINGS);
At some point, you might want to force a log out such as when the user logs out from your app. To force a log out:
MposUi mposUi = MposUi.getInitializedInstance()
mposUi.logout();
To check if a user is logged in:
MposUi mposUi = MposUi.getInitializedInstance()
boolean isLoggedIn = mposUi.isLoggedIn();
Custom and Printed Receipts
To create custom or printed receipts, access the embedded receipt objects after the transaction completes. Make sure to check if the user is logged in, otherwise you cannot query the receipt data. Custom and printed receipt must contains, at the minimum, all the information shown on the email receipt.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MposUi.REQUEST_CODE_PAYMENT) {
[...]
//get hold of the last transaction
Transaction transaction = MposUi.getInitializedInstance().getTransaction();
Receipt merchantReceipt = transaction.getMerchantReceipt();
Receipt customerReceipt = transaction.getCustomerReceipt();
}
}