cancel
Showing results for 
Search instead for 
Did you mean: 

Apple Pay - Required fields are missing from decrypted data

I am trying to set up apple pay using objective c for a native iPhone app.  I have not been able to get Apple Pay to successfully process a transaction.  I have tried it in both production and sandbox, and I am getting the below error message for both environments using a real MasterCard Credit Card.  
 
Any ideas as to why my transactions are not getting processed?  What fields are missing from the decrypted data and what I can do to add them?
 
JSON sent to api:
{
	"createTransactionRequest": {
		"merchantAuthentication": {
			"name": "ApiLoginHere",
			"transactionKey": "TransactionKeyHere"
		},
		"refId": "123456",
		"transactionRequest": {
			"transactionType": "authCaptureTransaction",
			"amount": "0.01",
			"payment": {
				"opaqueData": {
					"dataDescriptor": "COMMON.APPLE.INAPP.PAYMENT",
					"dataValue": "eyJ2ZX...GEifX0="
				}
			},
			"lineItems": {
				"lineItem": {
					"itemId": "1",
					"name": "Donation",
					"description": "Donation",
					"quantity": "1",
					"unitPrice": "0.01"
				}
			}
		}
	}
}
 
JSON returned from api call:
{
	"transactionResponse": {
		"responseCode": "3",
		"authCode": "",
		"avsResultCode": "P",
		"cvvResultCode": "",
		"cavvResultCode": "",
		"transId": "0",
		"refTransID": "",
		"transHash": "3C0B543D31B546B9FB07763547E76925",
		"testRequest": "0",
		"accountNumber": "",
		"accountType": "",
		"errors": [{
			"errorCode": "153",
			"errorText": "There was an error processing the payment data. Required fields are missing from decrypted data."
		}],
		"transHashSha2": ""
	},
	"refId": "123456",
	"messages": {
		"resultCode": "Error",
		"message": [{
			"code": "E00027",
			"text": "The transaction was unsuccessful."
		}]
	}
}
 
After the user clicks the apple pay button, giving Apple Pay the payment information:
self.donationAmount = [NSDecimalNumber decimalNumberWithString:@"0.01"];
PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
request.countryCode = @"US";
request.currencyCode = @"USD";
request.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa];
request.merchantCapabilities = PKMerchantCapabilityEMV;
request.merchantIdentifier = @"merchant.mymerchantidentifier.org";
        
PKPaymentSummaryItem *paymentTotal = [PKPaymentSummaryItem summaryItemWithLabel:@"" amount:self.donationAmount];
request.paymentSummaryItems = @[paymentTotal];
        
PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentPane.delegate = self;
[self presentViewController:paymentPane animated:TRUE completion:nil];
 
In the paymentAuthorizationViewController method, sending the data to authorize.net:
PKPaymentToken *paymentToken = payment.token;
NSData *data = paymentToken.paymentData;
NSString *base64Encoded = [data base64EncodedStringWithOptions:0];

    NSString *body = [NSString stringWithFormat: @"{\"createTransactionRequest\": {"
    "\"merchantAuthentication\": {"
        "\"name\": \"ApiLoginIdHere\","
        "\"transactionKey\": \"TransactionKeyHere\""
    "},"
        "\"refId\": \"123456\","
        "\"transactionRequest\": {"
            "\"transactionType\": \"authCaptureTransaction\","
            "\"amount\": \"0.01\","
            "\"payment\": {"
                "\"opaqueData\": {"
                    "\"dataDescriptor\": \"COMMON.APPLE.INAPP.PAYMENT\","
                    "\"dataValue\": \"%@\""
                    "}"
                "},"
                "\"lineItems\": {"
                    "\"lineItem\": {"
                        "\"itemId\": \"1\","
                        "\"name\": \"Donation\","
                        "\"description\": \"Donation\","
                        "\"quantity\": \"1\","
                        "\"unitPrice\": \"0.01\""
                    "}"
                "}"
            "}"
        "}"
    "}", base64Encoded];
    
NSString *requestURI = @"https://apitest.authorize.net/xml/v1/request.api";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestURI]];
    [request setHTTPShouldHandleCookies:NO];
    [request setTimeoutInterval:60];
    request.HTTPMethod = @"Post";
    request.HTTPBody   = [body dataUsingEncoding:NSUTF8StringEncoding];
    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
      ^(NSData * _Nullable data,
        NSURLResponse * _Nullable response,
        NSError * _Nullable error) {
          
          NSString *responseStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
          NSLog(@"Data received: %@", responseStr);
      }] resume];
 
katie
Member
1 ACCEPTED SOLUTION

Accepted Solutions

Thanks Aaron!  I got it to work!

 

My Apple Merchant ID was correct, but I think there was something wrong with my certificates.  After re-generating my certificates I was able to get it to work.  Thanks for letting me know that the Apple Merchant ID is tied to decrypting the payment data - that was what tipped me off to start looking there.  

 

I still haven't been able to get the sandbox environment to work, but that is probably another certificate-related issue.  

 

The only other thing I needed to do to make the transaction go through was to add the "billTo" fields in the JSON.  

View solution in original post

5 REPLIES 5

A couple of things to look at:

 

  • The Apple Merchant ID that you enter into our site must be identical to the one that you created at the Apple site. If it is different, we will not be able to to decrypt the payment data. 
  • Must be an e-commerce transaction. Confirm that your gateway account is set up as a card-not-present account. 
  • The submitted data must be base64 encoded. As far as I can tell, you're doing that right, but double-check. I don't know if the BLOB you're getting back is already base64 encoded, but maybe double-check to make sure you're not double-encoding it.

Let me know if this helps at all, or if I'm completely off the mark.

Aaron
All Star

Thanks Aaron!  I got it to work!

 

My Apple Merchant ID was correct, but I think there was something wrong with my certificates.  After re-generating my certificates I was able to get it to work.  Thanks for letting me know that the Apple Merchant ID is tied to decrypting the payment data - that was what tipped me off to start looking there.  

 

I still haven't been able to get the sandbox environment to work, but that is probably another certificate-related issue.  

 

The only other thing I needed to do to make the transaction go through was to add the "billTo" fields in the JSON.  

I'm getting the following error:

Failed Transaction.
Error Code: 153
Error message: There was an error processing the payment data. Unable to decrypt data.

Your help is much appreciated.

 

And I'm sending the opaquedata.dataValue as the base64 encoded data that contains the version, data, signature, header(ephemeralPublicKey, publicKeyHash, transactionId).

We generated the token using apple pay and transaction is successful for sandbox environment.We used exactly the same process for token generation for live environment but we get the above error:

"Required fields are missing from decrypted data".In sandbox mode 

PKMerchantCapability.capability3DS works, while in live mode we get below error:

"This processor does not support this method of submitting payment data."

As mentioned in possible solutions for error codes,

Changing it to PKMerchantCapability.capabilityEMV does not help and gives the below response:

"Required fields are missing from decrypted data".We have set all possible values of 

PKPaymentRequest including shippingAddress,Billing contact,etc.Also ensured that merchant account is card not present & encrypted data belongs to merchant.

 

In live environment,we are setting location of device to US and using US credit card details.Device is located in India.

 

Sample Response:

 

{
"transactionResponse": {
"responseCode": "3",
"authCode": "",
"avsResultCode": "P",
"cvvResultCode": "",
"cavvResultCode": "",
"transId": "0",
"refTransID": "",
"transHash": "817E4EEE366139A5598A43F3CA026D41",
"testRequest": "0",
"accountNumber": "",
"accountType": "",
"errors": [
{
"errorCode": "153",
"errorText": "There was an error processing the payment data. Required fields are missing from decrypted data."
}
],
"userFields": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
],
"transHashSha2": "0F4059266DB96EC3DF32F9B4A39F61E3BF26FF67523C31A42FCBBABDC841D3719038BE788DD47BC5227A05042B1BA2198AD4A137A6926BBC39E2C171ED9176B6"
},
"refId": "123456",
"messages": {
"resultCode": "Error",
"message": [
{
"code": "E00027",
"text": "The transaction was unsuccessful."
}
]
}
}

 

 

Pragati
Member

Hi, did you figure this out? I haven't had any luck talking to them. I never got the transactions to work when i use discover card but there is no problem processing visa card. It is pretty strange and very similar to what you're experiencing.