Customers API - MonriPayments/monri-android GitHub Wiki
Our customers API allows you to securely save customer data and payment methods. In order to associate customer's payment method for future payments you have to provide customer UUID in the transaction params, details below.
In order to operate with our Customer API you have to obtain access token and forward to your mobile app.
Here is example how to create access token with your backend:
POST request on endpoint https://ipgtest.monri.com/v2/oauth Body:
{
"client_id": "Authenticity token",
"client_secret": "Merchant key",
"scopes": ["customers", "payment-methods"],
"grant_type": "client_credentials"
}
Response example:
{
"access_token": "*********************",
"token_type": "Bearer",
"expires_in": 900,
"status": "approved"
}
Create Monri instance in onCreate method (or before):
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
monri = new Monri(((ActivityResultCaller) this), MonriApiOptions.create("merchant authenticity token", true));
//...
}
In order to create a Customer
you’ve to provide:
- access token
CustomerData
//...
String accessToken = "Bearer *********************" //access token from backend
CustomerData customerData = new CustomerData()
.setMerchantCustomerUuid(merchantCustomerId)//optional, you can use your own uuid
.setDescription("description")
.setEmail("[email protected]")
.setName("Adnan")
.setPhone("00387000111")
.setMetadata(new HashMap<>() {{
put("a", "b");
}})
.setZipCode("71000")
.setCity("Sarajevo")
.setAddress("Džemala Bijedića 2")
.setCountry("BA");
CreateCustomerParams createCustomerParams = new CreateCustomerParams(
customerData,
accessToken
);
monri.getMonriApi().customers().create(
createCustomerParams,
new ResultCallback<Customer>() {
@Override
public void onSuccess(final Customer result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//...
}
});
//...
In order to update a Customer
you’ve to provide:
- access token
UpdateCustomerParams
//...
final CustomerData updateCustomerData = new CustomerData()
.setEmail("[email protected]")
.setName("Adnan")
.setPhone("00387000112");
final UpdateCustomerParams updateCustomerParams = new UpdateCustomerParams(
updateCustomerData,
"created customer uuid",
"accessToken from backend"
);
monri.getMonriApi()
.customers()
.update(
updateCustomerParams,
new ResultCallback<Customer>() {
@Override
public void onSuccess(final Customer result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//...
}
}
);
//...
In order to delete a Customer
you’ve to provide:
- access token
DeleteCustomerParams
//...
final DeleteCustomerParams deleteCustomerParams = new DeleteCustomerParams(
"accessToken",
"created customer uuid"
);
monri.getMonriApi().customers().delete(
deleteCustomerParams,
new ResultCallback<DeleteCustomerResponse>() {
@Override
public void onSuccess(final DeleteCustomerResponse result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//..
}
}
);
//...
In order to retrieve a Customer
you’ve to provide:
- access token
GetCustomerParams
//...
final GetCustomerParams retrieveCustomerParams = new GetCustomerParams(
"accessToken",
"created customer uuid"
);
monri.getMonriApi().customers().get(
retrieveCustomerParams,
new ResultCallback<Customer>() {
@Override
public void onSuccess(final Customer result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//...
}
}
);
//...
In order to retrieve a Customer
via Merchant Uuid you’ve to provide:
- access token
RetrieveCustomerViaMerchantCustomerUuidParams
//...
final RetrieveCustomerViaMerchantCustomerUuidParams retrieveCustomerViaMerchantCustomerUuidParams = new RetrieveCustomerViaMerchantCustomerUuidParams(
"accessToken",
"created customer uuid"
);
monri.getMonriApi().customers().getViaMerchantCustomerUuid(
retrieveCustomerViaMerchantCustomerUuidParams,
new ResultCallback<Customer>() {
@Override
public void onSuccess(final Customer result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//...
}
}
);
//...
In order to get all customers you’ve to provide:
- access token
//...
monri.getMonriApi().customers().all("accessToken", new ResultCallback<MerchantCustomers>() {
@Override
public void onSuccess(final MerchantCustomers result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//...
}
});
//...
In order to retrieve all customer payment methods you’ve to provide:
- access token
CustomerPaymentMethodParams
//...
final CustomerPaymentMethodParams customerPaymentMethodParams = new CustomerPaymentMethodParams(
"created customer uuid",
20,//limit
0,//offset
"accessToken"
);
monri.getMonriApi().customers().paymentMethods(
customerPaymentMethodParams,
new ResultCallback<CustomerPaymentMethodResponse>() {
@Override
public void onSuccess(final CustomerPaymentMethodResponse result) {
//...
}
@Override
public void onError(final Throwable throwable) {
//...
}
}
);
//...
In order to associate customer's payment method for future payments, beside customer's data which is optional, you have to provide also:
- created customer UUID
- clientSecret - please see our section about Payment API Integration
final Card card = new Card("4111 1111 1111 1111", 12, 2034, "123");
final CustomerParams customerParams = new CustomerParams()
.setCustomerUuid("created customer UUID")
.setAddress("Adresa")
.setFullName("Adnan Omerovic")
.setCity("Sarajevo")
.setZip("71000")
.setPhone("+38761000111")
.setCountry("BA")
.setEmail("[email protected]");
card.setTokenizePan(true);//save card for future payment
ConfirmPaymentParams confirmPaymentParams = ConfirmPaymentParams.create(
"clientSecret",
card.toPaymentMethodParams(),
TransactionParams.create()
.set("order_info", "Android SDK payment session")
.set(customerParams)
);
monri.confirmPayment(confirmPaymentParams, (PaymentResult result, Throwable cause) -> {
if (cause == null) {
//... handle result
} else {
//... handle error
}
});