Creating a PaymentDataRequest object

When the buyer is ready to pay, create a PaymentDataRequest object and assign the BaseRequest object to it.

This object should contain information that will be used for the payment:
  • payment gateway details,
  • payment methods supported by your application,
  • additional information that you wish to obtain in the response.

Define the supported payment methods by populating the allowedPaymentMethods property with the result of the getCardPaymentMethod function (see chapter Transmitting supported payment methods).

Define transaction details in the TransactionInfo object:

property totalPriceStatus
value "FINAL"
  Required parameter when making the createPaymentDataRequest() call.

Its value will not be taken into account for the payment.

   
property totalPrice
value "10.00"
  Required parameter when making the createPaymentDataRequest() call.

However, only the value transmitted during the call to the createPayment method of the SOAP Web service API v5 will be taken into account for the payment.

   
property currencyCode
value "EUR"
  Required parameter when making the createPaymentDataRequest() call.

However, only the value transmitted during the call to the createPayment method of the SOAP Web service API v5 will be taken into account for the payment.

For more information, see the documentation of the TransactionInfo object.

Specify the additional information that you wish to obtain in the response:

property billingAddressRequired
value true
  Makes the entry of the billing address mandatory. The selected address will be returned in the payload.

Useful if you wish to offer express checkout to the buyer.

   
property emailRequired
value true
  Allows to transmit the e-mail associated with the selected Google account.
   
property shippingAddressRequired
value true
  Makes the entry of the shipping address mandatory. The address selected by the buyer will be returned in the payload.

Useful if you wish to offer express checkout to the buyer.

   
property phoneNumberRequired
value true
  Makes the entry of the phone number mandatory within the billing and shipping address.

If shippingAddressRequired or billingAddressRequired is set to true, the phone number will be transmitted in the payload.

Useful if you wish to offer express checkout to the buyer.

   

For more information, see the documentation of the PaymentDataRequest object.

Excerpt from the sample code:

private fun preparePaymentDataRequest(price: String, currency: String, gatewayMerchantId: String): PaymentDataRequest {
    val paymentDataRequestJson = getBaseRequest()
    val additionalParams = JSONObject()
    val transactionJson = JSONObject()
    transactionJson
            .put("totalPriceStatus", "FINAL")
            .put("totalPrice", price)
            .put("currencyCode", currency)
    additionalParams.put("billingAddressRequired", true)
    additionalParams
            .put("billingAddressParameters", JSONObject()
            .put("format", "FULL").put("phoneNumberRequired", false))
    paymentDataRequestJson
            .put("allowedPaymentMethods", JSONArray()
            .put(getCardPaymentMethod(additionalParams, getTokenizationSpecification(gatewayMerchantId))))

    paymentDataRequestJson.put("shippingAddressRequired", true)
    paymentDataRequestJson.put("emailRequired", true)
    paymentDataRequestJson.put("transactionInfo", transactionJson)
    return PaymentDataRequest.fromJson(paymentDataRequestJson.toString())
}