Custom data

When integrating your application with the gateway, you will sometimes find it useful to store your database IDs or other identifiers on the gateway, together with the created objects.

Later when you retrieve the thus enriched objects, you will receive your custom data back as well.

Adding custom data

Adding custom data is enabled on most of the top-level gateway objects, like Customer, Transaction, CreditCard, Plan, Address and some others.

// set all properties as usual, and then add your custom field
transactionRequest.customData("my-field", "my-value");

// or add multiple custom fields at once
Map<String, String> data = new HashMap<String, String>();
data.put("my-field", "value");
data.put("my-field2", "value2");

transactionRequest.customData(data);

You make sure that you are sending non-binary content, and that you try to keep it lightweight as possible, so not to slow down the objects retrieval later.

Reading custom data

Once you retrieve the same gateway object later, you can easily access your custom data.

Transaction transaction = gw.transaction().find("transaction_uid");

// Read your custom data field
txn.getCustomData().get("my-field");