question

gsm-tommy avatar image
gsm-tommy asked parquet76 edited

Adding a Vaulted Card to a created customer using Clover Connector

Hi, I have an app that allows creating a customer after swiping their card and then save the card to that created customer object using clover connector. The issue now is after customer is been created through card swiping, I was able to get the vaultedCard response, but the card was not saving to the customer created instead it keeps throwing this error:

W InputValidator: checkCloverId(InputValidator.java:379)[Binder:2364_4]: Not a valid Clover ID: 7297162975886668, app=unknown


Method for creating a customer;


public void createNewCustomerAndVaultCard(String firstName, String lastName) {
    if (mAccount == null) {
        Toast.makeText(this, "Clover account not found!", Toast.LENGTH_SHORT).show();
        return;
    }

    // create customer
    boolean marketingAllowed = false;
    new CreateCustomerTask(customerConnector, firstName, lastName, marketingAllowed,
            new OnCustomerCreatedListener() {
                @Override
                public void onCustomerCreated(Customer customer) {
                    // Customer created successfully then vault a new card for the customer
                    vaultCard(customer);
                }

                @Override
                public void onError(String message) {
                    // Error creating customer
                }
            }).execute();

}


Method for the vaultCard;


private void vaultCard(Customer customer) {
        createdCustomer = customer;
        int cardEntryMethods = CloverConnector.CARD_ENTRY_METHOD_MAG_STRIPE | CloverConnector.CARD_ENTRY_METHOD_NFC_CONTACTLESS | CloverConnector.CARD_ENTRY_METHOD_ICC_CONTACT;

        cloverConnector.vaultCard(cardEntryMethods);
    }


Method for the onVaultCardResponse using the Clover Connector;


public void onVaultCardResponse(VaultCardResponse response) {
                if(response.isSuccess()){
                    VaultedCard vaultedCard = response.getCard();

                    // Get the card token
                    String token = vaultedCard.getToken();

                    // Create a new Card object with the necessary information
                    Card card = new Card.Builder()
                            .token(token)
                            .first6(vaultedCard.getFirst6())
                            .last4(vaultedCard.getLast4())
                            .expirationDate(vaultedCard.getExpirationDate())
                            .build();

                    // Associate the vaulted card with the customer
                    try {
                        customerConnector.setCard(createdCustomer.getId(), token, card);

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                  
                                createdCustomer = null;
                                Toast.makeText(Activity.this, "Card vaulted successfully.", Toast.LENGTH_SHORT).show();
                            }
                        });
                    } catch (ClientException e) {
                        throw new RuntimeException(e);
                    } catch (ServiceException e) {
                        throw new RuntimeException(e);
                    } catch (BindingException e) {
                        throw new RuntimeException(e);
                    } catch (RemoteException e) {
                        throw new RuntimeException(e);
                    }finally {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(this, "Card vaulted unsuccessful.", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }else{
                    if (response.getResult() == ResultCode.CANCEL) {
                        Toast.makeText(this, "User canceled the operation", Toast.LENGTH_SHORT).show();
                        cloverConnector.showWelcomeScreen();
                    }else{
                        Toast.makeText(this, "Error capturing card: " + response.getResult(), Toast.LENGTH_SHORT).show();
                        String msg = "Card was not saved";
                        JsonObject jsonMsg = new JsonObject();
                        jsonMsg.addProperty("message", msg);
                        cloverConnector.showMessage(msg);
                        SystemClock.sleep(4000); //wait 4 seconds
                        cloverConnector.showWelcomeScreen();
                    }
                }
            }



Please kindly help me out.

Clover Android SDK
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

·
bryanvargas avatar image
bryanvargas answered parquet76 edited

Clover doesn't support card vaulting due to deprecating DevPay, you should migrate to Ecomm to save a card to a customer.


https://docs.clover.com/docs/migrating-from-developer-pay-to-ecommerce

Clover Android Payments API will soon have this feature again.

https://docs.clover.com/docs/using-clover-android-payments-api

4 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.

gsm-tommy avatar image gsm-tommy commented ·

I have gotten the right api with my access_token and customerId.

curl --request PUT \  --url 'https://scl-sandbox.dev.clover.com/v1/customers/{customerId}' \  
--header 'accept: application/json' \  
--header 'authorization: Bearer {access_token}' \  
--header 'content-type: application/json' \  
--data '{"source":"{token}"}'

Then for the `source: {token}`, how do I get that? Because I set the token from the vaulted card response after customer swipe their cards like this:

// Get the card token
String token = vaultedCard.getToken();


But I keep getting:

{
    "message": "400 Bad Request",
    "error": {
        "type": "invalid_request_error",
        "code": "invalid_request",
        "message": "Please provide a valid source or token."
    }
}


In addition, I made sure to enable the right permissions including `e-commerce for processing payment online and also chose API Integration Type in the e-commerce settings` but still gets the same error. I have also uninstall and reinstalled the app on my clover device. If that's not the right value for the body data '{"source": "{token}"}'. How do I get the right value for the source?

My sample customer response as well:

{
  "href": "https://sandbox.dev.clover.com/v3/merchants/{merchantId}/customers/{customerId}",
  "id": "{customerId}",
  "firstName": "April",
  "lastName": "18",
  "marketingAllowed": false,
  "customerSince": 1681856847000,
  "metadata": {}
}


Thanks in advance.

0 Likes 0 ·
greyskymedia avatar image greyskymedia gsm-tommy commented ·

Any feedback Bryan?

0 Likes 0 ·
greyskymedia avatar image greyskymedia commented ·
Following up again @bryanvargas , any thoughts?
0 Likes 0 ·
parquet76 avatar image parquet76 greyskymedia commented ·

Not sure what Bryan is talking about, Clover certainly does support card vaulting. What does the token in the vault response from the Clover Connector API look like? If it isn't a string beginning with "clv" it isn't going to work. I'd use Rest Pay API and see if that works - https://docs.clover.com/docs/creating-a-card-token. I am guessing Clover Connector sdks don't support this (considering you have to pass a special token type flag to do it with Rest Pay API) or you need to update your sdk (check the recent releases see if there are any relevant release notes).

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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

Welcome to the
Clover Developer Community