How I can use IPN handler with Pay operation and receive messages? - ruby-on-rails

I have function, which paying users:
def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
user = User.find(params[:user_id])
#params_id = params[:user_id]
credentials = {
'USER' => 'payer_1342623102_biz_api1.gmail.com',
'PWD' => '1342623141',
'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
}
header = {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
"X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T"
}
//here is data what is posting to PayPal
data = {"actionType" => "PAY",
"receiverList.receiver(0).email"=> user.email,
"receiverList.receiver(0).amount" => "10",
"currencyCode" => "USD",
"cancelUrl" => "http://127.0.0.1:3000/",
"returnUrl" => "http://127.0.0.1:3000/",
"requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
end
From documentation:
Adaptive Payments API operation - use -
ipnNotificationUrl field of the Pay or Preapproval request
So, I should add into data variable:
"ipnNotificationUrl" => "myaapp.com"//my site url yes ?
I should put in this field my site url or not ?
How to get info from this notification ?
How to send some emails and do some action if transaction is successful ?
I can't test it locally, yes ?
How can I test it in sandbox ?

Yes, you should include the field if you want to receive notifications related to the payment,
You need to specify a URL that is reachable from the outside (As this is where PayPal will post the information to, from their servers).
This URL could be a PHP page, that upon receiving the IPN, and verifying it, sends out the emails you mentioned.
To simulate an IPN coming from PayPal, you can use the following tool from the sandbox developer page: https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
(Alternatively, you can complete a purchase in the sandbox, and if you specified the ipnNotificationURL in the API call, PayPal will send you one upon completion of the payment)

Related

how to record inbound calls with twilio

Outbound calls in Twilio can be recorded by setting the TwiML passed to the client.calls.create() API method to have a <Conference> tag with the record attribute set to true. If recordingStatusCallback is set to a URL it'll post a notification to that URL when the recording is available.
How do you do this for inbound calls?
For my specific phone number, for Voice & Fax, I have, on twilio.com, "Accept Incoming" set to "Voice Calls", "Configure With" set to "TwiML App" and "TwiML App" set to my custom app. For that app I have the Voice Request URL set to a given URL.
When a call is incoming an HTTP POST is made to my TwiML App, which responds with an <Enqueue>. Later, a Conference Instruction Reservation is made in the client side javascript with ConferenceRecord set to true and ConferenceRecordingStatusCallback set to the same URL that we used with recordingStatusCallback for the outbound calls.
Here's what my "Conference Instruction Reservation" request payload looks like:
stdClass Object
(
[url] => https://taskrouter.twilio.com/v1/Workspaces/.../Tasks/.../Reservations/...
[method] => POST
[token] => ...
[params] => stdClass Object
(
[Instruction] => conference
[From] =>
[PostWorkActivitySid] =>
[Timeout] => 10
[To] =>
[EndConferenceOnExit] => true
[EndConferenceOnCustomerExit] => true
[ConferenceStatusCallback] => https://my.domain.tld/twilio/conference
[ConferenceStatusCallbackMethod] => POST
[ConferenceStatusCallbackEvent] => start,end,join,leave,mute,hold
[ConferenceRecord] => true
[ConferenceRecordingStatusCallback] => https://my.domain.tld/twilio/conference/recording
[ConferenceRecordingStatusCallbackMethod] => POST
[ConferenceRecordingStatusCallbackEvent] => completed
)
)
As a result of that Twilio calls the ConferenceStatusCallback URL multiple times but the ConferenceRecordingStatusCallback URL is never called.
Any ideas?
So idk why the "Conference Instruction Reservation" request approach wasn't working but calling client.calls.recordings.create() did the trick

Forward message similar to webhook from a Studio Flow

I have the ability to receive the full incoming message from setting a url in the number section under "A message comes in" to Webhook and entering my url. I would like my messages to be processed in a Studio Flow first. Is there any way from the flow I could then pass it out to a webhook url? I know the webhook sends this info in json, but I'm not sure if I can build all of this data with the html widget. Any idea for how I could do it?
(
[inbound] =>
[ToCountry] => US
[ToState] => OK
[SmsMessageSid] => xxx
[NumMedia] => 0
[ToCity] => NOBLE
[FromZip] => 73003
[SmsSid] => xxx
[FromState] => OK
[SmsStatus] => received
[FromCity] => EDMOND
[Body] => Test
[FromCountry] => US
[To] => +xxx
[ToZip] => 73068
[NumSegments] => 1
[MessageSid] => xxx
[AccountSid] => xxx
[From] => +xxx
[ApiVersion] => 2010-04-01
)
Twilio developer evangelist here.
You could certainly pass it to a Studio Flow first, as you describe, and then use the HTTP request to send all the data onto a webhook URL of your own.
To send all the data onto your own URL, you would need to add all the parameters to the widget too. You'll find all that data in the trigger object within the flow.

How to pass form data to an external API in ROR

Hello I am designing an online application that uses mobile money as a means of payment. But I need assistance on how I can pass my order form data to the API of the mobile money service providers who complete the transaction.
Try httparty, post method.
An existed example could be
options = {:type => auto}
payload = options.to_json
query = {
:request_id => request_id,
......................
:user_id => user
}
response = post("/tbc/submit_job.json", :body => payload, :query => query)
You can use httparty to customize yours.

How to return profile id using paypal subscription button?

I am using Paypal subscription button to subscribe the item,I have successfully subscribe the item but in response I get (transaction id,signature,cc,transaction status,cost,currency_code custom_msg) but i need profile_id(subscription id) for that particular subscription also.because when I unsubscribe the item,I need profile_id to unsubscribe it.
You could use IPN to get the details of the transaction back to your system. This will contain the transaction as well as the profile id. You will receive an IPN each time the profile bills.
Finally got the solution, I have used paypal_nvp gem with GetTransactionDetails API to find the profile id for particular subscription.
p = PaypalNVP.new(true{ :user => "o.bonn_1237393081_biz_api1.solisoft.net", :pass => "1237393093", :cert => "AU2Yv5COwWPCfeYLv34Z766F-gfNAzX6LaQE6VZkHMRq35Gmite-bMXu", :url => "https://api-3t.sandbox.paypal.com/nvp" })
data = {
:method => "GetTransactionDetails",
:TRANSACTIONID =>params[:tx]
}
response = p.call_paypal(data)
profile_id = response["SUBSCRIPTIONID"]
for further information you can go to https://github.com/solisoft/paypal_nvp url

paypal adaptive payment rails 3

How to use ipn notification with paypal apadaptive payment gem with active merchant?
I want to avoid using metal, directly a controller wanna use.
rails 3
ruby 1.9.2
Thanks
Using like this
response = gateway.setup_purchase(
:return_url => url_for(:action => 'index',:port=>"3001", :only_path => false),
:cancel_url => url_for(:action => 'create',:port=>"3001", :only_path => false),
**:ipn_notification_url => payments_notify_action_url**,
:receiver_list => recipients
)
Here you specify the IPN notification URL and then:
def notify_action
notify = ActiveMerchant::Billing::Integrations::PaypalAdaptivePayment::Notification.new(request.raw_post)
p "Notification object is #{notify}"
if notify.acknowledge
p "Transaction ID is #{notify.transaction_id}"
p "Notification object is #{notify}"
p "Notification status is #{notify.status}"
end
Before that go to the sandbox account.
Choose the test account.
Then click any business account -> click "Enter sandbox account"
Enter email of business account and type password
Choose -> profile settings -> ipn notification -> set return url
You may want to check this gem that encapsulates it all for your convenience:
https://github.com/jpablobr/active_paypal_adaptive_payment

Resources