Rails - PayPal IPN Callback Processing Using Coupon Replication

I am using a paypal-recurring gem to handle recurring payments in a Rails application. Most of my codes are from this excellent Railscast , but I also want to add a payment_notification model to accept the IPN callback and save any relevant data. This Railscast describes how to set up notifications. However, it is difficult for me to determine how to send the paypal-recurring gem IPN callback to my PaymentNotification model.

How can I set: ipn_url to write the IPN callback correctly for my PaymentNotification model. I tried the following:

1) Adding ipn_url: "http://my-app-name.com/payment_notifications" to the process method (under options) or payment_notifications_url

2) Try the solution suggested at the bottom of this page of the GitHub problem

3) Using the Paypal instant payment simulator (IPN) to send to "http://my-app-name.com/payment_notifications", but I get an error message: IPN delivery error. HTTP Error Code 401: Unauthorized

EDIT

I was able to successfully simulate IPN delivery on my payments_notifications_url. Now I just need to figure out how to specify a repeating stone in order to send ipn there.

Any pointers would be greatly appreciated. Below is the code of my current code. If I forget any relevant details, please let me know.

PaypalPayment Model

  class PaypalPayment def initialize(subscription) @subscription = subscription end def checkout_details process :checkout_details end def checkout_url(options) process(:checkout, options).checkout_url end def make_recurring process :request_payment process :create_recurring_profile, period: :monthly, frequency: 1, start_at: Time.zone.now end def cancel_recurring process :cancel end private def process(action, options = {}) options = options.reverse_merge( token: @subscription.paypal_payment_token, payer_id: @subscription.paypal_customer_token, description: @subscription.plan.name, amount: @subscription.plan.monthly_price, currency: "JPY" ) response = PayPal::Recurring.new(options).send(action) raise response.errors.inspect if response.errors.present? response end end 

Payment Controller

  class PaymentNotificationsController < ApplicationController protect_from_forgery :except => [:create] def create PaymentNotification.create!(:params => params, :status => params[:payment_status], :transaction_id => params[:txn_id]) render :nothing => true end end 
+7
source share
1 answer

I have earned. In case someone in the future encounters the IPP PayPal problem, here are a few things that I was wrong:

1) In my subscription controller, I called if @subscription.save instead of if @subscription.save_with_payment , so the save_with_payment method was not actually called.

2) In the process method, I added ipn_url: "https://my-app-name.com/payment_notifications",

  def process(action, options = {}) options = options.reverse_merge( token: @subscription.paypal_payment_token, payer_id: @subscription.paypal_customer_token, description: @subscription.plan.name, amount: @subscription.plan.monthly_price, ipn_url: "https://my-app-name.com/payment_notifications", currency: "JPY" ) response = PayPal::Recurring.new(options).send(action) raise response.errors.inspect if response.errors.present? response end 

3) In the PayPal developer’s sandbox, click “Test Accounts” and then click the orange “Enter Sandbox Test Site” button. After that, log in with your seller credentials. After that, go to the "My Account" and "Profile" section, and in the "Sales Settings" section, click "Instant Payment Notification Settings". Set the URL of your notification so that it matches the URL that you configured to receive the POST IPN, and set up message delivery to enable.

+5
source

All Articles