Class: Charge

Inherits:
Object
  • Object
show all
Defined in:
lib/payment/Charge.rb

Instance Method Summary collapse

Constructor Details

#initialize(endpoints, username, password) ⇒ Charge

Returns a new instance of Charge.



11
12
13
14
15
# File 'lib/payment/Charge.rb', line 11

def initialize(endpoints, username, password)
  @endpoints=endpoints
  @username=username
  @password=password
end

Instance Method Details

#charge(endUserId, referenceCode, description, currency, amount, code, clientCorrelator, onBehalfOf, purchaseCategoryCode, channel, taxAmount, serviceId, productId) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/payment/Charge.rb', line 41

def charge(endUserId,referenceCode,description,currency,amount,code,clientCorrelator,onBehalfOf,purchaseCategoryCode,channel,taxAmount,serviceId,productId)
  baseurl=@endpoints.getAmountChargeEndpoint()
  requestProcessor=JSONRequest.new()
  formparameters=FormParameters.new()
  formparameters.put('endUserId',endUserId)
  if baseurl.index('{endUserId}')!=nil then
    baseurl=baseurl.gsub('{endUserId}',CGI::escape(endUserId.to_s))
  end
  formparameters.put('referenceCode',referenceCode)
  formparameters.put('description',description)
  formparameters.put('currency',currency)
  formparameters.put('amount',amount)
  formparameters.put('code',code)
  formparameters.put('clientCorrelator',clientCorrelator)
  formparameters.put('onBehalfOf',onBehalfOf)
  formparameters.put('purchaseCategoryCode',purchaseCategoryCode)
  formparameters.put('channel',channel)
  formparameters.put('taxAmount',taxAmount)
  formparameters.put('serviceId',serviceId)
  formparameters.put('productId',productId)
  postdata=formparameters.encodeParameters()
  rawresponse=requestProcessor.post(baseurl,postdata,'application/json', @username, @password)
  response=AmountResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['amountTransaction']!=nil) then
      response.setAmountTransactionJSON(jsondata['amountTransaction'])
    end
  end
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end

#chargeWithCallback(endUserId, referenceCode, description, currency, amount, code, callbackURL, clientCorrelator, onBehalfOf, purchaseCategoryCode, channel, taxAmount, serviceId, productId) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/payment/Charge.rb', line 82

def chargeWithCallback(endUserId,referenceCode,description,currency,amount,code,callbackURL,clientCorrelator,onBehalfOf,purchaseCategoryCode,channel,taxAmount,serviceId,productId)
  baseurl=@endpoints.getAmountChargeEndpoint()
  requestProcessor=JSONRequest.new()
  formparameters=FormParameters.new()
  formparameters.put('endUserId',endUserId)
  if baseurl.index('{endUserId}')!=nil then
    baseurl=baseurl.gsub('{endUserId}',CGI::escape(endUserId.to_s))
  end
  formparameters.put('referenceCode',referenceCode)
  formparameters.put('description',description)
  formparameters.put('currency',currency)
  formparameters.put('amount',amount)
  formparameters.put('code',code)
  formparameters.put('callbackURL',callbackURL)
  formparameters.put('clientCorrelator',clientCorrelator)
  formparameters.put('onBehalfOf',onBehalfOf)
  formparameters.put('purchaseCategoryCode',purchaseCategoryCode)
  formparameters.put('channel',channel)
  formparameters.put('taxAmount',taxAmount)
  formparameters.put('serviceId',serviceId)
  formparameters.put('productId',productId)
  postdata=formparameters.encodeParameters()
  rawresponse=requestProcessor.post(baseurl,postdata,'application/json', @username, @password)
  response=AmountResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['amountTransaction']!=nil) then
      response.setAmountTransactionJSON(jsondata['amountTransaction'])
    end
  end
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end

#getEndpointsObject



16
17
18
# File 'lib/payment/Charge.rb', line 16

def getEndpoints
  @endpoints
end

#getPasswordObject



32
33
34
# File 'lib/payment/Charge.rb', line 32

def getPassword
  @password
end

#getUsernameObject



24
25
26
# File 'lib/payment/Charge.rb', line 24

def getUsername
  @username
end

#refund(endUserId, referenceCode, description, currency, amount, code, clientCorrelator, originalServerReferenceCode, onBehalfOf, purchaseCategoryCode, channel, taxAmount, serviceId, productId) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/payment/Charge.rb', line 124

def refund(endUserId,referenceCode,description,currency,amount,code,clientCorrelator,originalServerReferenceCode,onBehalfOf,purchaseCategoryCode,channel,taxAmount,serviceId,productId)
  baseurl=@endpoints.getAmountRefundEndpoint()
  requestProcessor=JSONRequest.new()
  formparameters=FormParameters.new()
  formparameters.put('endUserId',endUserId)
  if baseurl.index('{endUserId}')!=nil then
    baseurl=baseurl.gsub('{endUserId}',CGI::escape(endUserId.to_s))
  end
  formparameters.put('referenceCode',referenceCode)
  formparameters.put('description',description)
  formparameters.put('currency',currency)
  formparameters.put('amount',amount)
  formparameters.put('code',code)
  formparameters.put('clientCorrelator',clientCorrelator)
  formparameters.put('originalServerReferenceCode',originalServerReferenceCode)
  formparameters.put('onBehalfOf',onBehalfOf)
  formparameters.put('purchaseCategoryCode',purchaseCategoryCode)
  formparameters.put('channel',channel)
  formparameters.put('taxAmount',taxAmount)
  formparameters.put('serviceId',serviceId)
  formparameters.put('productId',productId)
  postdata=formparameters.encodeParameters()
  rawresponse=requestProcessor.post(baseurl,postdata,'application/json', @username, @password)
  response=AmountResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['amountTransaction']!=nil) then
      response.setAmountTransactionJSON(jsondata['amountTransaction'])
    end
  end
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end

#setEndpoints(endpoints) ⇒ Object



20
21
22
# File 'lib/payment/Charge.rb', line 20

def setEndpoints(endpoints)
  @endpoints=endpoints
end

#setPassword(password) ⇒ Object



36
37
38
# File 'lib/payment/Charge.rb', line 36

def setPassword(password)
  @password=password
end

#setUsername(username) ⇒ Object



28
29
30
# File 'lib/payment/Charge.rb', line 28

def setUsername(username)
  @username=username
end