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
81
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
|
# File 'lib/nequi.rb', line 52
def self.payment_request(amount, phone, product_id)
current_time = Time.now
utc_time = current_time.utc
formatted_timestamp = utc_time.strftime('%Y-%m-%dT%H:%M:%S.%LZ')
access_token = get_token[:access_token]
= {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => "Bearer #{access_token}",
'x-api-key' => configuration.api_key
}
body = {
"RequestMessage" => {
"RequestHeader" => {
"Channel" => "PNP04-C001",
"RequestDate" => formatted_timestamp,
"MessageID" => product_id,
"ClientID" => configuration.client_id,
"Destination" => {
"ServiceName" => "PaymentsService",
"ServiceOperation" => "unregisteredPayment",
"ServiceRegion" => "C001",
"ServiceVersion" => "1.2.0"
}
},
"RequestBody" => {
"any" => {
"unregisteredPaymentRQ" => {
"phoneNumber" => phone,
"code" => "NIT_1",
"value" => amount
}
}
}
}
}.to_json
unregisteredpayment = configuration.api_base_path + configuration.unregisteredpayment_endpoint
response = HTTParty.post(unregisteredpayment, body: body, headers: )
response_status = response["ResponseMessage"]["ResponseHeader"]["Status"]
status_code = response_status["StatusCode"]
status_description = response_status["StatusDesc"]
return {
type: 'Error',
status: status_code,
message: ERRORS_MESSAGES[:"#{status_code}"] || "#{status_code} #{status_description}",
} unless response_status == { "StatusCode" => "0", "StatusDesc" => "SUCCESS" }
response_any = response["ResponseMessage"]["ResponseBody"]["any"]
success_id = response_any["unregisteredPaymentRS"]["transactionId"]
{token: access_token, success_id: success_id, type: 'success', status: response.code, api_status: status_code, message: 'Payment request send success fully'}
end
|