activemerchant / offsite_payments

A simple and unified API to handle dozens of different offsite payment pages.
MIT License
169 stars 201 forks source link

Payfast Passphrase issue #295

Open lesliepoolman opened 6 years ago

lesliepoolman commented 6 years ago

Hello all,

This is the first time I am creating an issue on github so please be gentle :smile:

I have a Rails 4.2.9 store app where i have been using the Payfast payment system successfully for a while and now i want to add a passphrase to use the recurring billing on the same Payfast account on a different site.

When I test in my local env using ngrok and payfasts sandbox with a passphrase i get a http 400 error code. When I remove the passphrase from the sandbox the payments go through and my controller acknowledges them

This is the code I am using at the moment based off of the example from payfasts sample code.

Please let me know if you have any suggestions or questions

class PayfastController < ApplicationController
  include OffsitePayments::Integrations

  def success
  end

  def fail
  end

  def itn
    create_notification 'main'

    if @notification.acknowledge
      # binding.pry
        if @notification.complete? and @order.vcs_formatted_total == @notification.gross
          find_order_by_reference_and_complete_asynchronously @notification.item_id
          PaymentResponse.log_response @notification.params, "m_payment_id"
        end
    else
      head :bad_request
    end
  end

private

  def create_notification(password)
    @notification = OffsitePayments.integration(:pay_fast).notification(request.raw_post, secret: Settings.payfast_pass[password])
    find_payment
  end

  def find_payment
    @order = Order.find_by_reference @notification.item_id
  end
end
JGPage commented 6 years ago

Hi @lesliepoolman

Active merchant plugin isn't maintained anymore. If you use the newer one then you should be able to transact as you want.

lesliepoolman commented 6 years ago

hi @JGPage

Thanks for the response! I do not have an active_merchant gem on my rails app and I based this payfast integration off of other comments i found here in the offsite_payments issues. Can you please expand and explain your comment to me?

JGPage commented 6 years ago

Hi @lesliepoolman

Apologies, thought you were using the PayFast code that was in use previously, found in pay_fast.rb or are you using it?

If so, you would need to make some modifications as it doesn't incorporate the passphrase from what I remember. This would explain the behaviour you are seeing when removing the passphrase from the sandbox system.

Could you provide me with the email address you are transacting with on Sandbox? I'll then see if I can see anything.

lesliepoolman commented 6 years ago

I based my code off of this from payfast: https://github.com/pawel2105/payfast_rails_example and issue #80 and i read through the code in pay_fast.rb as well, so kind of a jigsaw of pieces that made sense to be put together in my case.