Code Monkey home page Code Monkey logo

adyen-cse-ruby's Introduction

Gem Version Build Status

Adyen CSE for Ruby

Adyen's Client Side Encryption (CSE) library for Ruby.

This is a port of Adyen's Android CSE library, packaged as a Ruby gem.

Check out the Python version here.

Installation

Add this line to your application's Gemfile:

gem 'adyen-cse-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install adyen-cse-ruby

Usage

require 'adyen_cse'

cse = AdyenCse::Encrypter.new(public_key)

encrypted_card = cse.encrypt!(
  holder_name: "Adyen Shopper",
  number: 4111_1111_1111_1111.to_s,
  expiry_month: "08",
  expiry_year: "2018",
  cvc: "737"
)

Optionally, you may pass a custom generation_time to mock expired data.

encrypted_card = cse.encrypt!(
  ...,
  generation_time: Time.new(2015, 10, 21)
)

factory_bot integration

Example of an :adyen_test_card factory with factory_bot.

# ./spec/factories/adyen_test_card.rb

require 'adyen_cse'

class AdyenTestCard
  attr_reader :holder_name, :number, :expiry_month, :expiry_year, :cvc

  PUBLIC_KEY = "your_public_key_here"

  def initialize(params = {})
    @holder_name  = params[:holder_name]
    @number       = params[:number]
    @expiry_month = params[:expiry_month]
    @expiry_year  = params[:expiry_year]
    @cvc          = params[:cvc]
  end

  def nonce
    AdyenCse::Encrypter.new(PUBLIC_KEY).encrypt!(
      holder_name: holder_name,
      number: number,
      expiry_month: expiry_month,
      expiry_year: expiry_year,
      cvc: cvc
    )
  end
end

FactoryBot.define do
  factory :adyen_test_card do
    sequence(:holder_name) { |n| "Shopper #{n}" }
    expiry_month { '08' }
    expiry_year { '2018' }
    cvc { '737' }

    visa

    trait :visa do
      number { 4111_1111_1111_1111.to_s }
    end

    trait :mastercard do
      number { 5555_5555_5555_4444.to_s }
    end

    trait :amex do
      number { 3451_779254_88348.to_s }
      cvc { '7373' }
    end

    skip_create
    initialize_with { new(attributes) }
  end
end

Example usage:

RSpec.describe ExamplePaymentService do
  let(:credit_card) { FactoryBot.build(:adyen_test_card) }
  ...
end

adyen-cse-ruby's People

Contributors

jooeycheng avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

adyen-cse-ruby's Issues

OpenSSL::CCMError: unsupported cipher algorithm (AES)

Happening on certain environments (CircleCI), still unsure of root cause:

OpenSSL::CCMError:
  unsupported cipher algorithm (AES)
./vendor/bundle/ruby/2.5.0/gems/openssl-ccm-1.2.1/lib/openssl/ccm.rb:42:in `initialize'
./vendor/bundle/ruby/2.5.0/gems/adyen-cse-ruby-1.1.0/lib/adyen_cse/encrypter.rb:34:in `new'
./vendor/bundle/ruby/2.5.0/gems/adyen-cse-ruby-1.1.0/lib/adyen_cse/encrypter.rb:34:in `encrypt!'

Refer to SmallLars/openssl-ccm#4 for issue explanation.

NoMethodError: undefined method `e=' for #<OpenSSL::PKey::RSA:0x.....>

The NoMethodError is triggered from
https://github.com/jooeycheng/adyen-cse-ruby/blob/v1.0.0/lib/adyen_cse/encrypter.rb#L49
https://github.com/jooeycheng/adyen-cse-ruby/blob/master/lib/adyen_cse/encrypter.rb#L49

as in MRI 2.4.3 the OpenSSL::PKey::RSA class changed; you are suppose to call #set_keys.
https://ruby-doc.org/stdlib-2.4.3/libdoc/openssl/rdoc/OpenSSL/PKey/RSA.html#method-i-set_key

Please check the following commit in the fork of @vbanthia, maybe he could make a PR (instead of publishing the gem himself with v2.0.0).
vbanthia-zz@898d275

Ruby Version: ruby 2.4.4p296 (2018-03-28 revision 63013)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.