Coder Social home page Coder Social logo

ruby-sdk's Introduction

Build Status Coverage Status

Pay.nl SDK in Ruby



This SDK is available as Ruby gem.

With this SDK you will be able to start transactions and retrieve transactions with their status for the Pay.nl payment service provider.

Installation

Add this line to your application's Gemfile:

gem 'paynl'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paynl

Requirements

This gem requires Ruby 2.5+. We have tested this gem with Ruby 2.5, 2.6 and 2.7.

Usage

Loading the gem (after installation):

require 'paynl'

Setting the configuration:

require 'paynl'

Paynl::Config::setApiToken('****************************************')
Paynl::Config::setServiceId('SL-####-####')
Paynl::Config::setTokenCode('AT-####-####')

Getting a list of available payment methods for your site:

require 'paynl'

Paynl::Config::setApiToken('****************************************')
Paynl::Config::setServiceId('SL-####-####')
Paynl::Config::setTokenCode('AT-####-####')
api = Paynl::Paymentmethods.new
options = Hash.new
puts api.getList(options)

Starting a transaction:

require 'paynl'

Paynl::Config::setApiToken('****************************************')
Paynl::Config::setServiceId('SL-####-####')
Paynl::Config::setTokenCode('AT-####-####')

data = Paynl::Transaction.new
options = Hash.new
# Required values
options.store('amount', 6.21)
options.store('returnUrl', 'http://some.url.for.your.system.example.org/visitor-return-after-payment')
options.store('ipaddress', '127.0.0.1')


# Optional values
options.store('paymentMethod', 10)
options.store('description', 'demo payment')
options.store('testMode', true)
options.store('extra1', 'ext1')
options.store('extra2', 'ext2')
options.store('extra3', 'ext3')

# First product
products = Hash.new
product = Hash.new
product.store('id', '234567')
product.store('price', 1.21)
product.store('tax', 0.21)
product.store('name', 'Testproduct voor de demo tour')
product.store('qty', 1)
products.store(products.length + 1, product)

# Second product
product = Hash.new
product.store('id', '2')
product.store('price', 5.00)
product.store('tax', 0.87)
product.store('name', 'Testproduct 2 voor de demo tour')
product.store('qty', 1)
products.store(products.length + 1, product)
options.store('products', products)

# Enduser data
enduser = Hash.new
enduser.store('initials', 'T')
enduser.store('lastName', 'Test')
enduser.store('gender', 'M')
enduser.store('dob', '14-05-1999')
enduser.store('phoneNumber', '0612345678')
enduser.store('emailAddress', '[email protected]')
enduser.store('language','EN')
options.store('enduser', enduser)

# Address data
address = Hash.new
address.store('streetName', 'Test')
address.store('houseNumber', '10')
address.store('zipCode', '1234AB')
address.store('city', 'Test')
address.store('country', 'NL')
options.store('address', address)

invoiceAddress = Hash.new
invoiceAddress.store('initials', 'IT')
invoiceAddress.store('lastName', 'ITTest')
invoiceAddress.store('streetName', 'ITest')
invoiceAddress.store('houseNumber', '15')
invoiceAddress.store('zipCode', '1234CC')
invoiceAddress.store('city', 'TTest')
invoiceAddress.store('country', 'NL')
options.store('invoiceAddress', invoiceAddress)

result = data.start(options)

# Store the transaction ID which is in
puts result['transaction']['transactionId']

# Redirect the user to the URL
puts result['transaction']['paymentURL']

To determine if a transaction has been paid, you can use:

require 'paynl'

Paynl::Config::setApiToken('****************************************')
Paynl::Config::setServiceId('SL-####-####')
Paynl::Config::setTokenCode('AT-####-####')

data = Paynl::Transaction.new
result = data.getTransaction(transactionId)
if Paynl::Helper::transactionIsPaid(result) or Paynl::Helper::transactionIsPending(result)
    # redirect user to thank you page
else
    # it has not been paid yet, so redirect user back to checkout
end

When implementing the exchange script (where you should process the order in your backend):

require 'paynl'

Paynl::Config::setApiToken('****************************************')
Paynl::Config::setServiceId('SL-####-####')
Paynl::Config::setTokenCode('AT-####-####')

data = Paynl::Transaction.new
result = data.getTransaction(transactionId)
if Paynl::Helper::transactionIsPaid(result)
    # Process the payment
elsif Paynl::Helper::transactionIsCanceled(result)
    # Payment canceled, restock items
end

puts 'TRUE| ' 
# Optionally you can send a message after TRUE|, you can view these messages in the logs.
# https://admin.pay.nl/logs/payment_state
puts 'Paid: ' + Paynl::Helper::transactionIsPaid(result).to_s

Contributing

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

License

The gem is available as open source under the terms of the MIT License.

ruby-sdk's People

Contributors

sebastianberm avatar andypieters avatar woutse avatar ssl 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.