Description | Link |
---|---|
Home | https://home.bluesnap.com |
Developer Hub | https://developers.bluesnap.com |
Authentication | https://developers.bluesnap.com/docs/authentication |
Payment API | https://developers.bluesnap.com/v8976-JSON/docs |
Contents:
- 1 Register for merchant account
- 2 Request API credentials
- 3 Client-Side encryption
- 4 Vaulted shopper
- 5 Purchase
- 6 Authorize
- 7 Capture
- 8 Void
- 9 Refund
Log in to developer console here.
If you don't have an account already, sign up for it here
On the dashboard, go to Settings > API Settings and fill out below form:
Click on "Request API Credentials".
Under API Credentials, note down Username, Password, and Default Store ID.
Under Client Side Encryption, note Client Side Encryption Key.
These will be used to make API requests later.
Add JavaScript file on HTML page:
= javascript_include_tag 'https://gateway.bluesnap.com/js/cse/v1.0.3/bluesnap.js'
In the payment form, set data-bluesnap
attribute on credit card fields which need to be encrypted. For each of those fields, a new hidden field will be created by BlueSnap with its name
attribute set to value of data-bluesnap
. See details here. You must do this for card number and security code (cvv) fields. For others, it is optional.
Add following JavaScript:
var blueSnap = new BlueSnap(<CLIENT_SIDE_ENCRYPTION_KEY>);
blueSnap.encrypt(<FORM_ID>);
Your fields have been encrypted. The encrypted values can now be used to make transactions on BlueSnap.
uri = URI('https://ws.bluesnap.com/services/2/vaulted-shoppers')
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
credentials = '<USERNAME>:<PASSWORD>'
authorization = "Basic #{Base64.encode64(credentials).strip}"
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/json'
request['Authorization'] = authorization
request.body = { paymentSources: {
creditCardInfo: [{
creditCard: {
expirationYear: 2020,
encryptedCardNumber: '$bs_card_number_enc=',
encryptedSecurityCode: '$bs_security_code_enc=',
expirationMonth: '09'
}
}]
},
firstName: 'Jagdeep',
lastName: 'Singh',
shopperCurrency: 'USD' }.to_json
response = http.request(request)
=> #<Net::HTTPOK 200 200 readbody=true>
response.code
=> "200"
JSON.parse response.body
=> => {"vaultedShopperId"=>12341111, "firstName"=>"Jagdeep", "lastName"=>"Singh", "softDescriptor"=>"BLS*TODO", "shopperCurrency"=>"USD", "paymentSources"=>{"creditCardInfo"=>[{"billingContactInfo"=>{"firstName"=>"Jagdeep", "lastName"=>"Singh"}, "creditCard"=>{"cardLastFourDigits"=>"1111", "cardType"=>"VISA", "cardSubType"=>"CREDIT", "expirationMonth"=>"09", "expirationYear"=>"2020"}, "processingInfo"=>{"cvvResponseCode"=>"ND", "avsResponseCodeZip"=>"U", "avsResponseCodeAddress"=>"U", "avsResponseCodeName"=>"U"}}]}}
In sandbox mode, replace https://ws.bluesnap.com with https://sandbox.bluesnap.com.
uri = URI('https://ws.bluesnap.com/services/2/transactions')
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/json'
request['Authorization'] = authorization
request.body = { amount: 19.99,
vaultedShopperId: 12341111,
recurringTransaction: 'ECOMMERCE',
currency: 'USD',
creditCard: {
cardLastFourDigits: 1111,
cardType: 'VISA'
},
cardTransactionType: 'AUTH_CAPTURE' }.to_json
response = http.request(request)
=> #<Net::HTTPOK 200 200 readbody=true>
JSON.parse response.body
=> {"cardTransactionType"=>"AUTH_CAPTURE", "transactionId"=>"1011011001", "recurringTransaction"=>"ECOMMERCE", "softDescriptor"=>"BLS*TODO", "amount"=>19.99, "currency"=>"USD", "vaultedShopperId"=>12341111, "creditCard"=>{"cardLastFourDigits"=>"1111", "cardType"=>"VISA", "cardSubType"=>"CREDIT"}, "processingInfo"=>{"processingStatus"=>"success", "avsResponseCodeZip"=>"U", "avsResponseCodeAddress"=>"U", "avsResponseCodeName"=>"U"}}
Use the code from purchase above. Only change is in the value of cardTransactionType
. Set it to "AUTH_ONLY" for authorize.
request.body = { amount: 19.99,
vaultedShopperId: 12341111,
recurringTransaction: 'ECOMMERCE',
currency: 'USD',
creditCard: {
cardLastFourDigits: 1111,
cardType: 'VISA'
},
cardTransactionType: 'AUTH_ONLY' }.to_json
uri = URI('https://ws.bluesnap.com/services/2/transactions')
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri)
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/json'
request['Authorization'] = authorization
request.body = { cardTransactionType: 'CAPTURE', transactionId: 1234511111 }.to_json
response = http.request(request)
=> #<Net::HTTPOK 200 200 readbody=true>
JSON.parse response.body
=> {"cardTransactionType"=>"CAPTURE", "transactionId"=>"1234511111", "recurringTransaction"=>"ECOMMERCE", "softDescriptor"=>"BLS*TODO", "amount"=>100.0, "openToCapture"=>0, "currency"=>"USD", "cardHolderInfo"=>{"firstName"=>"Jagdeep", "lastName"=>"Singh"}, "vaultedShopperId"=>12341111, "creditCard"=>{"cardLastFourDigits"=>"1111", "cardType"=>"VISA", "cardSubType"=>"CREDIT"}, "processingInfo"=>{"processingStatus"=>"SUCCESS", "avsResponseCodeZip"=>"U", "avsResponseCodeAddress"=>"U", "avsResponseCodeName"=>"U"}}
request.body = { cardTransactionType: 'CAPTURE', transactionId: 1234511111, amount: 19.99 }.to_json
response = http.request(request)
JSON.parse response.body
=> {"cardTransactionType"=>"CAPTURE", "transactionId"=>"1234511111", "recurringTransaction"=>"ECOMMERCE", "softDescriptor"=>"BLS*TODO", "amount"=>19.99, "openToCapture"=>80.01, "currency"=>"USD", "cardHolderInfo"=>{"firstName"=>"Jagdeep", "lastName"=>"Singh"}, "vaultedShopperId"=>12341111, "creditCard"=>{"cardLastFourDigits"=>"1111", "cardType"=>"VISA", "cardSubType"=>"CREDIT"}, "processingInfo"=>{"processingStatus"=>"SUCCESS", "avsResponseCodeZip"=>"U", "avsResponseCodeAddress"=>"U", "avsResponseCodeName"=>"U"}}
Same as capture but set cardTransactionType
to "AUTH_REVERSAL".
request.body = { cardTransactionType: 'AUTH_REVERSAL', transactionId: 1234511111 }.to_json
response = http.request(request)
JSON.parse response.body
=> {"cardTransactionType"=>"AUTH_REVERSAL", "transactionId"=>"1234511111", "recurringTransaction"=>"ECOMMERCE", "softDescriptor"=>"BLS*TODO", "amount"=>100.0, "openToCapture"=>100.0, "currency"=>"USD", "cardHolderInfo"=>{"firstName"=>"Jagdeep", "lastName"=>"Singh"}, "vaultedShopperId"=>12341111, "creditCard"=>{"cardLastFourDigits"=>"1111", "cardType"=>"VISA", "cardSubType"=>"CREDIT"}, "processingInfo"=>{"processingStatus"=>"SUCCESS", "avsResponseCodeZip"=>"U", "avsResponseCodeAddress"=>"U", "avsResponseCodeName"=>"U"}}
uri = URI('https://ws.bluesnap.com/services/2/transactions/1234511111/refund')
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri)
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/json'
request['Authorization'] = authorization
request.body = {}.to_json
response = http.request(request)
=> #<Net::HTTPNoContent 204 204 readbody=true>
response.body
=> nil
To refund a partial amount, pass it in query string as below:
uri = URI('https://ws.bluesnap.com/services/2/transactions/1234511111/refund?amount=19.99')
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri)
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/json'
request['Authorization'] = authorization
response = http.request(request)
=> #<Net::HTTPNoContent 204 204 readbody=true>