Skip to content

Ruby gem enabling communication with GoPay (Czech payment integrator)

Notifications You must be signed in to change notification settings

Pepan/gopay_api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About GoPay

GoPay is a library making it easy to access GoPay.cz paygate from Ruby.

Quick Start

GoPay is distributed primarily via gem, but it can be also placed to “vendor/plugins” as a Rails plugin.

Configuration

First, you have to include it in your Gemfile or install manually and require:

# Gemfile
gem 'gopay'

# Manually
gem install gopay
require 'gopay'

GoPay can be configured within a config block (placed in config/initializers/gopay.rb for Rails, for instance):

GoPay.configure do |config|
    config.environment = :test
    config.goid = "XXXXX"
    config.secret = "XXXXX"
    config.success_url = "https://example.com/success"
    config.failed_url = "https://example.com/failed"
end

It can also take a YAML file with configuration:

# YAML file (config.yml):
goid: XXXXX
secret: XXXXX
success_url: https://www.success_url.cz
failed_url: https://www.failed_url.cz


# Ruby:
GoPay.configure_from_yaml("config.yml"))

Such YAML config file can be also placed in Rails config dir (named gopay.yml) – it will be autoloaded.

Usage

# first you have to init a payment
payment = GoPay::EshopPayment.new(:variable_symbol => "gopay_test_#{GoPay.configuration.goid}",
                                            :total_price_in_cents => 100,
                                            :product_name => "productName",
                                            :payment_channel => "cz_gp_w"
                                           )
# and request its creation on paygate:
payment.create # =>
# #<GoPay::EshopPayment:0x7fa27c0fab88
# @last_response=
#  {:"@xmlns:ns1"=>"urn:AxisEPaymentProvider",
#   :total_price=>"100",
#   :variable_symbol=>"gopay_test_8531903182",
#   :result=>"CALL_COMPLETED",
#   :payment_channel=>
#    {:"@xsi:type"=>"soapenc:string",
#     :"@xmlns:soapenc"=>"https://schemas.xmlsoap.org/soap/encoding/"},
#   :eshop_go_id=>"8531903182",
#  :session_state=>"WAITING",
#   :"@xsi:type"=>"ns1:EPaymentStatus",
#  :buyer_go_id=>
#    {:"@xsi:type"=>"soapenc:long",
#     :"@xmlns:soapenc"=>"https://schemas.xmlsoap.org/soap/encoding/"},
#   :product_name=>"productName",
#   :payment_session_id=>"3000523838",
#   :result_description=>"WAITING",
#  :url=>"https://www.failed_url.cz",
#   :encrypted_signature=>
#    "b653c3b55e981abb29ff9a6b25eb1153abb4d5e888b4675594b636456146c189fba2f81e6303dfa3a5b661f6d58385a0"},
# @payment_channel="cz_gp_w",
# @payment_session_id="3000523838",
# @product_name="productName",
# @total_price_in_cents=100,

# After user gets back to success/failed url, you can check status of payment:
payment = GoPay::EshopPayment.new(:variable_symbol => "XXXXX",
                                      :total_price_in_cents => price.to_i,
                                      :product_name => name,
                                      :payment_session_id => payment_session_id,
                                      :payment_channels => ["cz_gp_w"])

payment.actual_session_state # => "PAYMENT_DONE"
payment.is_in_state?(GoPay::PAYMENT_DONE) # => true

About

Ruby gem enabling communication with GoPay (Czech payment integrator)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%