A Ruby API client that interfaces with card connect's REST api for credit card payment processing.
config/initializers/card_connect_gateway.rb
CardConnectGateway.configure do |config|
config.test_mode = true
config.merchant_id = ENV["CARD_CONNECT_MERCHANT_ID"]
config.user_id = ENV['CARD_CONNECT_USER_ID']
config.password = ENV['CARD_CONNECT_PASSWORD']
config.debug = true
config.require_avs_zip_code_match = true
config.require_avs_address_match = false
config.require_avs_customer_name_match = false
config.supported_card_types = [
CardConnectGateway::Base::VISA,
CardConnectGateway::Base::MASTERCARD,
CardConnectGateway::Base::AMEX,
CardConnectGateway::Base::DISCOVER,
CardConnectGateway::Base::MAESTRO,
CardConnectGateway::Base::DINERS_CLUB,
CardConnectGateway::Base::JCB
]
endsetup ajax tokenizer (if using)
<script type="text/javascript">
CARDCONNECT_AJAX_URL = CardConnectGateway.configuration.ajax_url
</script>auth = CardConnectGateway.authorization({
account: '4788250000121443',
expiry: '0921',
cvv2: '112',
postal: '19406'
})
auth.valid?
# => true
auth = CardConnectGateway.authorization({
account: '5454545454545454',
expiry: '0921',
cvv2: '112',
amount: 20,
postal: '19111'
})
auth.valid?
auth.errors
# => {:postal=>"doesn't match."}
auth.card_type
# => "MasterCard" NOTE: if authorizing from a token you must fill in card_type as well
# create
response = CardConnectGateway.create_profile({
account: '4788250000121443',
expiry: '0921'
})
response.valid?
# => true
# update
response2 = CardConnectGateway.update_profile({
account: '5454545454545454',
expiry_month: 9,
expiry_year: 10,
profile: response.profileid
})
response.valid?
# => trueauth = CardConnectGateway.authorization({
account: '4788250000121443',
expiry: '0921',
cvv2: '112',
postal: '19406'
capture: true,
amount: 20
})
void = CardConnectGateway.void({
retref: auth.retref
})
void.valid?
# => trueauth = CardConnectGateway.authorization({
account: '4788250000121443',
expiry: '0921',
cvv2: '112',
postal: '19406'
capture: true,
amount: 20
})
refund = CardConnectGateway.refund({
retref: auth.retref
})
refund.valid?
# can't actually process one of these because you have to wait 24 hours
refund.errors
# => {PPS: "Txn not settled"}auth = CardConnectGateway.authorization({
account: '4788250000121443',
expiry: '0921',
cvv2: '112',
postal: '19406',
amount: 20
})
capture = CardConnectGateway.capture({
retref: auth.retref,
amount: 5
})
capture.valid?
# => true app/assets/javascripts/application.js.coffee.erb
#= require ajax_tokenizer
Wantable = angular.module('Wantable', [ 'cardConnect'])
Wantable.controller 'CreditCardController', (ajaxTokenizer) ->
ajaxTokenizer.tokenize('4788250000121443').then((tokenizedCard) ->
# tokenizedCard =>
)
first install grunt
$ npm install -g grunt-cli
$ npm install grunt-contrib-coffee --save-dev
$ npm install grunt-contrib-watch --save-dev
then tell grunt to watch coffeescript files and rebuild them as they are changed with $ grunt watch
to force a coffeescript build call $ grunt coffee
rspec
$ CARD_CONNECT_MERCHANT_ID=[MERCHANT_ID] CARD_CONNECT_USER_ID=[USER_ID] CARD_CONNECT_PASSWORD=[PASSWORD] rake test
....
Finished in 0.00142 seconds (files took 0.09582 seconds to load)
4 examples, 0 failures
jasmine
$ rake jasmine and visit localhost:8888
If you're doing international payments you have to set the country on authorize. Otherwise it defaults to US.