Class | ActiveMerchant::Billing::Integrations::Paypal::Notification
In: | lib/active_merchant/billing/integrations/paypal/notification.rb
Parent: | ActiveMerchant::Billing::Integrations::Notification

Parser and handler for incoming Instant payment notifications from paypal. The Example shows a typical handler in a rails application. Note that this is an example, please read the Paypal API documentation for all the details on creating a safe payment controller.

Example

      class BackendController < ApplicationController
        include ActiveMerchant::Billing::Integrations

        def paypal_ipn
          notify = Paypal::Notification.new(request.raw_post)

          order = Order.find(notify.item_id)

          if notify.acknowledge
            begin

              if notify.complete? and order.total == notify.amount
                order.status = 'success'

                shop.ship(order)
              else
                logger.error("Failed to verify Paypal's notification, please investigate")
              end

            rescue => e
              order.status        = 'failed'
              raise
            ensure
              order.save
            end
          end

          render :nothing
        end
      end

### Methods

account acknowledge complete? currency fee gross invoice item_id received_at status test? transaction_id type

### Included Modules

PostsData

### Public Instance methods

account()
acknowledge()

Acknowledge the transaction to paypal. This method has to be called after a new ipn arrives. Paypal will verify that all the information we received are correct and will return a ok or a fail.

Example:

      def paypal_ipn
        notify = PaypalNotification.new(request.raw_post)

        if notify.acknowledge
          ... process order ... if notify.complete?
        else
          ... log possible hacking attempt ...
        end

complete?()

Was the transaction complete?

currency()

What currency have we been dealing with

fee()

the markup paypal charges for the transaction

gross()

the money amount we received in X.2 decimal.

invoice()

This is the invoice which you passed to paypal

item_id()

This is the item number which we submitted to paypal The custom field is also mapped to item_id because PayPal doesn‘t return item_number in dispute notifications

received_at()

When was this payment received by the client. sometimes it can happen that we get the notification much later. One possible scenario is that our web application was down. In this case paypal tries several times an hour to inform us about the notification

status()

Status of transaction. List of possible values: `Canceled-Reversal`:: `Completed`:: `Denied`:: `Expired`:: `Failed`:: `In-Progress`:: `Partially-Refunded`:: `Pending`:: `Processed`:: `Refunded`:: `Reversed`:: `Voided`::

test?()

Was this a test transaction?

transaction_id()

Id of this transaction (paypal number)

type()

What type of transaction are we dealing with?

     "cart" "send_money" "web_accept" are possible here.

[Validate]