Class: Paytrail::MerchantApi
- Inherits:
-
Object
- Object
- Paytrail::MerchantApi
- Defined in:
- lib/paytrail/merchantapi.rb
Constant Summary collapse
- @@apiName =
Example usage
require ‘paytrail/merchantapi’
merchantApi = Paytrail::MerchantApi.new(13466, ‘6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ’, ‘api.paytrail.com’) response = merchantApi.createRefund(
'ORD-59867', '[email protected]', [{ :amount => 100, :vatPercent => 1000, :description => 'Refund for item 123' }], 'http://paytrail.com'
)
refundToken = nil
if response.code == ‘202’
puts 'Refund created!' location = response.get_fields('location') refundToken = location[0].split('/')[-1]
else
puts 'ERROR' print 'HTTP code: ' puts response.code puts response.body
end
if refundToken
response = merchantApi.deleteRefund(refundToken) if response.code == '204' puts 'Refund deleted!' else puts 'ERROR' print 'HTTP code: ' puts response.code puts response.body end
end
'PaytrailMerchantAPI'
Instance Method Summary collapse
- #createRefund(orderNumber, email, refundRows, notifyUrl) ⇒ Object
- #deleteRefund(refundToken) ⇒ Object
-
#initialize(apiKey, secret, uri) ⇒ MerchantApi
constructor
A new instance of MerchantApi.
Constructor Details
#initialize(apiKey, secret, uri) ⇒ MerchantApi
Returns a new instance of MerchantApi.
48 49 50 51 |
# File 'lib/paytrail/merchantapi.rb', line 48 def initialize(apiKey, secret, uri) @paytrail = Paytrail.new(@@apiName, apiKey, secret) @uri = uri end |
Instance Method Details
#createRefund(orderNumber, email, refundRows, notifyUrl) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/paytrail/merchantapi.rb', line 53 def createRefund(orderNumber, email, refundRows, notifyUrl) data = { :email => email, :rows => refundRows } if notifyUrl data[:notifyUrl] = notifyUrl end data = data.to_json location = '/merchant/v1/payments/%s/refunds' % [orderNumber] headers = @paytrail.makeHeaders('POST', location, @paytrail.makeTimestamp, data) @paytrail.post(@uri + location, headers, data) end |
#deleteRefund(refundToken) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/paytrail/merchantapi.rb', line 70 def deleteRefund(refundToken) location = '/merchant/v1/refunds/%s' % [refundToken] headers = @paytrail.makeHeaders('DELETE', location, @paytrail.makeTimestamp, '') @paytrail.delete(@uri + location, headers) end |