A simple contract based on
TaskResultContracts.GetApiTaskResult
that returns a wrapper including a
PaymentData
object and additional information about the Task
operation.
This contract resolves a Task
created by the
Google Pay API client and returns a result containing the PaymentData
object and additional information about the API call.
Below is an example that uses this contract to return a ApiTaskResult
<PaymentData>
from a completed Task
object created by
the
PaymentsClient.loadPaymentData(PaymentDataRequest)
method:
// Use the contract to create an activity result launcher
val paymentDataLauncher = registerForActivityResult(GetPaymentDataResult()) {
when (it.status.statusCode) {
CommonStatusCodes.SUCCESS -> // Do something with the result (it.result: PaymentData?)
CommonStatusCodes.CANCELED -> // The user canceled
AutoResolveHelper.RESULT_ERROR -> // The API returned an error (it.status: Status)
CommonStatusCodes.INTERNAL_ERROR -> // Handle other unexpected errors
}
}
// Start the task operation and associate it with the activity launcher
val paymentDataTask: Task<PaymentData> = paymentsClient.loadPaymentData(request)
paymentDataTask.addOnCompleteListener(context, paymentDataLauncher::launch)
Public Constructor Summary
Public Method Summary
ApiTaskResult<PaymentData> |
parseResult(int resultCode, Intent
intent)
|
Protected Method Summary
PaymentData |