CyberSource / cybersource-rest-client-ruby

Ruby client library for the CyberSource REST API
Other
6 stars 36 forks source link

Apple Pay call is missing field paymentInformation.card.number #43

Closed kanyonbollinger closed 2 years ago

kanyonbollinger commented 4 years ago

This Ruby library looks like it should support Apple Pay. However when submitting the request, it seems that the API is looking for a card number, not the token provided by the Apple Pay Javascript library. Here's a sample of my code:

client_reference_information = CyberSource::Ptsv2paymentsClientReferenceInformation.new
client_reference_information.code = order.order_number

processing_information = CyberSource::Ptsv2paymentsProcessingInformation.new
processing_information.commerce_indicator = "internet"
processing_information.capture = true

processing_information.payment_solution = '001'

mobile_payment = CyberSource::Ptsv2paymentsPaymentInformationFluidData.new
mobile_payment.key_serial_number = "eyJ2ZXJzaW9uIjoiRUNfdjEiLCJkYXRhIjoiZktI..."
mobile_payment.descriptor = "RklEPUNPTU1PTi5BUFBMRS5JTkFQUC5QQVlNRU5U"
mobile_payment.encoding = "Base64"
payment_information.fluid_data = mobile_payment

request = CyberSource::CreatePaymentRequest.new
request.processing_information = processing_information
request.client_reference_information = client_reference_information
request.payment_information = payment_information

payments_api_instance = CyberSource::PaymentsApi.new(
  CyberSource::ApiClient.new,
  MerchantConfiguration.new.merchantConfigProp
)
data, status_code, _headers = payments_api_instance.create_payment(request)

The response I'm getting back is:

Exception: #<CyberSource::ApiError: {
  :code=>400, 
  :response_headers=>{
    "Content-Type"=>"application/json", 
    "Content-Length"=>"237", 
    "X-Cnection"=>"close", 
    "x-response-time"=>"192ms", 
    "Strict-Transport-Security"=>"max-age=31536000", 
    "v-c-correlation-id"=>"0cacc2cc-1bb3-4ea7-96d0-d8e01cb1de9e"}, 
  :response_body=>"{
    "submitTimeUtc":"2020-05-22T21:55:51Z",
    "status":"INVALID_REQUEST",
    "reason":"MISSING_FIELD",
    "message":"Declined - The request is missing one or more fields",
    "details":[{"field":"paymentInformation.card.number","reason":"MISSING_FIELD"}]
    }"}>

As you know, an Apple Pay request would not include the card number when opting to have CyberSource decrypt the Apple Pay token. Any help here would be greatly appreciated!

kanyonbollinger commented 4 years ago

I was able to resolve this by removing the limit placed on the attribute value from the Ptsv2paymentsPaymentInformationFluidData class.