Verify User API Credentials - Rails, ActiveMerchant, and PayPal Express Gateway

I am creating an application in the market using PayPal Express. I have a form for sellers to enter their PayPal API credentials, but I need a way to verify them by making some sort of call to PayPal.

I use PayPalExpressGateway in ActiveMerchant, and I see nothing but standard purchase controls. Is there any null operation that can be used?

Any help would be greatly appreciated!

+4
source share
7 answers

For security reasons, there is no way to check if the email is a valid PayPal account. You can always make a small transaction and then cancel it if the validity of the account is really required.

+1
source

I am using TransactionSearch for this purpose. STARTDATE=2100-01-01 00:00:00 specifying STARTDATE=2100-01-01 00:00:00 , this basically results in no operation.

He will check the credentials for you without requiring additional data from the seller.

+2
source

I have no answer personally. But I know that Ryan Bates from Railscasts.com recently dedicated six (!) Episodes of ActiveMerchant and Paypal in particular. Browse episodes No. 141 to No. 146 at railscasts.com .

+1
source

OK, after 4 hours ...

  module ActiveMerchant #: nodoc:
   module Billing #: nodoc:
     class PaypalExpressGateway <Gateway

       def get_balance (options = {})
         commit 'GetBalance', build_get_balance_request (options)
       end

     private
       def build_get_balance_request (options)
         xml = Builder :: XmlMarkup.new: indent => 2
         xml.tag!  'GetBalanceReq', 'xmlns' => PAYPAL_NAMESPACE do
           xml.tag!  'GetBalanceRequest', 'xmlns: n2' => EBAY_NAMESPACE do
             xml.tag!  'n2: Version', API_VERSION
             xml.tag!  'n2: ReturnAllCurrencies', '1'
           end
         end

         xml.target!
       end
     end
   end
 end

 class SellerMerchantValidator <ActiveModel :: Validator
   def validate (record)
     paypal_attrs = ['paypal_api_username', 'paypal_api_password', 'paypal_api_signature']
     if record.paypal_merchant?  && (record.changed - paypal_attrs) .size <record.changed.size # one of paypal_attrs changed
       response = record.gateway.get_balance
       unless response.params ['balance']. present?
         record.errors [: base] << "Please check the PayPal details and make sure all three are entered correctly."
       end
     end
   end
 end

Thanks to Neils for the idea of ​​checking out TransactionSearch.

Please let me know if there is a better way to check if any of the api fields have changed.

+1
source

There is also a GetBalance call in the API. Code example

Looks like the easiest (and fastest?) Way.

+1
source

PayPal has an AddressVerify API. It confirms whether the mailing address and postal code match the specified PayPal account holder. In fact, I am currently implementing it on our website.

You can learn more about this here:
https://www.x.com/docs/DOC-1162#id0862M0QH02L

and here:
https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_AddressVerify

0
source

That's right, so if you want to test user credentials using ActiveMerchant, use the transaction_search method on the gateway

https://github.com/Shopify/active_merchant/blob/cb72e0f9c58f57b1293e6e976229b26cfbfee6a8/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb

This example will return success (be sure to fill out your test credentials)

 @username = '' @password = '' @signature = '' gateway = ActiveMerchant::Billing::PaypalExpressGateway.new( login: @username, password: @password, signature: @signature, test: true ) gateway.transaction_search({start_date: DateTime.now}) 
0
source

All Articles