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
diasks2
source share