Class: K2Pay
- Defined in:
- lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb
Overview
For PAY/ Send Money to others TODO: Add K2Config configuration for the callback URL
Constant Summary
Constants included from K2Validation
K2Validation::ALL_EVENT_TYPES, K2Validation::TILL_SCOPE_EVENT_TYPES
Instance Attribute Summary collapse
-
#payments_location_url ⇒ Object
readonly
Returns the value of attribute payments_location_url.
-
#recipients_location_url ⇒ Object
readonly
Returns the value of attribute recipients_location_url.
Attributes inherited from K2Entity
#access_token, #k2_response_body, #location_url, #query_hash, #the_array
Instance Method Summary collapse
-
#add_recipient(params) ⇒ Object
Adding PAY Recipients with either mobile_wallets or bank_accounts as destination of your payments.
-
#create_payment(params) ⇒ Object
Create an outgoing Payment to a third party.
-
#query_resource(url) ⇒ Object
Query Location URL.
-
#query_status(method_type) ⇒ Object
Query/Check the status of a previously initiated PAY Payment request.
Methods inherited from K2Entity
Methods included from K2Validation
#determine_scope_details, #incorrect_keys, #nil_values, #to_indifferent_access, #validate_email, #validate_hash, #validate_input, #validate_network, #validate_phone, #validate_settlement_method, #validate_till_number_prefix, #validate_url, #validate_webhook, #validate_webhook_input
Methods included from K2Utilities
Constructor Details
This class inherits a constructor from K2Entity
Instance Attribute Details
#payments_location_url ⇒ Object (readonly)
Returns the value of attribute payments_location_url.
4 5 6 |
# File 'lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb', line 4 def payments_location_url @payments_location_url end |
#recipients_location_url ⇒ Object (readonly)
Returns the value of attribute recipients_location_url.
4 5 6 |
# File 'lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb', line 4 def recipients_location_url @recipients_location_url end |
Instance Method Details
#add_recipient(params) ⇒ Object
Adding PAY Recipients with either mobile_wallets or bank_accounts as destination of your payments.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb', line 7 def add_recipient(params) params = params.with_indifferent_access @exception_array += %w[type] # In the case of mobile pay recipient if params[:type].eql?('mobile_wallet') params = validate_input(params, @exception_array += %w[first_name last_name phone_number email network]) k2_request_pay_recipient = { first_name: params[:first_name], last_name: params[:last_name], phone_number: validate_phone(params[:phone_number]), email: validate_email(params[:email]), network: params[:network] } # In the case of bank pay recipient elsif params[:type].eql?('bank_account') params = validate_input(params, @exception_array += %w[account_name account_number bank_branch_ref settlement_method]) k2_request_pay_recipient = { account_name: params[:account_name], account_number: params[:account_number], bank_branch_ref: params[:bank_branch_ref], settlement_method: params[:settlement_method] } # In the case of till pay recipient elsif params[:type].eql?('till') params = validate_input(params, @exception_array += %w[till_name till_number]) k2_request_pay_recipient = { till_name: params[:till_name], till_number: params[:till_number] } # In the case of bank pay recipient elsif params[:type].eql?('paybill') params = validate_input(params, @exception_array += %w[paybill_name paybill_number paybill_account_number]) k2_request_pay_recipient = { paybill_name: params[:paybill_name], paybill_number: params[:paybill_number], paybill_account_number: params[:paybill_account_number] } else raise ArgumentError, 'Undefined Payment Method.' end recipients_body = { type: params[:type], #type: params['pay_type'], pay_recipient: k2_request_pay_recipient } pay_recipient_hash = make_hash(K2Config.path_url('pay_recipient'), 'post', @access_token, 'PAY', recipients_body) @threads << Thread.new do sleep 0.25 @recipients_location_url = K2Connect.make_request(pay_recipient_hash) end @threads.each(&:join) end |
#create_payment(params) ⇒ Object
Create an outgoing Payment to a third party.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb', line 61 def create_payment(params) # Validation params = validate_input(params, @exception_array += %w[destination_reference destination_type description category tags currency value callback_url metadata]) # The Request Body Parameters k2_request_pay_amount = { currency: params[:currency], value: params[:value] } = params[:metadata] k2_request_links = { callback_url: params[:callback_url] } create_payment_body = { destination_reference: params[:destination_reference], destination_type: params[:destination_type], description: params[:description], category: params[:category], tags: params[:tags], amount: k2_request_pay_amount, meta_data: , _links: k2_request_links } create_payment_hash = make_hash(K2Config.path_url('payments'), 'post', @access_token, 'PAY', create_payment_body) @threads << Thread.new do sleep 0.25 @payments_location_url = K2Connect.make_request(create_payment_hash) end @threads.each(&:join) end |
#query_resource(url) ⇒ Object
Query Location URL
101 102 103 |
# File 'lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb', line 101 def query_resource(url) super('PAY', url) end |
#query_status(method_type) ⇒ Object
Query/Check the status of a previously initiated PAY Payment request
92 93 94 95 96 97 98 |
# File 'lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb', line 92 def query_status(method_type) if method_type.eql?('recipients') super('PAY', @recipients_location_url) elsif method_type.eql?('payments') super('PAY', @payments_location_url) end end |