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
Related
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
I have a system which receives and send mails to the various members in a group.
Lets say I have a group support#xyz.com which have members
member_1#xyz.com
member_2#xyz.com
and so on..
Same way there is another group help#xyz.com which have members
member_1#xyz.com
member_3#xyz.com
and so on..
When I get any mail for support#xyz.com it is forwarded to it's member and same way for help#xyz.com.
mail :from => the_person_who_sent_mail,
:to => members_email_id,
:subject => mail_subject,
:reply_to => the_group_name#xyz.com
And it appears like mail was sent to me.
But I want to do a change in this as shown below :
When it lands in my inbox it should be something like
From : the_person_who_sent_mail#something.com
Reply To : the_group_name#xyz.com
To : the_group_name#xyz.com
But according to my setting it comes like
From : the_person_who_sent_mail#something.com
Reply To : the_group_name#xyz.com
To : members_email_id#xyz.com
In my case it shows that the mail is destined to me. But in the first case it shows to whom the mail was originally destined for.
Mailing list servers accomplish this with BCC, like so:
mail :from => the_person_who_sent_mail,
:to => the_group_name#xyz.com,
:subject => mail_subject,
:reply_to => the_group_name#xyz.com,
:bcc => [members_email_id]
The downside to this is that your mailserver will actually attempt to send the e-mail to the_group_name#xyz.com, so it will have to know to ignore this message. However, when the message arrives in the user's inbox, the To: will be the_group_name#xyz.com.
The following code seems to work if there is one user, but truncate the email for multiple users:
users.each do |user|
mail(
:to => user.email,
:subject => 'Hi',
:template_name => 'notification'
).deliver
Is this the proper way to send a few emails?
Ruby on Rails 3.2.2
Heroku
SendGrid
I think this is what you're looking for:
def my_mailer_method
users = User.find({ ... })
headers['X-SMTPAPI'] = { :to => users.to_a }.to_json
mail(
:to => "this.will#be.ignored.com",
:subject => "Hi",
:template_name => "notification"
).deliver
end
This sends a message to any number of recipients use the SendGrid's SMTP API. You can find further information on the docs page.
You might also want to take a look at the sendgrid rails gem
To send email to multiple users: pass an array
Replace
:to => user.email
with
:to => users.map(&:email)
more > rails guide
If it is not important for you to hide email addresses from each other, you can specify recipients in a comma delimited string.
It seems that the problem is that each instance of the Mailer can only send one email. Perhaps the mail object is falling out of scope and getting cleaned up by the garbage collector...
The solution that worked was to iterate over the users outside of the Mailer, and call it once for each user. It may be slow but it should happen in the background anyway so it's fine.
I am trying to implement paypal express checkout using rails. I have read at lot of places that if one wants to do the checkout without paypal account by credit or debit card one can simply use SOLUTIONTYPE=Sole. It does not seem to work though and asks for login when I try to checkout. Please find the attached screenshot which shows this problem.
Here is my controller code :-
def pay
topup = Topup.find(params[:id])
response = EXPRESS_GATEWAY.setup_purchase(topup.price_in_cents,{
:ip => request.remote_ip,
:currency_code => 'GBP',
:return_url => topups_success_url,
:cancel_return_url => topups_cancel_url,
:SOLUTIONTYPE => 'Sole',
:items => [{:name => "Topup", :quantity => 1,:description => "Top up my account", :amount => topup.price_in_cents}]
})
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end
what is it that I am doing wrong? I am testing it on sandbox as of now.
Found an answer to this issue on SO itself, here is the link in case someone bumps into this question. API differences between Paypal Express Checkout and Website Payment Standard
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)