Skip to content

Instantly share code, notes, and snippets.

@thzinc
Created February 21, 2015 01:17
Show Gist options
  • Save thzinc/38afbb1ad272ca95af10 to your computer and use it in GitHub Desktop.
Save thzinc/38afbb1ad272ca95af10 to your computer and use it in GitHub Desktop.
Test Spreedly Gateway
#!/bin/bash
ENVIRONMENT_KEY=Spreedly_Environment_Key
SECRET=Spreedly_Secret
GATEWAY=Spreedly_Gateway_Token
echo Tokenize request
curl https://core.spreedly.com/v1/payment_methods.json\?environment_key=$ENVIRONMENT_KEY \
-H 'Origin: http://localhost' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Content-Type: application/json' \
-s \
-d '{
"payment_method":{
"credit_card":{
"first_name": "Purchaser",
"last_name": "McPurchason",
"number": "4111111111111111",
"verification_value": "111",
"month":"9",
"year":"2027"
}
}
}' | jq . > tokenize.response
PAYMENT_METHOD_TOKEN=$(cat tokenize.response | jq -r -M .transaction.payment_method.token)
echo Tokenize response
echo $PAYMENT_METHOD_TOKEN
AUTHORIZE_REQUEST=$(echo '<transaction>
<payment_method_token>PAYMENT_METHOD_TOKEN</payment_method_token>
<amount>103</amount>
<currency_code>USD</currency_code>
</transaction>' | sed "s/PAYMENT_METHOD_TOKEN/${PAYMENT_METHOD_TOKEN%%[[:space:]]}/g")
echo Authorize request
curl https://core.spreedly.com/v1/gateways/$GATEWAY/authorize.xml \
-u "$ENVIRONMENT_KEY:$SECRET" \
-H 'Content-Type: application/xml' \
-s \
-d "$AUTHORIZE_REQUEST" | xml fo > authorize.response
AUTHORIZE_TRANSACTION_TOKEN=$(cat authorize.response | xml sel -t -v '/transaction/token')
echo Authorize response
cat authorize.response
echo Capture request
curl https://core.spreedly.com/v1/transactions/$AUTHORIZE_TRANSACTION_TOKEN/capture.xml \
-u "$ENVIRONMENT_KEY:$SECRET" \
-H 'Content-Type: application/xml' \
-s \
-d '' | xml fo > capture.response
CAPTURE_TRANSACTION_TOKEN=$(cat capture.response | xml sel -t -v '/transaction/token')
echo Capture response
cat capture.response
echo Void request
curl https://core.spreedly.com/v1/transactions/$CAPTURE_TRANSACTION_TOKEN/void.xml \
-u "$ENVIRONMENT_KEY:$SECRET" \
-H 'Content-Type: application/xml' \
-s \
-d '' | xml fo > void.response
VOID_TRANSACTION_TOKEN=$(cat void.response | xml sel -t -v '/transaction/token')
echo Void response
cat void.response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment