Giter VIP home page Giter VIP logo

paypal_adaptive's Introduction

paypal_adaptive

This gem is a lightweight wrapper for the paypal adaptive payments API.

This is very much a work in progress! Use at your own risk or submit bug fixes :)

Before you need start, read the API manual https://www.x.com/docs/DOC-1531 and check out the forums on http://x.com It'll be invaluable for parameters and error messages. The gem keeps the request/response as hashes so you will have to read the manual to make the proper calls. I made a few test cases for further examples at http://github.com/tc/paypal_adaptive/tree/master/test/

HOWTO

Create paypal_adaptive.yml to your config folder:

development:
  environment: "sandbox"
  username: "sandbox_username"
  password: "sandbox_password"
  signature: "sandbox_signature"
  application_id: "sandbox_app_id"
  api_cert_file:

test:
  environment: "sandbox"
  username: "sandbox_username"
  password: "sandbox_password"
  signature: "sandbox_signature"
  application_id: "sandbox_app_id"
  api_cert_file: "/path/to_cert"

production:
  environment: "production"
  username: "my_production_username"
  password: "my_production_password"
  signature: "my_production_signature"
  application_id: "my_production_app_id"
  api_cert_file: "/path/to_cert"

You can also use ENV variables when specifying your configuration. eg. <%= ENV[''paypal.username'] %>

Make the payment request:

pay_request = PaypalAdaptive::Request.new

data = {
"returnUrl" => "http://testserver.com/payments/completed_payment_request", 
"requestEnvelope" => {"errorLanguage" => "en_US"},
"currencyCode"=>"USD",  
"receiverList"=>{"receiver"=>[{"email"=>"[email protected]", "amount"=>"10.00"}]},
"cancelUrl"=>"http://testserver.com/payments/canceled_payment_request",
"actionType"=>"PAY",
"ipnNotificationUrl"=>"http://testserver.com/payments/ipn_notification"
}

pay_response = pay_request.pay(data)

if pay_response.success?
  redirect_to pay_response.preapproval_paypal_payment_url
else
  puts pay_response.errors.first['message']
  redirect_to failed_payment_url
end

Once the user goes to pay_response.approve_paypal_payment_url, they will be prompted to login to Paypal for payment.

Upon payment completion page, they will be redirected to http://testserver.com/payments/completed_payment_request.

They can also click cancel to go to http://testserver.com/payments/canceled_payment_request

The actual payment details will be sent to your server via "ipnNotificationUrl" You have to create a listener to receive POST messages from paypal. I added a Rails metal template in the templates folder which handles the callback.

Additionally, you can make calls to Paypal Adaptive's other APIs: payment_details, preapproval, preapproval_details, cancel_preapproval, convert_currency, refund

Input is just a Hash just like the pay method. Refer to the Paypal manual for more details.

Using the embedded payment flow

Instead of redirecting to the url from redirect_to pay_response.approve_paypal_payment_url you can generate the action url for your form by using pay_response.approve_paypal_payment_url 'MY TYPE' The two types that are supported for embedded payment are 'light' and 'mini' More information about these types can be found here https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIntro

Certificate validation

You can set the location of the key file you downloaded from PayPal, in paypal_adaptive.yml for each environment, e.g.:

development:
  environment: "sandbox"
  username: "sandbox_username"
  password: "sandbox_password"
  signature: "sandbox_signature"
  application_id: "sandbox_app_id"
  api_cert_file: "/path/to/your/private.key"

The api_cert_file should point to your cert_key_pem.txt that is downloaded through the paypal developer interface. It will contain a section that specifies the RSA private key and another section that specifies a certificate. If this is left empty, paypal_adaptive will attempt to use the signature method of validation with PayPal, so your signature config must not be nil.

Changelog

0.3.11 Remove json from dependencies

0.3.10 Remove Rails dependent gems thanks @ rchekaluk

0.3.9 Ensure POST response is not decompressed under Ruby 2.0 thanks @rchekaluk

0.3.8 Fix IPN send back data. thanks @maxbeizer

0.3.7 Fix IPN under Ruby 2.0. thanks @rchekaluk

0.3.6 Include more details in error in case the HTTP request doesn't return. thanks mreinsch

0.3.5 SSL verify mode set to none for sandbox testing. thanks @mikong

0.3.4 Locale specific paypal urls and improved testing. changed approve_paypal_payment_url method signature with deprecation warning. thanks mreinsch.

0.3.3 Handle JSON parsing error. Added validation for config.

0.3.2 Added support to api certificate since ssl_cert_file config is now used to set CA Authority. thanks jimbocortes

0.3.1 Update json dependency to use ~>1.0 so any version 1.X will work.

0.3.0 ssl_cert_file fixes from eddroid. get_verified_status function from bundacia.

0.2.9 Fixed cert issues in last release. Exception handling for connection.

0.2.8 Cert fixes and ruby 1.9.3 files. Thanks tonyla.

0.2.7 Refactored config file handling for better non-Rails support, thanks mreinsch and dave-thompson.

0.2.6 Fix for using correct status field in pre-approval, thanks nbibler. Fix for ruby 1.9.3, thanks deepj.

0.2.5 Fix for embedded payments, thanks rafaelivan. Fix for Rails 3.1.1, thanks synth.

0.2.4 Support for embedded payments. Issue #21 thanks rafaelivan. Shipping address, wrapper methods has return response object. Issue #22 thanks tsmango.

0.2.3 Using bundler for gem creation. Moved all code to paypal_adaptive dir. Added ExecutePayment call to request. Thanks Roger Neel.

0.2.2 Added support for ERB in the config file. Thanks DanielVartanov.

0.2.1 Fixed SSL bug. Thanks gaelian.

0.2.0 Thanks to seangaffney for set payment option support. Thanks to gaelian for ssl cert support. Changed tests to use relative paths.

0.1.0 Fixed IPN rails metal template by sending the correct params back: ipn.send_back(env['rack.request.form_vars']) Thanks to github.com/JoN1oP for fixing this.

0.0.5 Added Preapproval preapproval_paypal_payment_url along with test case.

0.0.4 Preapproval now returns a PaypalAdaptive::Response class. Added preapproval test cases.

0.0.3 Renamed PayRequest, PayResponse into Request, Response since other api calls use the class as well.

0.0.2 Fixed initialized constant warning.

0.0.1 First release.

Copyright

Copyright (c) 2009 Tommy Chheng. See LICENSE for details.

paypal_adaptive's People

Contributors

ajenkins avatar danielvartanov avatar deepj avatar elanper avatar gaelian avatar jalvarezsamayoa avatar masha256 avatar maxbeizer avatar mikong avatar nbibler avatar potomak avatar rafaelivan avatar rromanchuk avatar seangaffney avatar tc avatar tsmango avatar williampollet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paypal_adaptive's Issues

Paypal Sandbox server down

The last couple of days we've being getting this error from our ci server.

 JSON::ParserError:
      756: unexpected token at '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
      <html><head>
      <title>502 Proxy Error</title>
      </head><body>
      <h1>Proxy Error</h1>
      <p>The proxy server received an invalid
      response from an upstream server.<br />
      The proxy server could not handle the request <em><a href="/AdaptivePayments/CancelPreapproval">POST&nbsp;/AdaptivePayments/CancelPreapproval</a></em>.<p>
      Reason: <strong>Error reading from remote server</strong></p></p>
      </body></html>

I believe that this is caused by Request#post not being able to handle this 502 error from PayPal

https://github.com/tc/paypal_adaptive/blob/master/lib/paypal_adaptive/request.rb#L95

Would you accept a pull request to have this method throw a Net:HTTP exception just for this case?

Response incorrectly recognized as successful

Using a PayPal Preapproval key with this library, I've come across a response where this library incorrectly recognizes a payment as being successful:

{"responseEnvelope":{"timestamp":"2011-11-20T09:33:51.178-08:00","ack":"Success","correlationId":"XXXXX","build":"2279004"},"payKey":"AP-XXXXXXXXXXXXXXXXX","paymentExecStatus":"ERROR","payErrorList":{"payError":[{"receiver":{"amount":"25.0","email":"[email protected]"},"error":{"errorId":"580036","domain":"PLATFORM","severity":"Error","category":"Application","message":"This transaction cannot be processed. Please enter a valid credit card number and type"}}]}}

Currently, this library simply looks to the ack value to determine whether or not the response is successful. But, as you can see here, that is not always the case, as it is obviously an error response.

Chained Payments

Hey -

Am I right in saying although there are a couple of references to Chained Payments, it actually hasn't been fully implemented?

Thanks,

Geoff

Nil object

When I try pay_response.success?, I get this error

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

I used the sample code using a new PaypalAdaptive::Request and then using pay_respond = pay_request.pay(data).

I'm using the sandbox account, and I set up my .yml without a ssl cert file. Am I doing something wrong?

http.post response_data is nil

PayPal Adaptive payments would attempt to parse JSON with a nil object

File is lib/request.rb

I changed to

  # changing this! used to be JSON.parse(response_data)
  JSON.parse(resp.body)

And that seemed to do the trick!

PaypalAdaptive::Request.new method not working ?

Hi,

I am using papal_adaptive gem . I provided my paypal sandbox account details in papal_adaptive.yml file . When I call " pay_request = PaypalAdaptive::Request.new" , it throws below error . I am using ruby 1.9.2 ,rails 3.0.7 in windows .

You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]

Thanks in Advance,
Divya.

Dinamyc Reciever "Population" (Chained Payments)

Note: I didn't find a better title for this O.o

Humm, What I want to do is to have a Rails app where a visitor can click a button/link to make a "special" chained payment; Currently I have a Users registration form that has one field for the user to enter his/her paypal account email, and as I saw here: http://marker.to/XGg9MR it is possible to specify the primary reciever and the secondary ones by adding such info in a controller action when using your gem in a rails app. The thing is, I don't want to hard code the secondary reciever as I need to specify a different secondary reciever from time to time, (being specific my primary reciever will always be the same, but depending on what button/link the visitor clicks, the secondary one is going to change) and I want that secondary reciever email to be the paypal e-mail account from one of the registered users when the visitor clicks on their specific button/link...

My question is:

Is it possible to create such enviroment functionality in my app using the current implementation of your gem?

Could you point me in the right direction on how to accomplish such thing? I'm really new in the paypal handling universe! XD

Thanks! :)

confused and disoriented with paypal ipn

I am using this gem for payments in paypal https://github.com/tc/paypal_adaptive

I am very confused and disoriented with this gem. I hope this question will help more people having the same problem.

My steps are:

1ยบ I send request to paypal from my orders_controller.rb with method preaproval_payment.

def preapproval_payment
preapproval_request = PaypalAdaptive::Request.new
data = {
  "returnUrl" => response_paypal_user_orders_url(current_user),
  "cancelUrl"=>  cancel_payment_gift_url(@gift),
  "requestEnvelope" => {"errorLanguage" => "en_US"},
  "senderEmail" => "[email protected]",
  "startingDate" => Time.now,
  "endingDate" => Time.now + (60*60*24) * 30,
  "currencyCode"=>"USD",
  "maxAmountPerPayment" => "@gift.price",
  "ipnNotificationUrl" => ipn_notification_url,
  "ip" => request.remote_ip
  }
    preapproval_response = preapproval_request.preapproval(data)
    puts data
  if preapproval_response.success?
    redirect_to preapproval_response.preapproval_paypal_payment_url
  else
    redirect_to gift_url(@gift), alert: t(".something_was_wrong")
  end
end

2ยบ These are the data of my request in my log console from command puts data :

{"returnUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders/response_paypal", "cancelUrl"=>"http://localhost:3000/en/gifts/gift-1/cancel_payment", "requestEnvelope"=>{"errorLanguage"=>"en_US"}, "senderEmail"=>"[email protected]", "startingDate"=>2012-07-29 13:05:49 +0200, "endingDate"=>2012-08-28 13:05:49 +0200, "currencyCode"=>"USD", "maxAmountPerPayment"=>9, "ipnNotificationUrl"=>"http://localhost:3000/ipn_notification?locale=en", "ip"=>"127.0.0.1"}

3ยบ I redirect to paypal page, and I make the payment on paypal successfully :D.

4ยบ When payment is completed successfully, I am directed to:

http://localhost:3000/en/u/maserranocaceres/orders/response_paypal

I have response_paypal action in orders_controller.rb. It is GET action and my code for this action is:

def response_paypal
  respond_to do |format|
       format.html { redirect_to user_orders_url(current_user), :alert => "works fine return url"}
    end
 end

Up to this point everything works fine.

Now what I need is to get the data I received from paypal and save my database a new order if payment is successfully processed.

5ยบ For this purpose I make a file in lib/paypal_ipn.rb and I add to this file the content from https://github.com/tc/paypal_adaptive/blob/master/templates/paypal_ipn.rb

# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)

class PaypalIpn
  def self.call(env)
    if env["PATH_INFO"] =~ /^\/paypal_ipn/
      request = Rack::Request.new(env)
      params = request.params
      ipn = PaypalAdaptive::IpnNotification.new
      ipn.send_back(env['rack.request.form_vars'])
      if ipn.verified?
        #mark transaction as completed in your DB
        output = "Verified."
      else
        output = "Not Verified."
      end

      [200, {"Content-Type" => "text/html"}, [output]]
    else
      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
    end
  end

end

In my routes.rb I add:

match "/ipn_notification" => PaypalIpn

My 2 problems are:

a) I do not see that after making the payment this file to be fired and I can not see in my console data I get from paypal.

b) I want to send to paypal in my request, the id of object @gift for being able to recover later in paypal_ipn.rb and to save my database.

What am I doing wrong and how I can solve these problems?

Thank you

Rails blank? dependency

There is a dependency on Rails' blank? method, preventing using paypal_adaptive from straight Ruby:

undefined method `blank?' for nil:NilClass

The workaround is a monkey patch, but ideally this shouldn't be needed:

class NilClass
  def blank?
    true
  end
end

grep finds these uses of blank?

./lib/paypal_adaptive/config.rb:        @ssl_cert_path = config['ssl_cert_path'] unless config['ssl_cert_path'].blank?
./lib/paypal_adaptive/config.rb:        @ssl_cert_file = config['ssl_cert_file'] unless config['ssl_cert_file'].blank?
./lib/paypal_adaptive/config.rb:        @api_cert_file = config['api_cert_file'] unless config['api_cert_file'].blank?
./lib/paypal_adaptive/ipn_notification.rb:      http.ca_path = @ssl_cert_path unless @ssl_cert_path.blank?
./lib/paypal_adaptive/ipn_notification.rb:      http.ca_file = @ssl_cert_file unless @ssl_cert_file.blank?
./lib/paypal_adaptive/request.rb:      http.ca_path = @ssl_cert_path unless @ssl_cert_path.blank?
./lib/paypal_adaptive/request.rb:      http.ca_file = @ssl_cert_file unless @ssl_cert_file.blank?

In a Rake Task: uninitialized constant PaypalAdaptive::Config::Rails

I am trying to use your gem inside of a Rake Task. Whenever I do


I get the following error


uninitialized constant PaypalAdaptive::Config::Rails
/Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
/Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/paypal_adaptive-0.2.6/lib/paypal_adaptive/config.rb:26:in`initialize'
/Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/paypal_adaptive-0.2.6/lib/paypal_adaptive/request.rb:12:in `new'
/Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/paypal_adaptive-0.2.6/lib/paypal_adaptive/request.rb:12:in`initialize'

I am attempting to do payments in a rake task so I can run this on Heroku as a scheduled task. My question is why does error occur? I am looking at the code and I don't see a Rails const declared at least till later in the file.

SIDEBAR: Also why does this application need to be so tied to Rails? The way its written and developed I see no reason other then paypal postback, which could be a separate project in my opinion. Even the config could be more generic. I suppose I could just fork it and make a pull request :S

Parameters filtered in log

When receiving an IPN, I observe that some parameters are filtered from the Rails log:

"transaction"=>{"0"=>{
  ".is_primary_receiver"=>"[FILTERED]", 
  ".id_for_sender_txn"=>"redacted", 
  ".receiver"=>"[FILTERED]", 
  ".amount"=>"USD 1.23", 
  ".refund_id"=>"redacted", 
  ".status"=>"Partially_Refunded", 
  ".id"=>"redacted", 
  ".refund_amount"=>"USD 0.30", 
  ".refund_account_charged"=>"redacted", 
  ".status_for_sender_txn"=>"Partially_Refunded", 
  ".paymentType"=>"SERVICE", 
  ".pending_reason"=>"NONE"
}},
...
"pay_key"=>"[FILTERED]", 
"preapproval_key"=>"[FILTERED]", 

I have not explicitly filtered these parameters in my application (using config.filter_parameters); what has configured these to be filtered?

Problem with rails3.1 and HashWithIndifferentAccess

I noticed the following bug while testing...

In my controller I have a variable: pay_response which should be instance PaypalAdaptive::Response object
pre-rails3.1, the test:

assigns(:pay_response).should be_a(PaypalAdaptive::Response)

passes

in rails 3.1.1 it fails because

assigns(:pay_response).class == HashWithIndifferentAccess

this is because in test_process.rb:

def assigns(key = nil)
  assigns = @controller.view_assigns.with_indifferent_access
  key.nil? ? assigns : assigns[key]
end

now recursively converts all hash's to HWIA, and when it converts subclasses of HWIA, it discards the subclass and just makes it HWIA.

So, the workaround:

module PaypalAdaptive
  class Response
    def nested_under_indifferent_access
      self
    end
  end
end

See these links:

rails/rails#454 and
dlee/rails@099eb2b

Do we receive multiple IPNs for the same payment when payment status is updated?

I am new to paypal integration and am trying to better understand how IPN works. For simplicity, say I make a payment to some person using the adaptive payment API.

The documentation says I receive an IPN after making that 'Pay' API call. The IPN has the payment status (which could be 'created', 'pending', etc...) in it.

My question is: Do I receive more IPNs in the future related to the same payment whenever the status of the payment is updated in paypal's end? So, if a payment goes from 'pending' to 'completed' in paypal's servers, can I expect to receive an IPN describing that update with the same pay key used for the first IPN?

RuntimeError (Could not load settings from config file):

I'm trying to deploy a Rails 3.0.11 app using this gem on Heroku. Locally it runs fine and I can interact with the sandbox accounts as expected. However, even though I use identical credentials in my paypal_adaptive.yml for both production: and development:, on heroku I get the error RuntimeError (Could not load settings from config file): when I call PaypalAdaptive::Request.new

One thing worth mentioning is that I make no reference in paypal_adaptive.yml to the ssl_cert_file: but I understand this means it defaults to the one bundled.

Any ideas?

The amount is invalid

I am receiving this error in my log console:

I am working in http://localhost:3000/

The amount is invalid

I have in my controller:

def pay
 pay_request = PaypalAdaptive::Request.new
     data = {
       "returnUrl" => user_orders_url(current_user),
       "requestEnvelope" => {"errorLanguage" => "en_US"},
       "currencyCode" => "USD",
       "receiverList" =>
               { "receiver" => [
                 {"receiver"=> [{"email"=>"email1", "amount"=>"10.00", "primary" => true}, {"email"=>"email2", "amount"=>"9.00", "primary" => false}]}
               ]},
       "cancelUrl" => user_orders_url(current_user),
       "actionType" => "PAY",
       "ipnNotificationUrl" => ipn_notification_user_orders_url(current_user)
     }
     pay_response = pay_request.pay(data)

     if pay_response.success?
         # Send user to paypal
         redirect_to pay_response.preapproval_paypal_payment_url
     else
         puts pay_response.errors.first['message']
         redirect_to root_url, alert: "Something went wrong. Please contact support."
     end
end

What am I doing bad?

Accessing the response variables

I'm not sure if I'm getting confused, but I'm struggling to access attributes of Paypal response in a clean way

Eg
ipn = PaypalAdaptive::IpnNotification.new
ipn.send_back(env['rack.request.form_vars'])
if ipn.verified? #do some stuff.

But then if I want to know about the "status" attribute, I have to call
params["status"].

This seems wrong? Shouldn't I be able to access the attributes through the ipn object?

Get information about payment status

Hi, I wonder if there is possibility to get information about status payment :

for example:

Client chose some product, go to paypal, pay for that and there is problem with connection on server and paypal can't send information about status of payment.
Then let say that problem is solved and I would like to ask paypal about this transaction, and get answer about if user paid for those products.

How I can do that using this plugin ?

Thanks a lot for help

Getting error message "Invalid request: {0}"

Hello,

I am getting error response {"responseEnvelope"=>{"timestamp"=>"2014-01-13T03:36:10.038-08:00", "ack"=>"Failure", "correlationId"=>"a668cb42ba8d5", "build"=>"7935900"}, "error"=>[{"errorId"=>"580001", "domain"=>"PLATFORM", "subdomain"=>"Application", "severity"=>"Error", "category"=>"Application", "message"=>"Invalid request: {0}"}]}

I have run the following code

data = {
  "returnUrl" => root_url, 
  "requestEnvelope" => {"errorLanguage" => "en_US"},
  "currencyCode"=>"USD",  
  "receiverList"=> { "receiver"=>[{ "email"=>self.paypal_email, "amount"=> self.amount}]},
  "cancelUrl"=>root_url,
  "actionType"=>"CREATE",
  "ipnNotificationUrl"=>root_url,
  "startingDate" => DateTime.now
}
preapproval = pay_request.preapproval(data)
pay_response = pay_request.pay(data)
self.pay_key = pay_response["payKey"]
self.paypal_status = "Payed"
execute_payment = pay_request.execute_payment(pay_response["payKey"])

Please help me out from this...

Thanks in advance

new Client ID

Now the paypal moved the x.com to paypal developers and the turn the application_id to client_id to live app.
since then the adaptive on production mode did not work anymore. anyone with the same issue?

log!

i would like to know if have a way to see the fail log on adptative gem. thank's

PaypalAdaptive is broken under Ruby 1.9.3

citadela:paypal_adaptive deepj$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

citadela:paypal_adaptive deepj$ rake test
Run options: 

# Running tests:

...-------
get shipping addresses
E........EEE...-------
chain
E-------
parallel
E-------
simple
E-------
payment details
E-------
set payment options
E-------
invalid
E-------
invalid
E-------
valid test
{"returnUrl"=>"http://127.0.0.1:3000/payments/completed_payment_request", "requestEnvelope"=>{"errorLanguage"=>"en_US"}, "currencyCode"=>"USD", "cancelUrl"=>"http://127.0.0.1:3000/payments/canceled_payment_request", "maxTotalAmountOfAllPayments"=>"1500.00", "maxNumberOfPayments"=>"30", "startingDate"=>"2020-07-13T07:00:00.000Z", "endingDate"=>"2020-12-13T07:00:00.000Z"}
E

Finished tests in 14.331456s, 1.8142 tests/s, 0.5582 assertions/s.

  1) Error:
test_get_shipping_addresses(GetShippingAddressesTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/get_shipping_addresses_test.rb:19:in `test_get_shipping_addresses'

  2) Error:
test_invalid_chain_pay(PayRequestTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/pay_request_test.rb:50:in `test_invalid_chain_pay'

  3) Error:
test_invalid_parallel_pay(PayRequestTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/pay_request_test.rb:71:in `test_invalid_parallel_pay'

  4) Error:
test_invalid_simple_pay(PayRequestTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/pay_request_test.rb:25:in `test_invalid_simple_pay'

  5) Error:
test_valid_chain_pay(PayRequestTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/pay_request_test.rb:36:in `test_valid_chain_pay'

  6) Error:
test_valid_parallel_pay(PayRequestTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/pay_request_test.rb:62:in `test_valid_parallel_pay'

  7) Error:
test_valid_simple_pay(PayRequestTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/pay_request_test.rb:15:in `test_valid_simple_pay'

  8) Error:
test_payment_details(PaymentDetailsTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/payment_details_test.rb:18:in `test_payment_details'

  9) Error:
test_payment_options(PaymentOptionsTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:29:in `pay'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/payment_options_test.rb:19:in `test_payment_options'

 10) Error:
test_invalid_preapproval(PreapprovalTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:49:in `preapproval'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/preapproval_test.rb:31:in `test_invalid_preapproval'

 11) Error:
test_invalid_preapproval_with_bad_credit_information(PreapprovalTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:49:in `preapproval'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/preapproval_test.rb:45:in `test_invalid_preapproval_with_bad_credit_information'

 12) Error:
test_preapproval(PreapprovalTest):
TypeError: can't convert nil into String
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:90:in `post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:75:in `wrap_post'
    /Users/deepj/dev/oss/paypal_adaptive/lib/paypal_adaptive/request.rb:49:in `preapproval'
    /Users/deepj/dev/oss/paypal_adaptive/test/unit/preapproval_test.rb:16:in `test_preapproval'

26 tests, 8 assertions, 0 failures, 12 errors, 0 skips
rake aborted!
Command failed with status (12): [/Users/deepj/.rvm/rubies/ruby-1.9.3-p0/bin...]

Tasks: TOP => test => test:units
(See full trace by running task with --trace)

In my test and application PaypalAdaptive::Request.pay returns the same error under Ruby 1.9.3, Ruby 1.9.2 is okay.

Support for ruby 2.0

Is this compatible with ruby 2.0? We tested it, it seems fine but just wondering if there's anything we should be aware of.

add embedded payments url support

Change response.rb approve_paypal_payment_url method

def approve_paypal_payment_url(type=nil)
  if self['payKey'].nil?
    return nil
  elsif type == "embedded"
    "https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=#{self['payKey']}"
  else
    "#{@@paypal_base_url}/webscr?cmd=_ap-payment&paykey=#{self['payKey']}"
  end
end

or it could be setup in the config.yml file to set @@paypal_base_url

Rake dependency and Rails 3

The dependency from rake ~>0.8 makes rubygems select and install version 2.2 of the gem with latest version or Rails. Version 2.2 is selected because it's the latest version that doesn't specify a version for the rake depedency.

As you can notice all the latest forks make the same change updating rake dependecy version or removing it.

Possible solutions:

  1. update rake dependency version to >=0.8
  2. remove rake dependency version

IPN Failure

While the gem is almost fully working - I can get to Paypal's screen, input sandbox info and pay, the payment goes through in the sandbox, I get redirected to my website and Paypal attempts to deliver the IPN, which shows all of the correct info.

I need some assistance figuring out why the IPN info isn't being received, and since I'm a relatively new programmer, I wouldn't doubt it is likely something simple I'm overseeing.

I'm using RESTful routing:

resources :projects, :only=> [:index, :new, :create, :show] do
collection do
...
get 'thank_you'
post 'confirm'
get 'cancel'
end
member do
...
put 'pay'
end

My project controller looks like the following:

def Pay
...
request = PaypalAdaptive::Request.new

    data = {
      :returnUrl => url_for(:action => 'thank_you', :id => backer.key, :only_path => false),
      :requestEnvelope => {"errorLanguage" => "en_US"},
      :currencyCode => "CAD",
      :memo => "filled'",
      :receiverList => {filled...
      :feesPayer => "SECONDARYONLY",
      :cancelUrl => "http://localhost:3000/canceled_payment_request",
      :actionType => "PAY_PRIMARY",
      :ipnNotificationUrl => url_for(:action => 'confirm', :id => backer.key, :only_path => false)
    }
    response = request.pay(data)

    if response.success?         
      redirect_to response.approve_paypal_payment_url
    else
      flash[:failure] = t('projects.pay.paypal_error')
      return redirect_to back_project_path(backer.project)
    end
  end

def thank_you
unless session[:thank_you_id]
flash[:failure] = t('projects.thank_you.error')
return redirect_to :root
end
@project = Project.find session[:thank_you_id]
@title = t('projects.thank_you.title')
session[:thank_you_id] = nil
end

user is sent here from PayPal when if they cancel

def cancel
flash[:failure] = t('projects.pay.paypal_error')
redirect_to redirect_to back_project_path(backer.project)
end
def confirm
key = params[:id]
status = params[:payment_status]
value = params[:mc_gross]
backer = Backer.find_by_key key

Checks the status of the payment

return render :nothing => true, :status => 200 if status != 'Completed'
return render :nothing => true, :status => 200 if backer.confirmed

Checks that the value is the correct amount

return render :nothing => true, :status => 422 if backer.moip_value != value

Need something to check that the receiver email address is ours!!!

receiver_email ... ? can make a param

Confirms the backer

backer.confirm!
return render :nothing => true, :status => 200

rescue => e
return render :nothing => true, :status => 422
end

My paypal_adaptive.yml uses the signature but not the certs
And everything else was left as it was when I downloaded it.

From my understanding this should still have it working from all of the posts I've read, or am I missing something?

Huge thanks in advance!

getting Internal Error for trying to refund

Hi, I have used this like so:

pp = PaypalAdaptive::Request.new("staging")

refund_data =  {
          receiverList:           {receiver: [amount:50]},
          requestEnvelope:        {errorLanguage: 'en_US', detailLevel: 'ReturnAll'},
          currencyCode:           'USD',
          transactionId:          "3LB17176J1579470G"
      }

pp.refund(refund_data)

the result is:

{"responseEnvelope"=>{"timestamp"=>"2014-01-29T04:43:15.462-08:00", 
"ack"=>"Failure", "correlationId"=>"64008dca7cba5", "build"=>"7935900"}, 
"error"=>[{"errorId"=>"520002", "domain"=>"PLATFORM",
 "subdomain"=>"Application", "severity"=>"Error", 
"category"=>"Application", "message"=>"Internal Error"}]}

Getting OpenSSL::SSL::SSLError on staging machine with existing SSL protection

Hi -- we have submitting a payment working on a development machine (well, taking us to the sandbox to login, which is as far as we've tested). This development machine is running with HTTPS.
However, when we try to run the same code on a staging server that has a valid SSL certificate in place, and so uses HTTPS for the actions to do with paying for orders, we get the following error:

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
/usr/lib/ruby/1.8/net/http.rb:586:in connect' /usr/lib/ruby/1.8/net/http.rb:586:inconnect'
/usr/lib/ruby/1.8/net/http.rb:553:in do_start' /usr/lib/ruby/1.8/net/http.rb:542:instart'
/usr/lib/ruby/1.8/net/http.rb:1035:in request' /usr/lib/ruby/1.8/net/http.rb:845:inpost'
/var/lib/gems/1.8/gems/paypal_adaptive-0.2.7/lib/paypal_adaptive/request.rb:88:in post' /var/lib/gems/1.8/gems/paypal_adaptive-0.2.7/lib/paypal_adaptive/request.rb:75:inwrap_post'
/var/lib/gems/1.8/gems/paypal_adaptive-0.2.7/lib/paypal_adaptive/request.rb:29:in pay' /app/controllers/orders_controller.rb:63:inpay'

Could you possibly advise us as to where we should look, next?
We have the correct values filled in in our paypal_adaptive.yml config file, and have downloaded the key from paypal.
My guess is that the SSL certificates are clashing, or that maybe I need to register our certificate with paypal somewhere?
Sorry to bug you with this, by the way, we've been hacking it together all day (getting it to work with a Rails 2.1 app), and could really use a little guidance, if possible.
Thanks,
Doug.

json dependency issue

When I installed the paypal_adaptive gem the json dependency didn't seem to be met.

Got this error, when executing rake -T

no such file to load -- json

paypal_adaptive in model

I'm thinking it might be more flexible to have this library as an extension to a model. Generally, when I'm sending paypal payments I want to save that event in my database, so why not have the model aware of how to send payments?

I'm going to work on an implementation.

Anybody else interested in such a conversion?

Paypal adaptive locks down json version, causes conflicts with more recent gems

I noticed in the gemspec, you use pessimistic version control of json to ~>1.6.0. This causes a conflict with me specifically with the desk gem(desk.com api wrapper) which requires json >= 1.7.5.

Do you have a specific reason to lock down to this json version? If not, I say use ~>1.0 so that everything up to json 2.0 would be supported.

What do you think?

Getting "Connection Reset. Request invalid URL."

I installed the gem few days ago and am trying to make a payment. But all I get is this error "Connection Reset. Request invalid URL.".

I've setup the paypal_adaptive.yml, only I can't see where I get my app_id from. The sandbox test site doesn't show anything like app_id in API credentials.

The code looks like this:

payout = Payout.find(params[:id])
# hook this up to paypal

data = {
   "returnUrl"       => URI.join(root_url, payment_successful_admin_payout_path(payout.id)), 
  "requestEnvelope" => {"errorLanguage" => "en_US"},
  "currencyCode"    => payout.currency_code,
  "receiverList"    => {
    "receiver"=>[
      {"email" => payout.destination_account, "amount"=> payout.amount}
    ]},
  "cancelUrl"       =>  URI.join(root_url, payment_canceled_admin_payout_path(payout.id)),
  "actionType"      =>  "PAY",
  "ipnNotificationUrl" => URI.join(root_url, instant_payment_notification_payout_path(payout.id))
}

require 'pp'
pp data

pay_request = PaypalAdaptive::Request.new
pay_response = pay_request.pay(data)

if pay_response.success?
  redirect_to pay_response.approve_paypal_payment_url
else
  p pay_response.errors.first['message']
  p pay_response.errors
  p pay_response
  problem = pay_response.errors.first['message']
  #begin
  #  raise problem
  #rescue
  #  Exceptional.handle $!
  #end
  flash[:error] = problem
  redirect_to admin_payout_path
end

And the output of 'data' variable is:

{"returnUrl"=>
  #<URI::HTTP:0x000000079d6ac8 URL:http://localhost:3000/admin/payouts/1/payment_successful>,
 "requestEnvelope"=>{"errorLanguage"=>"en_US"},
 "currencyCode"=>"GBP",
 "receiverList"=>
  {"receiver"=>[{"email"=>"[email protected]", "amount"=>100}]},
 "cancelUrl"=>
  #<URI::HTTP:0x000000079da628 URL:http://localhost:3000/admin/payouts/1/payment_canceled>,
 "actionType"=>"PAY",
 "ipnNotificationUrl"=>
  #<URI::HTTP:0x000000079dd328 URL:http://localhost:3000/payouts/1/instant_payment_notification>}

I've also tried the plain NVP paypal gem and the result us the same .. Its loading for a minute or so and then I get the same error.

I think this is not the gem's fault, but maybe the documentation could cointain a little more info on common pitfalls or if some errors in data hash can be detected, and exception or a warning would be useful.

I am greateful for any help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.