Created
February 9, 2017 19:08
-
-
Save kheast/673f8a434200d57bfb33c9e631d19d56 to your computer and use it in GitHub Desktop.
bash script to submit credit card transaction to First Data Global Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Code to submit a credit card transaction to First Data Global | |
# Gateway for processing. Shows the bare minimum necessary to process | |
# a transaction. Handy to verify validity of credentials and XML. | |
# Primarily intended to process transactions against FDGG test | |
# endpoint, but it will happily process live transactions against | |
# the FDGG secure endpoint, charging a real credit card for the | |
# specified amount. | |
ENDPT_TEST=https://staging.linkpt.net:1129/LSGSXML # Testing endpoint | |
ENDPT_LIVE=https://secure.linkpt.net:1129/LSGSXML # Live endpoint | |
# Requires that one already have an account with First Data | |
# and the requisite security credentials they supply. | |
# To use this script: | |
# 1) Place FDGG credentials (PEM file) in ./certs | |
# 2) Define transaction to process in ./process_fdgg.tx | |
# 3) Confirm TX_ENDPT is correct for intended use (i.e., test vs. live) | |
# 4) Run script and confirm results | |
# The file ./process_fdgg.tx contains bash environment variables | |
# defining the transaction to process. Uncomment the following | |
# lines and use them as a starting point for your process_fdgg.tx. | |
# | |
# TX_ENDPT="${ENDPT_TEST}" # Or use "${ENDPT_LIVE}" | |
# TX_STORE=1909839424 | |
# TX_AMOUNT="1.00" | |
# TX_ZIP="10050" | |
# TX_NAME="Bill Smith" | |
# TX_ADDR="111 Congress Ave." | |
# TX_ADDN="111" | |
# TX_CITY="Austin" | |
# TX_CARD_NUM="4111111111111111" | |
# TX_CARD_MM="04" | |
# TX_CARD_YY="25" | |
# TX_CARD_CVM="111" | |
# Only arg is optional config file location. | |
TXCONF="$1" | |
if [ ! -f "${TXCONF}" ] | |
then | |
TXCONF="./process_fdgg.tx" | |
fi | |
. "${TXCONF}" | |
# Note: See the CTE Response Code documentation for info on how | |
# AMOUNT and ZIP values affect the response from the gateway when | |
# running against the test endpoint. | |
# https://www.firstdata.com/downloads/marketing-merchant/ffd-cte-v2.pdf | |
VERBOSE="--verbose" # Uncomment for verbose/pretty output | |
DEBUG="--debug" # Uncomment for debug output from wget | |
# export https_proxy=127.0.0.1:8888 # Uncomment if using Charles Proxy | |
CERT=./certs/${TX_STORE}.pem # credentials | |
if [ ! -f "${CERT}" ] | |
then | |
echo "Error: ${CERT} does not exist." | |
exit 1 | |
fi | |
# Simulate a transaction ID | |
TXID=TXID-`date +%s` | |
# XML for the transaction. | |
PURCHASE_SINGLE=" | |
<order> | |
<orderoptions> | |
<ordertype>SALE</ordertype> | |
<result>LIVE</result> | |
</orderoptions> | |
<creditcard> | |
<cardnumber>${TX_CARD_NUM}</cardnumber> | |
<cardexpmonth>${TX_CARD_MM}</cardexpmonth> | |
<cardexpyear>${TX_CARD_YY}</cardexpyear> | |
<cvmvalue>${TX_CARD_CVM}</cvmvalue> | |
<cvmindicator>provided</cvmindicator> | |
</creditcard> | |
<billing> | |
<name> | |
<![CDATA[${TX_NAME}]]> | |
</name> | |
<address1> | |
<![CDATA[${TX_ADDR}]]> | |
</address1> | |
<city>Austin</city> | |
<state>TX</state> | |
<zip>${TX_ZIP}</zip> | |
<country>USA</country> | |
<addrnum>${TX_ADDN}</addrnum> | |
</billing> | |
<shipping></shipping> | |
<transactiondetails> | |
<oid>${TXID}</oid> | |
<terminaltype>unspecified</terminaltype> | |
</transactiondetails> | |
<merchantinfo> | |
<configfile>${TX_STORE}</configfile> | |
<keyfile>${CERT}</keyfile> | |
<host>staging.linkpt.net</host> | |
<port>1129</port> | |
</merchantinfo> | |
<payment> | |
<chargetotal>${TX_AMOUNT}</chargetotal> | |
</payment> | |
</order>" | |
# 'curl' was used previously, both here and in production code. In OS-X 10.10 (devel env), | |
# curl stopped using NSS for TLS/SSL support and started using Apple's 'Secure Transport'. | |
# When this happened, curl on OS-X would no longer accept pem files. | |
# To address the problem, this was changed to use wget, which is happy with pem. | |
purchase () | |
{ | |
RESP=`wget ${DEBUG} ${VERBOSE} --certificate="${CERT}" -O - --post-data="$*" ${TX_ENDPT}` | |
RC=$? | |
if [ $RC != 0 ] | |
then | |
echo "wget error = $RC" | |
else | |
echo "wget success" | |
fi | |
if [ ! -z "${VERBOSE}" ] | |
then | |
echo "===========================================================================" | |
echo "XML for Transaction" | |
echo "===========================================================================" | |
echo "$*" | tidy -xml -i -q | |
echo | |
echo "===========================================================================" | |
echo "FDGG Response" | |
echo "===========================================================================" | |
echo "$RESP" | tidy -xml -i -q | |
else | |
echo $RESP | |
fi | |
} | |
purchase $PURCHASE_SINGLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment