Module: Freelancer::API::Payment::InstanceMethods
- Defined in:
- lib/freelancer/api/payment.rb
Instance Method Summary collapse
-
#account_balance ⇒ Object
Retrieve the current users balance and the details of the last transaction.
-
#account_milestones(*args) ⇒ Object
Retrieve a list of milestones for the current user.
-
#account_withdrawals(*args) ⇒ Object
Retrieve a list of withdrawals for the current user.
-
#balance ⇒ Object
Retrieve the balance for the current user.
-
#cancel_milestone(*args) ⇒ Object
Cancel a milestone payment.
-
#cancel_withdrawal(*args) ⇒ Object
Cancel a money withdrawal request.
-
#create_milestone_payment(*args) ⇒ Object
Create a new milestone payment.
-
#prepare_transfer(*args) ⇒ Object
Prepare a transfer to validate it before actually transfering.
-
#projects_for_transfer ⇒ Object
Retrieve a list of projects that’s available for transfers.
-
#release_milestone(*args) ⇒ Object
Release a milestone payment.
-
#request_release_milestone(*args) ⇒ Object
Request to release a milestone payment.
-
#request_withdrawal(*args) ⇒ Object
Request withdrawal of funds.
-
#transactions(*args) ⇒ Object
Retrieve a list of transactions for the current user.
-
#transfer_money(*args) ⇒ Object
Transfer money to another user.
-
#withdrawal_fees ⇒ Object
Retrieve a list of available withdrawal fees.
Instance Method Details
#account_balance ⇒ Object
Retrieve the current users balance and the details of the last transaction.
8 9 10 11 12 13 |
# File 'lib/freelancer/api/payment.rb', line 8 def account_balance result = api_get("/Payment/getAccountBalanceStatus.json") ::Freelancer::Models::Balance.parse(result, :shift => :"json-result") end |
#account_milestones(*args) ⇒ Object
Retrieve a list of milestones for the current user
Valid parameters are:
- type: the type of milestone (Incoming (default) or Outgoing)
- count: the number of results to return (defaults to 50)
- page: the page to retrieve (defaults to 0)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/freelancer/api/payment.rb', line 53 def account_milestones(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/getAccountMilestoneList.json", build_api_params({ :type => params[:type], :count => params[:count], :page => params[:page] })) # Parse and return the response ::Freelancer::Models::Milestone.parse_collection(result, :shift => [ :"json-result", :items ]) end |
#account_withdrawals(*args) ⇒ Object
Retrieve a list of withdrawals for the current user
Valid parameters are:
- type: the type of withdrawal (Incoming (default) or Outgoing)
- count: the number of results to return (defaults to 50)
- page: the page to retrieve (defaults to 0)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/freelancer/api/payment.rb', line 75 def account_withdrawals(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/getAccountWithdrawalList.json", build_api_params({ :type => params[:type], :count => params[:count], :page => params[:page] })) # Parse and return the response ::Freelancer::Models::Withdrawal.parse_collection(result, :shift => [ :"json-result", :items ]) end |
#balance ⇒ Object
Retrieve the balance for the current user
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/freelancer/api/payment.rb', line 92 def balance result = api_get("/Payment/getBalance.json") json = JSONMapper::Parser.parse(result) if !json.nil? && json.key?(:"json-result") return json[:"json-result"][:balance].to_f end return nil end |
#cancel_milestone(*args) ⇒ Object
Cancel a milestone payment
Valid parameters are:
- transaction_id: the id of the milestone transaction to cancel
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/freelancer/api/payment.rb', line 228 def cancel_milestone(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/cancelMilestone.json", build_api_params({ :transactionid => params[:transaction_id] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#cancel_withdrawal(*args) ⇒ Object
Cancel a money withdrawal request
Valid parameters are:
- withdrawal_id: the id of the withdrawal to cancel
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/freelancer/api/payment.rb', line 210 def cancel_withdrawal(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/requestCancelWithdrawal.json", build_api_params({ :withdrawalid => params[:withdrawal_id] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#create_milestone_payment(*args) ⇒ Object
Create a new milestone payment
Valid parameters are:
- project_id: the id of the project to create the payment for
- amount: the amount of money to add to the milestone payment
- user_id: the id of the user to make out the payment to
- username: the username of the user to make out the payment to
- comment: the comment of the payment
- type: the milestone payment type (partial, full or other)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/freelancer/api/payment.rb', line 159 def create_milestone_payment(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/createMilestonePayment.json", build_api_params({ :projectid => params[:project_id], :amount => params[:amount], :touserid => params[:user_id], :tousername => params[:username], :reasontext => params[:comment], :reasontype => params[:type] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#prepare_transfer(*args) ⇒ Object
Prepare a transfer to validate it before actually transfering
Valid parameters are:
- project_id: the id of the project to transfer money for
- amount: the amount of money to transfer
- user_id: the id of the user to transfer money to
- type: the type of transfer (partial, full or other)
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/freelancer/api/payment.rb', line 287 def prepare_transfer(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/prepareTransfer.json", build_api_params({ :projectid => params[:project_id], :amount => params[:amount], :touserid => params[:user_id], :reasontype => params[:type] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#projects_for_transfer ⇒ Object
Retrieve a list of projects that’s available for transfers
113 114 115 116 117 118 |
# File 'lib/freelancer/api/payment.rb', line 113 def projects_for_transfer result = api_get("/Payment/getProjectListForTransfer.json") ::Freelancer::Models::Project.parse_collection(result, :shift => [ :"json-result", :items, :project ]) end |
#release_milestone(*args) ⇒ Object
Release a milestone payment
Valid parameters are:
- transaction_id: the id of the milestone transaction to release
- full_name: the full name of the payer (signature)
265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/freelancer/api/payment.rb', line 265 def release_milestone(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/releaseMilestone.json", build_api_params({ :transactionid => params[:transaction_id], :fullname => params[:full_name] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#request_release_milestone(*args) ⇒ Object
Request to release a milestone payment
Valid parameters are:
- transaction_id: the id of the milestone transaction to release
246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/freelancer/api/payment.rb', line 246 def request_release_milestone(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/requestReleaseMilestone.json", build_api_params({ :transactionid => params[:transaction_id] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#request_withdrawal(*args) ⇒ Object
Request withdrawal of funds
Valid parameters are:
- amount: the amount of money to withdraw
- method: the withdrawal method (paypal, moneybooker, wire, paynoneer)
- wire_comment: withdrawal comment for wire transfer
- paypal_email: paypal account to withdraw to
- moneybooker_account: moneybooker account to withdraw to
- description: description for wire transfer withdrawal
- country_code: country code for wire transfer withdrawal
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/freelancer/api/payment.rb', line 130 def request_withdrawal(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/requestWithdrawal.json", build_api_params({ :amount => params[:amount], :method => params[:method], :additionaltext => params[:wire_comment], :paypalemail => params[:paypal_email], :mb_account => params[:moneybooker_account], :description => params[:description], :country_code => params[:country_code] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#transactions(*args) ⇒ Object
Retrieve a list of transactions for the current user
Valid parameters are:
- from: the from date/time to search by
- to: the to date/time to search by
- count: the number of results to return (defaults to 50)
- page: the page to retrieve (defaults to 0)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/freelancer/api/payment.rb', line 22 def transactions(*args) params = extract_params(args) # If we have a from or to date, convert it to a string if params.key?(:from) && params[:from].is_a?(Date) params[:from] = params[:from].strftime("%Y-%m-%d %H:%M:%S") end if params.key?(:to) && params[:to].is_a?(Date) params[:to] = params[:to].strftime("%Y-%m-%d %H:%M:%S") end # Execute the service call result = api_get("/Payment/getAccountTransactionList.json", build_api_params({ :datefrom => params[:from], :dateto => params[:to], :count => params[:count], :page => params[:page] })) # Parse and return the response ::Freelancer::Models::Transaction.parse_collection(result, :shift => [ :"json-result", :items ]) end |
#transfer_money(*args) ⇒ Object
Transfer money to another user
Valid parameters are:
- project_id: the id of the project to transfer money for
- amount: the amount of money to transfer
- user_id: the id of the user to transfer the money to
- username: the username of the user to transfer the money to
- comment: the comment of the transfer
- type: the transfer type (partial, full or other)
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/freelancer/api/payment.rb', line 187 def transfer_money(*args) params = extract_params(args) # Execute the service call result = api_get("/Payment/transferMoney.json", build_api_params({ :projectid => params[:project_id], :amount => params[:amount], :touserid => params[:user_id], :tousername => params[:username], :reasontext => params[:comment], :reasontype => params[:type] })) # Parse and return the response ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result") end |
#withdrawal_fees ⇒ Object
Retrieve a list of available withdrawal fees
105 106 107 108 109 110 |
# File 'lib/freelancer/api/payment.rb', line 105 def withdrawal_fees result = api_get("/Payment/getWithdrawalFees.json") ::Freelancer::Models::WithdrawalFee.parse_collection(result, :shift => [ :"json-result", :items, :fee ]) end |