Giter VIP home page Giter VIP logo

active_merchant_first_data's Introduction

First Data Latvia gateway for Active Merchant

Build Status

Install

$ gem install active_merchant_first_data

Usage

require "active_merchant_first_data"

gateway = ActiveMerchant::Billing::FirstDataGateway.new(
  pem:  File.read("1234567_keystore.pem"),
  pem_password: "5x64jq8n234c"
)

# Authorize for 10 euros (1000 euro cents)
response = gateway.authorize(1000, client_ip_addr: '127.0.0.1')

# Use this url to enter credit card data
gateway.redirect_url(response.authorization)

# Capture the money
gateway.capture(1000, response.authorization, client_ip_addr: '127.0.0.1')

First Data test environment setup

  1. Generate a new certificate

    $ openssl req -newkey rsa:2048 -keyout spec/certs/1234567_key.pem -out spec/certs/1234567_req.pem -subj "/C=lv/O=example.com/CN=1234567" -outform PEM
    Enter PEM pass phrase: 81f174259v45
  2. Request your certificate using 1234567_req.pem

  3. Copy the 3 files you received in e-mail to spec/certs/:

    1234567.pem
    1234567_certificate_chain.p7.pem
    ECOMM.pem
    
  4. Convert the certificates and keys to 1234567_keystore.pem

    $ openssl pkcs12 -export -in spec/certs/1234567.pem -out spec/certs/1234567_keystore.p12 -certfile spec/certs/ECOMM.pem -inkey spec/certs/1234567_key.pem
    Enter pass phrase for 1234567_key.pem: 81f174259v45
    Enter Export Password: <empty>
    $ openssl pkcs12 -in spec/certs/1234567_keystore.p12 > spec/certs/1234567_keystore.pem
    Enter Import Password: <empty>
    Enter PEM pass phrase: 5x64jq8n234c
  5. Set your WAN IP address

Mocking in (RSpec) tests

Perhaps the best way to mock responses in tests is to disallow remote connections altogether and then control what responses specific requests receive.

For example, to mock response to the #purchase request with WebMock you'd:

before do
  body = {
    "TRANSACTION_ID" => "e+oClP4em8uBDozaZ4CBBbipEcM="
  }.merge(options).map{ |k, v| "#{k}: #{v}" }.join("\n")

  WebMock.stub_request(:post, %r'firstdata.lv').
    with(body: hash_including("command" => "v")).
    to_return(body: body)
end

Peruse first_data_gateway.rb to find out which command letters map to which methods.
Additionally, have a look at spec/cassettes for response body examples.

active_merchant_first_data's People

Contributors

ebeigarts avatar epigene avatar janjiss avatar miks avatar rsim avatar sacristan avatar

Watchers

 avatar

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.