Request a tip
United States
Use the RequestTipIntentBuilder
class to build an Intent to display a tip screen for a customer.
Prerequisites
- Read overview of the Clover platform.
- Create a global developer account with a default test merchant account.
- Order a Clover Developer Kit (Dev Kit) and set it up.
- Use the required Android SDK versions.
Step
Build a simple tip request.
val tippableAmount = 2000L;
val builder = RequestTipIntentBuilder(tippableAmount)
val intent = builder.build(context)
long tippableAmount = 2000l;
RequestTipIntentBuilder builder = new RequestTipIntentBuilder(tippableAmount);
Intent intent = builder.build(context);
Additional field
Additional field to set on the RequestTipIntentBuilder
class.
Field | Description |
---|---|
tipSuggestions : List<TipSuggestion> | List of up to four tip suggestions on either percentage or fixed amounts. Percentage-based suggestions are calculated based on the tippableAmount . |
Example—Create custom tip suggestions
var tipSuggestions = listOf<TipSuggestion>(
TipSuggestion.Percentage("Thanks!", 20L),
TipSuggestion.Percentage("Good Job!", 25L),
TipSuggestion.Percentage("Great!", 35L)
)
val tippableAmount = 2000L
val builder = RequestTipIntentBuilder(tippableAmount).tipSuggestions(tipSuggestions)
val intent = builder.build(context)
List<TipSuggestion> tipSuggestions = Arrays.asList(
TipSuggestion.Percentage("Thanks!", 20L),
TipSuggestion.Percentage("Good Job!", 25L),
TipSuggestion.Percentage("Great!", 35L));
long tippableAmount = 2000l;
RequestTipIntentBuilder builder = new RequestTipIntentBuilder(tippableAmount).tipSuggestions(tipSuggestions);
Intent intent = builder.build(context);
Response details
When the tip selection flow completes, the response is available through onActivityResult()
Check the RequestTipIntentBuilder.Response
class for the response fields.
- For a successful request, retrieve the tip amount using the Intent:
RequestTipIntentBuilder.Response.TIP_AMOUNT
- For an unsuccessful request (error, failure, or cancellation), retrieve the optional failure message using the Intent:
RequestTipIntentBuilder.Response.FAILURE_MESSAGE
Response example
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == TIP_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
val tipAmount = data?.getLongExtra(RequestTipIntentBuilder.Response.TIP_AMOUNT, -1)
} else {
// tip request failed, check for error
val failureMessage = data?.getStringExtra(RequestTipIntentBuilder.Response.FAILURE_MESSAGE)
}
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TIP_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
long tipAmount = data.getLongExtra(RequestTipIntentBuilder.Response.TIP_AMOUNT, -1);
} else {
// tip request failed, check for error
String failureMessage = data.getStringExtra(RequestTipIntentBuilder.Response.FAILURE_MESSAGE);
}
}
}
Updated 3 months ago