API: Process Encrypted Card Payments through MercuryPay
Communicate with MercuryPay servers to process secure, end-to-end encrypted credit card transactions using an IDTech Shuttle or Magtek iDynamo card reader correctly keyed to MercuryPay's servers.
Requirements
- Integration of our JavaScript API into your webpage
- Sample code to run within the app and download for integration into your own project is available here.
- Best practices for working with the JavaScript API are available here.
- App Settings
- Content > JavaScript API > Access JavaScript API > By Import
- Peripherals & Integrations > Card Readers & Payments
- Card Reader Type = "ID Tech Shuttle or UniMag II" or "MagTek iDynamo"
- Enable MercuryPay > On
- Merchant ID = set
- Web Services Password = set
- Physical Hardware
- An IDTech Shuttle or Magtek iDynamo card reader, keyed to MercuryPay's servers.
Triggers via API Functions
kp_UniMag2CardReader_mps_doCreditSaleOperation & kp_iDynamoCardReader_mps_doCreditSaleOperation
This is the primary method of the MercuryPay API, performing all steps of processing of a credit-sale operation: requesting card reader swipe, reading card data, sending request to MercuryPay, processing response, and (if configured) printing a standard receipt when the operation is finished successfully.
UniMag2 Format | kp_UniMag2CardReader_mps_doCreditSaleOperation(amount, invoiceNumber); |
iDynamo Format | kp_iDynamoCardReader_mps_doCreditSaleOperation(amount, invoiceNumber); |
Parameters |
|
amount
Kiosk Pro will try to convert this string value to the equivalent float value. If this conversion fails or result is less than or equal to zero, then Kiosk Pro will cancel the operation at this point. To prevent any issues, please make sure that the value is formatted as a number with two decimal places and without any currency sign - for example, '0.01' for a $0.01 transaction.
invoiceNumber
In most instances, this value should be empty - this means that your code would like to initiate a NEW credit-sale operation and Kiosk Pro should generate a new unique value for the invoice number.
If this value is not empty, then Kiosk Pro assumes that your code would like to RESEND a previously-processed credit-sale operation to return the real status of that operation. In both cases, Kiosk Pro will first request card reader swipe to read card data. Next, Kiosk Pro will try to find registered operation (in its local database) using parameters: amount, invoiceNumber and cardData; if Kiosk Pro cannot find the operation, it will then return the request as FAILED.
Important: Your code should only resend a previously processed operation during the same operation day. Once the time-based batching is intiated closing the batch for that operation day, all invoice numbers are reset and it is no longer possible to rely on MercuryPay's duplicate processing prevention logic to prevent a double-charge to the card.
kp_MercuryPaySystem_generateFullReportToFile
This method allows you to generate a full report about all credit-sale operations during an entire session of Kiosk Pro. The report is formatted as a .csv file with the following sections:
Column Name | Description |
Transaction Input Data | |
---|---|
swipeDate | Swipe Date and Time in UTC format. Example: 2013-03-27 14:10:55 +0000 |
invoiceNo | Invoice Number. Example: 8000000001 |
amount | Amount. The value is formatted as a number with two decimal places without any currency sign - for example, '0.01' for a $0.01 transaction. |
account_number | Account Number. Only a partial card number is saved and shown for security reasons. Example: 400300******6781 |
card_holder_name | Card Holder Name. Example: TEST/MPS |
exp_date | Expiration Date. Example: 1512 |
merchantID | Merchant ID. Example: 395347305=E2E |
operatorID | Operator ID. As noted previously, this will match the Unique Kiosk ID in Kiosk Pro settings. Example: Kiosk |
memo | Memo. Example: KPE Connect v.3.1.1691 |
Communication with ONE MercuryPay Server Info | |
serverURL | The URL of MercuryPay Server. Primary Server: https://w1.mercurypay.com/ws/ws.asmx or Secondary Server: https://w2.backuppay.com/ws/ws.asmx |
sentDate | Request Sent Date and Time in UTC format. Example: 2013-03-27 14:11:00 +0000. |
receivedDate | Response Date and Time in UTC format. Example: 2013-03-27 14:11:03 +0000. Can be empty. One of the reason of this means that Kiosk Pro was terminated before finish of the transaction. |
Communication Error | |
errorDomain | If a communication error occured while attempting the request, this column will contain the name of the error domain (most frequently this will be NSURLErrorDomain). Can be empty. |
errorCode | If a communication error occured while attempting the request, this column will contain an error code as reported as integer. Example: -1001 (means timeout). Can be empty or equal to 0. |
Cmd Response | |
responseOrigin | Response Origin. Example: Processor. Please see 'Mercury Platform Integration Specifications.pdf'. |
dsixReturnCode | DSIXReturnCode. Example: 000000. Please see 'Mercury Platform Integration Specifications.pdf'. |
cmdStatus | CmdStatus. Example: Declined. Please see 'Mercury Platform Integration Specifications.pdf'. |
textResponse | TextResponse. Example: DECLINE. Please see 'Mercury Platform Integration Specifications.pdf'. |
Tran Response | |
cardType | CardType. Example: VISA. Please see 'Mercury Platform Integration Specifications.pdf'. |
captureStatus | CaptureStatus. Please see 'Mercury Platform Integration Specifications.pdf'. Can be empty. |
refNo | RefNo. Example: 8000000004. Please see 'Mercury Platform Integration Specifications.pdf'. |
amount | Result Amount. The value is formatted as a number with two decimal places without any currency sign - for example, '0.01' for a $0.01 transaction. Potentialy this value can differ from Amount in the section 'Transaction Input Data'. |
authCode | AuthCode. Please see 'Mercury Platform Integration Specifications.pdf'. Can be empty. |
Please note, each record in the report file reflects information about interaction with a single MercuryPay server. If during a transaction the primary MercuryPay Server did not respond and Kiosk Pro resends request to the secondary MercuryPay Server, details of this second interaction will be saved as a second entry.
The following types of records in the .csv report are possible:
- The section: 'Transaction Input Data' is not empty and other sections are empty. This means that Kiosk Pro successfully register transaction and then Kiosk Pro was terminated for any reason (by visitor or because of unhandled exception) before being sent. This means that the transaction has NOT left the iPad and no communication has taken place with Mercury's servers. No transaction has been attempted and the visitor's card has not been charged. Please note section 'Transaction Input Data' is not always empty.
- The section: 'Communication with ONE MercuryPay Server Info' has empty 'receivedDate'. In this instance, the transaction has LEFT the iPad, but Kiosk Pro was terminated for any reason (by visitor or because of unhandled exception) before the response was received. In this case, we don't know the final status of the transaction and recommend resending the request to MercuryPay with the same amount, card and invoice number.
- The section: 'Communication Error' is not empty. This means that transaction has LEFT iPad, but communication error has occured. If the next record (with the same 'Transaction Input Data') exists and it has non empty 'Cmd Response' section, then you know the final status of the transaction. But if the next record contains non-empty section 'Communication Error', it means that we don't know the final status of the transaction.
- The section: 'Cmd Response' is not empty. Please note that the sections 'Communication Error' and 'Cmd Response' are mutually exclusive. Based on info in this section, you know the final status of the transaction.
- The section: 'Tran Response' is not empty. It's an additional section which appears only if the section 'Cmd Response' is presented. Please see 'Mercury Platform Integration Specifications.pdf' for more information about fields in this section.
Format | kp_MercuryPaySystem_generateFullReportToFile(fileName, callback); |
Parameters |
|
Callback format | callback(success); |
Callback return values | 1 = report was generated successfully. |
kp_MercuryPaySystem_getSettings()
This function returns Kiosk Pro's current MercuryPay settings.
Format | kp_MercuryPaySystem_getSettings(); |
Status
Kiosk Pro will immediately call: kp_MercuryPaySystem_getSettingsDidFinishWithData() and pass the current MercuryPay settings values defined in Kiosk Pro settings.
Notifications via API Callbacks
- kp_MercuryPaySystem_getSettingsDidFinishWithData
- kp_MercuryPaySystem_requestLastRegisteredOperation
- kp_MercuryPaySystem_creditSaleOperationWillRunStep
- kp_MercuryPaySystem_communicationDidNotStartWithError
- kp_MercuryPaySystem_communicationDidFailWithErrors
- kp_MercuryPaySystem_communicationDidFinishWithResponse
- kp_MercuryPaySystem_printReceiptDidFailWithError
- kp_MercuryPaySystem_printReceiptDidFinishWithStatus
- kp_MercuryPaySystem_requestLastOperationDidFailWithError
- kp_MercuryPaySystem_requestLastOperationDidFinishWithData
kp_MercuryPaySystem_getSettingsDidFinishWithData
This callback returns values of all major MercuryPay parameters.
Format | kp_MercuryPaySystem_getSettingsDidFinishWithData(cardReaderType, enabled, connectionState, mid, operatorID, memo, responseTimeOut, uniqueKioskNumber, printReceipt); |
Return values |
|
kp_MercuryPaySystem_requestLastRegisteredOperation
This method allows to get info about last registered operation. For our purposes, 'registered' means that operation was saved in the local database.
There are 4 possible cases:
- No operations were registered.
- Last operation has communication error.
- Last operation was without error and response.
- Operation with MercuryPay response.
Format | kp_MercuryPaySystem_requestLastRegisteredOperation(); |
creditSaleOperationWillRunStep
This callback informs your code where Kiosk Pro is in the process of performing the credit-sale operation.
Format | kp_UniMag2CardReader_creditSaleOperationWillRunStep(stepId); kp_iDynamoCardReader_creditSaleOperationWillRunStep(stepId); |
Return values |
|
communicationDidNotStartWithError
This callback is triggered when error occurs before sending request to the MercuryPay.
If this error is returned, no communication has taken place with Mercury's servers. No transaction has been attempted and the visitor's card has not been charged.
Format | kp_UniMag2CardReader_communicationDidNotStartWithError(errorDictionary, requestDataDictionary); kp_iDynamoCardReader_communicationDidNotStartWithError(errorDictionary, requestDataDictionary); |
Return values |
|
communicationDidFailWithErrors
This callback is triggered when an error occurs while sending a request to MercuryPay.
Kiosk Pro implements failover logic - if connection with the primary MercuryPay Server fails, then Kiosk Pro tries to resend request to the secondary MercuryPay Server. The probability of this error is low.
Important: If you see this callback, it means that Kiosk Pro does not know the status of the transaction. In this case, we recommend relying on MercuryPay's duplicate charge prevention logic and sending the credit-sale operation again (with the same card, amount and invoice number). If the charge was previously made, Mercury's servers will recognize this and return the code 'AP*'; if not, Mercury will process the charge and return the result as normal.
Format | kp_UniMag2CardReader_communicationDidFailWithErrors(listOfErrorDictionaries, requestDataDictionary); kp_iDynamoCardReader_communicationDidFailWithErrors(listOfErrorDictionaries, requestDataDictionary); |
Return values |
|
communicationDidFinishWithResponse
This callback is triggered when credit-sale operation is finished. In general, this operation returns either "Accepted" or "Declined", but may give other messages detailed below.
Format | kp_UniMag2CardReader_communicationDidFinishWithResponse(requestDataDictionary, cmdResponseDictionary, tranResponseDictionary, willStartPrintReceipt); kp_iDynamoCardReader_communicationDidFinishWithResponse(requestDataDictionary, cmdResponseDictionary, tranResponseDictionary, willStartPrintReceipt); |
Return values |
|
printReceiptDidFailWithError
This callback is triggered when print receipt is failed.
Currently Kiosk Pro supports automatic receipt printing for MercuryPay only on supported Star thermal kiosk printers.
Format | kp_UniMag2CardReader_printReceiptDidFailWithError(errorDictionary); kp_iDynamoCardReader_printReceiptDidFailWithError(errorDictionary); |
Return values | errorDictionary = error as associate array. For example: {'domain':'MPSReceiptPrintingErrorDomain', 'code':2, 'url':null, 'description':'Fail to open port.'}. Only one possible error domain: MPSReceiptPrintingErrorDomain. Value for key: 'url' is always null. |
printReceiptDidFinishWithStatus
This callback is triggered when print receipt is finished.
Currently Kiosk Pro supports automatic receipt printing for MercuryPay only on supported Star thermal kiosk printers.
Format | kp_UniMag2CardReader_printReceiptDidFinishWithStatus(overTemp, unrecoverableError, cutterError, mechError, headThermistorError, receiveBufferOverflow, pageModeCmdError, blackMarkError, presenterPaperJamError, headUpError, voltageError, receiptBlackMarkDetection, receiptPaperEmpty, receiptPaperNearEmptyInner, receiptPaperNearEmptyOuter); kp_iDynamoCardReader_printReceiptDidFinishWithStatus(overTemp, unrecoverableError, cutterError, mechError, headThermistorError, receiveBufferOverflow, pageModeCmdError, blackMarkError, presenterPaperJamError, headUpError, voltageError, receiptBlackMarkDetection, receiptPaperEmpty, receiptPaperNearEmptyInner, receiptPaperNearEmptyOuter); |
Return values |
|
requestLastOperationDidFailWithError
This callback is triggered when last operation can't be extracted.
Format | kp_UniMag2CardReader_requestLastOperationDidFailWithError(errorDictionary); kp_iDynamoCardReader_requestLastOperationDidFailWithError(errorDictionary); |
Return values |
|
requestLastOperationDidFinishWithData
This callback is triggered when request last registered operation is finished. Parameters give more information about the last registered transaction.
For more information about specific transaction responses returned by Mercury's servers, please check page 16 in the 'Mercury Platform Integration Specifications.pdf' or contact your Mercury representative.
Format | kp_UniMag2CardReader_requestLastOperationDidFinishWithData(requestDataDictionary, listOfErrorDictionaries, cmdResponseDictionary, tranResponseDictionary); kp_iDynamoCardReader_requestLastOperationDidFinishWithData(requestDataDictionary, listOfErrorDictionaries, cmdResponseDictionary, tranResponseDictionary); |
Return values |
|
Errors
MPSStartCommunicationErrorDomain
Code | Description | Troubleshooting |
High level enabling/disabling | ||
---|---|---|
1 | Communication with MercuryPay is disabled in Kiosk Pro. | Please check that Card Reader Type = "IDTech UniMagII or Shuttle" or "MagTek iDynamo". |
2 | Appropriate Card Reader is disabled in Kiosk Pro. | Please check that Enable MercuryPay = On. |
Swipe errors | ||
9 | Card Reader is disconnected. | Please unplug and reconnect the Shuttle reader, making sure it is firmly seated in the audio jack and the volume is at the maximum possible level. |
10 | Swipe is already in progress. | This error is seen when the visitor and/or your code attempts to start a new credit-sale operation during swiping. Please complete the current operation and then attempt a new credit-sale operation. |
11 | Card reader was disconnected during swipe. | Please unplug and reconnect the Shuttle reader, making sure it is firmly seated in the audio jack and the volume is at the maximum possible level. |
12 | Swipe timeout is reached. | This error is seen when the visitor does nothing during swipe period or a card reader did not see any manipulation with card. Please check that the card is being swiped correctly. |
13 | Bad swipe. Please try again. | Card reader could not read data from card. Please repeat swipe. |
14 | Swipe is cancelled. | The 'Cancel' button was touched - accidentally or not. |
Card data parse errors | ||
30 | Encrypted block is empty. | Possible causes: card does not have encrypted information available of track 2 or Kiosk Pro has error in parsing procedure for this type of card. Please repeat swipe again and if it does not help, please contact our support. Be prepared to provide mps log file. |
31 | Encrypted key is empty. | Possible causes: card does not have encrypted KSN or Kiosk Pro has error in parsing procedure for this type of card. Please repeat swipe again and if it does not help, please contact our support. Be prepared to provide mps log file. |
32 | Account number is empty. | Possible causes: card does not have Account number or Kiosk Pro has error in parsing procedure for this type of card. Please repeat swipe again and if it does not help, please contact our support. Be prepared to provide mps log file. |
Invalid Request Data errors | ||
50 | Request amount is not a valid number. | Check that your code is passing the correct request amount to Kiosk Pro. Please note that Kiosk Pro expects a properly-formatted string. |
51 | Request amount is less than or equal to zero. | Your code is passing an invalid potential transaction amount. Check that your code is passing the correct request amount to Kiosk Pro. Please note that Kiosk Pro expects a properly-formatted string. |
52 | Request amount exceeded possible maximum. | Your code is passing an invalid potential transaction amount. Check that your code is passing the correct request amount to Kiosk Pro. Please note that Kiosk Pro expects a properly-formatted string that is less than the MAXFLOAT value of 0x1.fffffep+127f (which is roughly 1.99999999999999999999998 times 2^127). This value is checked prior to sending the request to Mercury's servers and is likely to be larger than the maximum possible transaction amount determined by Mercury for each individual merchant; for more information on these limits for your account, please contact your MercuryPay representative. |
Resend errors | ||
100 | Can not find registered operation with such invoice number and amount during operation day. | This error is seen when the visitor attempts to resend a previously registered operation, but Kiosk Pro could not find this operation in the local database with specified invoice number and amount and card data during the current operation day or your operation parameters are incorrect or such operation does not exist. |
Invoice number management errors | ||
150 | Internal error: can not update invoice number. | Kiosk Pro's local database is broken or your iPad does not have enough space to perform save operation. Be sure you have enough space and if that is not the issue, then please stop work with Kiosk Pro and call our support. |
151 | Invoice number exceeded possible maximum. | As the app resets invoice numbers once a day, this should not be an issue. If you do see this error, you should wait until the finish of operation day or try to change the Unique KPE Number setting, but be careful with this to avoid overlapping. |
Register errors | ||
200 | Internal error: can not register credit operation. | The Kiosk Pro's local database is broken or your iPad does not have enough space to perform save operation. Be sure you have enough space and if that is not the issue, then please stop work with Kiosk Pro and call our support. |
MPSConnectionFatalErrorDomain
Code | Description | Troubleshooting |
---|---|---|
1 | Network is not available. | Kiosk Pro detected that there is no connection with which to communicate with Mercury's servers. Please check Your connection to the Internet. |
2 | Can not create connection. | This error means that iOS can't create URL-connection. This can happen if a lot of connections were created or by some other reasons that Apple does not define, but is a rare error. Please try resend transaction again later or terminate Kiosk Pro and try again later. |
MPSBackEndCommunicationErrorDomain
Code | Description | Troubleshooting |
---|---|---|
1 | Mercury did not get a response from the processing back end networks. | This error is seen when the no response is received from the Mercury server. When this happens, Kiosk Pro will automatically failover, sending the request to the secondary backup server. While the possibility of both Mercury servers being down does exist, the probability of this occurring is very, very low; if it does happen, please contact MercuryPay support directly. |
2 | Can not parse response. It is possible that the wrong server is being used. | Kiosk Pro received response from MercuryPay server, but could not parse this response successfully. If you are using a new version of Kiosk Pro or have changed any .plist settings within the Kiosk Pro app, please contact Kiosk Pro support team to check the server URL's that your request is being submitted to. If this request is being submitted to the correct server URLs, this means that Kiosk Pro has issue in the parsing procedure or the format of the response has been changed. |
MPSReceiptPrintingErrorDomain
Code | Description | Troubleshooting |
---|---|---|
1 | Internal error: can not find print data. | This is an internal error which means that Kiosk Pro could not find print data for receipt. In this case, check to make sure the 'Print Receipt' settings contain valid entries and if that doesn't help, contact Kiosk Pro support. |
2 | Fail to open port. | This means that the local network is disconnected or network printer port address ("tcp:nnn.nnn.nnn.nnn") is wrong. Please check connection and/or network printer port address. |
3 | Write port timeout. | With high probability, this means that during printing the Star printer was somehow disconnected. Please check the Star printer. |
Sample Code
- This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.
- To run sample code, set the app's homepage to kioskgroup.com/mercury-pay-api
- To download a .zip of sample code, click here.
Change Log
- Added in 3.3 version.