Skip to content

shift4developer/shift4-ruby

Repository files navigation

Shift4 ruby gem

Build Gem Version

If you don't already have Shift4 account you can create it here.

Installation

Add this line to your application's Gemfile:

gem 'shift4'

And then execute:

bundle

Or install it yourself as:

gem install shift4

Usage

Configuration:

Shift4::Configuration.secret_key = 'pr_test_id'

If you want connect to different backend:

Shift4::Configuration.api_url = 'https://api.myshift4.env'
Shift4::Configuration.uploads_url = 'https://uploads.myshift4.env'

Examples

Create a new Card

Creates a new card object.

customer_id = 'cust_id'
card = {
  number: '4242424242424242',
  expMonth: '11',
  expYear: '2022',
  cvc: '123',
  cardholderName: 'John Doe',
}

Shift4::Cards.create(customer_id, card)

Retrieve an existing Card

Retrieve an existing card object.

customer_id = 'cust_id'
card_id = 'card_id'

Shift4::Cards.retrieve(customer_id, card_id)

Update an existing Card

Update an existing card object.

customer_id = 'cust_id'
card_id = 'card_id'
card = {
  cardholderName: 'Mr Bean'
}
Shift4::Cards.update(customer_id, card_id, card)

Delete a Card

Deletes an existing card object.

customer_id = 'cust_id'
card_id = 'card_id'
Shift4::Cards.delete(customer_id, card_id)

List Cards

List card objects for given customer.

customer_id = 'cust_id'
Shift4::Cards.list(customer_id)

Create a Blacklist Rule

blacklist_rule = {
  ruleType: 'fingerprint',
  fingerprint: '123abc456efg'
}
Shift4::Blacklist.create(blacklist_rule)

Retrieve an existing Blacklist Rule

blacklist_rule_id = 'blr_number'
Shift4::Blacklist.retrieve(blacklist_rule_id)

Delete a Blacklist Rule

blacklist_rule_id = 'blr_number'
Shift4::Blacklist.delete(blacklist_rule_id)

List Blacklist Rules

Shift4::Blacklist.list(deleted: true, limit: 100)

API reference

Please refer to detailed API docs (linked) for all available fields

For further information, please refer to our official documentation at https://dev.shift4.com/docs.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/shift4developer/shift4-ruby

Development

After checking out the repo, run bundle setup to install dependencies.

To run integration tests:

SECRET_KEY='sk_test_id' bundle exec rake spec:integration

To run style checks execute:

bundle exec rubocop