Is there a PayPal IPN code sample for Ruby on Rails?

前端 未结 7 455
渐次进展
渐次进展 2021-02-01 05:27

There are official code samples for several languages but couldn\'t find one for Rails.

7条回答
  •  梦如初夏
    2021-02-01 06:03

    There are a few PayPal gems, and at least one of them (paypal-sdk-rest) includes the PayPal::SDK::Core::API::IPN.valid? method.

    Here's how to use it:

    class YourController < ApplicationController
    
      skip_before_action :verify_authenticity_token, only: :your_action
    
      def your_action
        verified = PayPal::SDK::Core::API::IPN.valid?(request.raw_post)
    
        if verified
          # Verification passed, do something useful here.
          render nothing: true, status: :ok
        else
          # Verification failed!
          render nothing: true, status: :unprocessable_entity
        end
      end
    
    end
    

提交回复
热议问题