How to get IPN notification in PayPal on localhost - ruby-on-rails

I am using Adaptive Payment in PayPal.
I am following the https://github.com/paypal/adaptivepayments-sdk-ruby.
All is working fine except I am not able to receive IPN notofications locally.
#api = PayPal::SDK::AdaptivePayments.new
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => "http://"+Rails.application.config.app_name+"/admin/dashboard",
:currencyCode => "USD",
:feesPayer => "SENDER",
:ipnNotificationUrl => "http://"+Rails.application.config.app_name+"/admin/receive_notification",
:receiverList => {
:receiver => [{
:amount => amount,
:email => #paypal_id }] },
:returnUrl => "http://"+Rails.application.config.app_name+"/admin/dashboard" })
So , how to receive notifications on localhost

Paypal will not be able to route to localhost to send the IPN. You would need to setup a publicly available domain name and the appropriate dns.
Localhost is always specific to your machine, you might be able to use dynamicdns but it would require network changes on your machine and network.

Related

Stripe API in Rails

I'm trying to use source_transaction with the Rails API so that I can have managed accounts that create payments and are later sent to other accounts.
I'm getting the error Stripe::InvalidRequestError: Insufficient funds in Stripe account. In test mode, you can add funds to your available bal
ance (bypassing your pending balance) by creating a charge with 4000 0000 0000 0077 as the card number. You can use th
e the /v1/balance endpoint to view your Stripe balance (for more details, see stripe.com/docs/api#balance).
But usinrg source_transaction I thought was supposed to bypass using my balance and only transfer funds once the transaction cleared.
Here is the code I'm using
charge = Stripe::Charge.create(
:customer => stripe_cust_id,
:amount => total_amount_owed,
:description => 'Groundwork Subscription Charge',
:currency => 'usd',
:transfer_group => invoice_number
)
...
transfer = Stripe::Transfer.create({
:amount => amount_to_transfer,
:currency => "usd",
:destination => StripeInfo.where(account_id: project_owner.accounts.first.id).first.stripe_id,
:application_fee => (amount_to_transfer*0.05).round,
:source_transaction => charge[:charge_id]
# :transfer_group => invoice_number
})

recurring paypal with preapproval adaptive payment

I have create rails application and implemented preapproval payment using adaptivepayments-sdk-ruby gem. I plan to use this as recurring payment.
this is my code for create preapproval:
ADAPTIVE_PAYMENT.build_preapproval({
:cancelUrl => my_cancel_url,
:currencyCode => "USD",
:paymentPeriod => "DAILY",
:returnUrl => my_return_url,
:startingDate => DateTime.now.in_time_zone
})
and then I use this code to charge:
ADAPTIVE_PAYMENT.build_pay({
:actionType => "PAY",
:cancelUrl => my_cancel_url,
:currencyCode => "USD",
:feesPayer => "PRIMARYRECEIVER",
:preapprovalKey => Preapproval_key,
:receiverList => {
:receiver => [{
:amount => 100,
:email => example#example.com,
:primary => true},
{
:amount => $100,
:email => example#example.com,
:primary => false }
]
},
:returnUrl => my_return_url
})
How to make it automatically charged every day without execute the pay code again?
Im pretty sure there is no automatic pay feature from paypals side. I know that you can setup how many monthly / weekly payments they are signing up for but I think thats just for the pre-approval agreement.
However, why dont you just setup a CRON job and let it take care of it for you? I was super nervous about doing this with paypal adaptive payments the first time but its actually saved me SO much time and its a lot more reliable than any human could be with its ability to send job reports after its done.

Paypal adaptive payments for digital goods

I am struggling to figure out how to get Digital goods to work with my adaptive payments. I am using the Paypal ruby gem can someone please show me a code sample for a payments with 2 receivers and for Digital Goods?
I already am approved for micro payments by paypal.
# Build request object
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => "http://localhost:3000/account", #sandbox
:currencyCode => "USD",
#:feesPayer => "SENDER",
:ipnNotificationUrl => "http://596w.localtunnel.com/pay/#{purchased.id}", #sandbox
:memo => "Test payment",
:receiverList => {
:receiver => [{
:amount => price.round(2),
:email => "an email", #sandbox
:paymentType => "DIGITALGOODS",
:primary => true
},
unless account.user.email == "an email"
{
:amount => mycut.round(2),
:email => "anemail", #sandbox
:paymentType => "DIGITALGOODS"
}
end
] },
:returnUrl => "http://localhost:3000/pay/complete/" #sandbox
})
I get the error:
This feature (Digital Goods) is not supported.
As far as i know on the the Express Payment option of Paypal supports digital good. if you can replace your integration to use activemerchant and use the PaypalDigitalGoodsGateway you'd do yourself a favor.
Log a ticket at https://www.paypal.com/mts and they'll enable it for you.
For what it's worth, the product you're trying to use is: Digital Goods for Express Checkout.
Express Checkout itself is available by default on all accounts, but that team can enable Digital Goods on your Sandbox account.
This error may appear if you get the payKey successfully but redirect user to wrong url later.
Here is haml code for form for embedded payments, including Digital Goods.
= javascript_include_tag "//www.paypalobjects.com/js/external/apdg.js"
%form.text-center{:action => ::PAYPAL_ADAPTIVE_GATEWAY.embedded_flow_url, :target => "PPDGFrame"}
%input#type{:name => "expType", :type => "hidden", :value => "light"}
%input#paykey{:name => "payKey", :type => "hidden", :value => #payKey}
%input#submitBtn{:type => "submit", :value => 'Pay with PayPal' }
:javascript
var returnFromPayPal = function(){
//do something on PayPal popup closing here
};
var dgFlowMini = new PAYPAL.apps.DGFlowMini({ trigger: 'submitBtn', callbackFunction: returnFromPayPal});
//works only for lightbox mode
function MyEmbeddedFlow(embeddedFlow) {
this.embeddedPPObj = embeddedFlow;
this.paymentSuccess = function () {
this.embeddedPPObj.closeFlow();
// handle payment success here
window.location.reload(true);
};
this.paymentCanceled = function () {
this.embeddedPPObj.closeFlow();
// handle payment cancellation here
window.location.reload(true);
};
}
var myEmbeddedPaymentFlow = new MyEmbeddedFlow(dgFlowMini);
::PAYPAL_ADAPTIVE_GATEWAY.embedded_flow_url is from activemerchant, you may use 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay' for sandbox or 'https://www.paypal.com/webapps/adaptivepayment/flow/pay' for production.

hostname does not match the server certificate - cannot send email

I am using Pony mail to send email messages (because I could never get ActionMailer to work on my local Windows box).
The code in my user_mailer.rb file include this call to the Pony.mail method:
Pony.mail({
:to => email_address,
:from => 'MyChairSales <support#mychairsales.com>',
:subject => subject,
:body => email_body,
:html_body => html_body,
:via => :smtp,
:via_options => {
:address => 'mail.mychairsales.com',
:port => '25',
:enable_starttls_auto => true,
:user_name => 'mychairs',
:password => 'thepassword',
:domain => "mychairsales.com" # the HELO domain provided by the client to the server
}
})
This was working (I have received email using this method) but is now failing with the error "hostname does not match the server certificate".
Here is the top of the stack trace:
["/usr/lib64/ruby/1.9.3/openssl/ssl-internal.rb:121:in `post_connection_check'",
"/usr/lib64/ruby/1.9.3/net/smtp.rb:585:in `tlsconnect'", "/usr/lib64/ruby/1.9.3
/net/smtp.rb:560:in `do_start'", "/usr/lib64/ruby/1.9.3/net/smtp.rb:519:in `start'",
"/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib/mail/network/delivery_methods
/smtp.rb:144:in `deliver!'", "/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib
/mail/message.rb:245:in `deliver!'", "/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:166:in `deliver'", "/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:138:in `mail'", "/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:32:in `send_mail'", "/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:23:in `send_password_reset_email'",...
Any guidance would be greatly appreciated!
A bit late but I also encountered this error but with the Ruby Mail gem. If your SMTP server supports TLS, it will attempt to use TLS and authenticate the SSL certificate. If the certificate is issued for a hostname other than the one used or if the certificate cannot be authenticated (for example if it's self-signed and you don't trust the CA), then it will fail with the error "hostname does not match the server certificate".
To get around it, use the :openssl_verify_mode option. This can be set to OpenSSL::SSL::VERIFY_NONE to do no verification of the certificate - it will still encrypt the SMTP session though. Or there are other options available within the OpenSSL library.
Using your example, it would be:
Pony.mail({
:to => email_address,
:from => 'MyChairSales <support#mychairsales.com>',
:subject => subject,
:body => email_body,
:html_body => html_body,
:via => :smtp,
:via_options => {
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
:address => 'mail.mychairsales.com',
:port => '25',
:enable_starttls_auto => true,
:user_name => 'mychairs',
:password => 'thepassword',
:domain => "mychairsales.com" # the HELO domain provided by the client to the server
}
})
This also works for the Mail gem as well.

How to use an external server with Ruby AMQP Carrot Library

I am using the Ruby AMQP Carrot library and I am trying to talk to a test RabbitMQ server on a virtual machine. The AMQP port is open on the machine but I can't get Carrot to establish an external connection. I have tried the following:
Carrot.queue('message', :durable => true, :server => '192.168.162.176')
Carrot.queue('message', :durable => true, :host => '192.168.162.176')
I talked with the Carrot developer and this is the answer he gave me and it works great:
#client = Carrot.new(
:host => host,
:port => port.to_i,
:user => #opts['user'],
:pass => #opts['pass'],
:vhost => #opts['vhost'],
:insist => #opts['insist']
)
queue = #client.queue('foo')

Resources