Module: GlobalpayRubyGem
- Extended by:
- GlobalpayRubyGem
- Included in:
- GlobalpayRubyGem
- Defined in:
- lib/globalpay_ruby_gem.rb,
lib/globalpay_ruby_gem/version.rb
Constant Summary collapse
- VERSION =
"1.2.0"
Instance Method Summary collapse
- #authenticate_client(client_id, client_secret, is_live) ⇒ Object
- #authentication(*args) ⇒ Object
- #initialize(*args) ⇒ Object
- #initialize_transaction(access_token, returnurl, merchantreference, merchantid, description, currencycode, totalamount, customeremail, customernumber, customerfirstname, customerlastname, is_live) ⇒ Object
- #retrieve(*args) ⇒ Object
- #retrieve_transaction(access_token, merchantid, merchantreference, transactionrequest, is_live) ⇒ Object
Instance Method Details
#authenticate_client(client_id, client_secret, is_live) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/globalpay_ruby_gem.rb', line 35 def authenticate_client(client_id,client_secret,is_live) http = HTTPClient.new body = 'client_id='+client_id+'&client_secret='+client_secret+'grant_type=client_credentials' header = { 'Content-Type' => 'application/x-www-form-urlencoded'} if is_live res = http.post(TOKEN_URL_LIVE, body) else res = http.post(TOKEN_URL_STAGING, body) end if res.successful?(res.status) res.body else response = "{'error':{'status':'#{res.status}','body':'#{res.body}'}}" end end |
#authentication(*args) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/globalpay_ruby_gem.rb', line 10 def authentication(*args) if args.size == 4 GlobalpayRubyGem.authenticate_client(args[0],args[1],args[2]) else response = "{'error':'parameters miss match, expecting 4 paramters'}" end end |
#initialize(*args) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/globalpay_ruby_gem.rb', line 18 def initialize(*args) if args.size == 7 GlobalpayRubyGem.initialize_transaction(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11]) else response = "{'error':'parameters miss match, expecting 7 paramters'}" end end |
#initialize_transaction(access_token, returnurl, merchantreference, merchantid, description, currencycode, totalamount, customeremail, customernumber, customerfirstname, customerlastname, is_live) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/globalpay_ruby_gem.rb', line 53 def initialize_transaction(access_token,returnurl,merchantreference,merchantid,description,currencycode,totalamount,customeremail,customernumber,customerfirstname,customerlastname,is_live) http = HTTPClient.new body = { 'returnurl' => returnurl,'customerip' => '', 'merchantreference' => merchantreference, 'merchantid' => merchantid, 'description' => description, 'currencycode' => currencycode, 'totalamount' => totalamount, 'customer' => { 'email' => customeremail,'firstname' => customerfirstname, 'lastname' => customerlastname, 'mobile' => customernumber }, 'paymentmethod' => 'card','transactionType' => 'Payment', 'connectionmode' => 'redirect', 'product' => [{'name' => description, 'unitprice' => totalamount,'quantity' => '1'}]} header = { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{access_token}"} if is_live res = http.post(BASE_URL_LIVE + '/SetRequest', body,header) else res = http.post(BASE_URL_STAGING + '/SetRequest', body,header) end if res.successful?(res.status) res.body else response = "{'error':{'status':'#{res.status}','body':'#{res.body}'}}" end end |
#retrieve(*args) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/globalpay_ruby_gem.rb', line 26 def retrieve(*args) if args.size == 4 GlobalpayRubyGem.retrieve_transaction(args[0],args[1],args[2],args[3],args[4]) else response = "{'error':'parameters miss match, expecting 4 paramters'}" end end |
#retrieve_transaction(access_token, merchantid, merchantreference, transactionrequest, is_live) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/globalpay_ruby_gem.rb', line 73 def retrieve_transaction(access_token,merchantid,merchantreference,transactionrequest,is_live) http = HTTPClient.new body = { 'merchantId' => merchantid, 'merchantreference' => merchantreference, 'transactionRequest' => transactionrequest} header = { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{access_token}"} if is_live res = http.post(BASE_URL_LIVE + '/Retrieve', body,header) else res = http.post(BASE_URL_STAGING + '/Retrieve', body,header) end if res.successful?(res.status) res.body else response = "{'error':{'status':'#{res.status}','body':'#{res.body}'}}" end end |