question

marain avatar image
marain asked marain commented

Android OrderConnector cash payment

Hi,

I'm trying to create an order and place a cash payment. After creating an order with some custom items on it I try to pay using:

Payment payment = new Payment();
payment.setTender(mTender);
payment.setCashTendered(amount);
payment.setAmount(amount);

orderConnector.addPayment(mOrderId, payment, order.getLineItems());

I also tried:

PaymentRequest paymentRequest = new PaymentRequest();
paymentRequest.setTender(mTender);
paymentRequest.setCashTendered(amount);
paymentRequest.setAmount(amount);

orderConnector.pay(order.getId(), paymentRequest, true, null);

I use this code to retrieve the tender:

List<com.clover.sdk.v1.tender.Tender> tenders = tenderConnector.getTenders();
for (com.clover.sdk.v1.tender.Tender tender :
        tenders) {
    if (tender.getLabelKey().equalsIgnoreCase(TenderConstants.CASH))
    {
        mTender = getV3TenderFromV1(tender);
        break;
    }
}

But I'm getting the error:

com.clover.sdk.v1.ForbiddenException: App doesn't have required permission
    at com.clover.sdk.v1.ServiceConnector.throwOnFailure(ServiceConnector.java:275)
    at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:210)
    at com.clover.sdk.v3.order.OrderConnector.pay(OrderConnector.java:432)

The application has all permissions. I do not have point to upload the picture....

Thank you

EDIT

I also tried REST API:

This is what I do:

CloverAuth.AuthResult authResult = CloverAuth.authenticate(this, account); 
CustomHttpClient httpClient = CustomHttpClient.getHttpClient(); 
String paymentsUri = "/v3/merchants/" + mMerchant.getId() + "/orders/" + mOrderId + "/payments/"; 
String url = authResult.baseUrl + paymentsUri + "?access_token=" + authResult.authToken; 
JSONObject payment = new JSONObject();
payment.put("amount", amount);

JSONObject tender = new JSONObject();
tender.put("id", mTender.getId());
payment.put("tender", tender);

String result = httpClient.post(url, payment.toString());

I get tender as described above and merchant as follows:

App app = appsConnector.getApp();
mMerchant = app.getMerchant();

Also I checked the apps permissions:

{
  "androidPermissions": {
    "elements": [

    ]
  },
  "permissionPaymentsRead": true,
  "permissionInventoryRead": true,
  "permissionProcessCards": true,
  "permissionEmployeesWrite": true,
  "permissionInventoryWrite": true,
  "permissionCustomersWrite": false,
  "permissionMerchantWrite": true,
  "permissionOrdersWrite": true,
  "permissionMerchantRead": true,
  "permissionMidRead": true,
  "permissionPaymentsWrite": true,
  "permissionOrdersRead": true,
  "permissionCustomersRead": false,
  "permissionEmployeesRead": true
}

How can I solve this issue? Could this be a sandbox issue?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Jeffrey Blattman avatar image
Jeffrey Blattman answered marain commented

There are certain SDK calls that we restrict only to Clover applications, and OrderConnector.pay() is one of them. This is a feature we have considered adding for third parties but there are many fine details to adding a payment that need to be documented, and our system needs to be protected fully against the cases where improper payments might be added by a third party.

We don't currently have a mechanism for programmtically adding a payment. You should send the user to the payments UI like this,

Intent payIntent = new Intent(Intents.ACTION_CLOVER_PAY);
startActivityForResult(payIntent, requestCode);

The result will tell you if the payment was made, not not. Of course this doesn't insist on a cash payment. The user would be able to pay with any valid tender.

EDIT: you can add a payment using the comparable REST API however. This obviously doesn't make sense that it's allowed via REST but not the Android SDK. It's something we will look into. Please see the answer here for an explanation on using the REST API to add a payment.

5 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

marain avatar image marain commented ·

Hi,

The problem is I tried REST API but sometimes work and sometimes doesn't. Same issue 401.1 Unauthorised.

0 Likes 0 ·
marain avatar image marain commented ·

This is what I do: 1.account = CloverAccount.getAccount(this); 2.App app = appsConnector.getApp(); mMerchant = app.getMerchant(); 3. Get tender cash as above 4. CloverAuth.AuthResult authResult = CloverAuth.authenticate(this, account); 5. CustomHttpClient httpClient = CustomHttpClient.getHttpClient(); String paymentsUri = "/v3/merchants/" + mMerchant.getId() + "/orders/" + mOrderId + "/payments/"; String url = authResult.baseUrl + paymentsUri + "?access_token=" + authResult.authToken; and I POST {amount:amount, tender:{id:x}} I've remove json creation because of comment lenght limit

0 Likes 0 ·
Dan avatar image Dan commented ·

It would be very useful if things like that were documented, even with an obvious exception thrown, or better still the function hidden from us. Much of my time on Clover has been spent trying to figure out why functions like this are not working, only to eventually assume it's just something we 'aren't supposed to use'!

0 Likes 0 ·
Mike M avatar image Mike M commented ·

Hi @Marain, I just successfully was able to post a Payment to an Order via the v3 REST API in our Sandbox environment. Can you please verify your http POST request via Postman or a similar client?

The only possible difference from your code that I can think of is that your url has an additional / before ?access_token.... Can you try removing that? (i.e. {baseUrl}/v3/merchants/{mId}/orders/{orderId}/payments?access_token={authToken})

Also, on another note, you case use MerchantConnector.getMerchant() to get the merchant.

0 Likes 0 ·
marain avatar image marain commented ·

Hi Mike,

Seams that now is working. It worked for me before but when added a second clover mini device to my dev account started to not work. I've un installed and deleted the app for both devices but had same authorisation issue. I hope will work fine in production.

0 Likes 0 ·

Welcome to the
Clover Developer Community