Giter Site home page Giter Site logo

paypal-recurring's Introduction

PayPal Recurring Billing

PayPal Express Checkout API Client for recurring billing.

Installation

gem install paypal-recurring

Usage

First, you need to set up your credentials:

require "paypal/recurring"

PayPal::Recurring.configure do |config|
  config.sandbox = true
  config.username = "seller_1308793919_biz_api1.simplesideias.com.br"
  config.password = "1308793931"
  config.signature = "AFcWxV21C7fd0v3bYYYRCpSSRl31AzaB6TzXx5amObyEghjU13.0av2Y"
end

Then, you can request a new payment authorization:

ppr = PayPal::Recurring.new({
  :return_url   => "http://example.com/paypal/thank_you",
  :cancel_url   => "http://example.com/paypal/canceled",
  :ipn_url      => "http://example.com/paypal/ipn",
  :description  => "Awesome - Monthly Subscription",
  :amount       => "9.00",
  :currency     => "USD"
})

response = ppr.checkout
puts response.checkout_url if response.valid?

You need to redirect your user to the url returned by response.checkout_url. After the user accepts or rejects your payment request, he will be redirected to one of those urls you specified. The return url will receive two parameters: PAYERID and TOKEN. You can use the TOKEN parameter to identify your user on your database.

If you need to retrieve information about your buyer, like address or e-mail, you can use the checkout_details() method.

ppr = PayPal::Recurring.new(:token => "EC-05C46042TU8306821")
response = ppr.checkout_details

Now, you need to request payment. The information you provide here should be exactly the same when you started the checkout process.

ppr = PayPal::Recurring.new({
  :token       => "EC-05C46042TU8306821",
  :payer_id    => "WTTS5KC2T46YU",
  :amount      => "9.00",
  :description => "Awesome - Monthly Subscription"
})
response = ppr.request_payment
response.approved?
response.completed?

Finally, you need to create a new recurring profile.

ppr = PayPal::Recurring.new({
  :amount      => "9.00",
  :currency    => "USD",
  :description => "Awesome - Monthly Subscription",
  :ipn_url     => "http://example.com/paypal/ipn",
  :frequency   => 1,
  :token       => "EC-05C46042TU8306821",
  :period      => :monthly,
  :reference   => "1234",
  :payer_id    => "WTTS5KC2T46YU",
  :start_at    => Time.now,
  :failed      => 1,
  :outstanding => :next_billing
})

response = ppr.create_recurring_profile
puts response.profile_id

(Optionally) You can specify a trial period, frequency, and length.

ppr = PayPal::Recurring.new({
  :amount          => "9.00",
  :currency        => "USD",
  :description     => "Awesome - Monthly Subscription",
  :ipn_url         => "http://example.com/paypal/ipn",
  :frequency       => 1,
  :token           => "EC-05C46042TU8306821",
  :period          => :monthly,
  :reference       => "1234",
  :payer_id        => "WTTS5KC2T46YU",
  :start_at        => Time.now,
  :failed          => 1,
  :outstanding     => :next_billing,
  :trial_length    => 1,
  :trial_period    => :monthly,
  :trial_frequency => 1
})

You can manage your recurring profile.

ppr = PayPal::Recurring.new(:profile_id => "I-VCEL6TRG35CU")

ppr.suspend
ppr.reactivate
ppr.cancel

What information do I need to keep?

You should save two paramaters to your database: TOKEN and PROFILEID. TOKEN is required when user returns to your website after he authorizes (or not) the billing process. You need to save it so you can find him later. You can remove this info after payment and recurring profile are set.

The PROFILEID allows you to manage the recurring profile, like cancelling billing when an user don’t want to use your service anymore.

NOTE: TOKEN will expire after approximately 3 hours.

Maintainer

License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

paypal-recurring's People

Contributors

fnando avatar jhliberty 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  avatar

paypal-recurring's Issues

Brief Express Checkout Flow

Hey,

Based on this image

recurringpaymentsflowux

Can you give a brief explanation step by step about what your code does accordingly to each flow step? It would be much easier to understand and it would be a massive help in your readme file.

Kudos,
Tiago Sousa

Pass "custom" within options of PayPal::Recurring.new(options)

Hi fnando,

This is my code:

def process(action, options = {})
options = options.reverse_merge(
token: @subscription.paypal_payment_token,
payer_id: @subscription.paypal_customer_token,
description: "Description for payment plan #{@subscription.plan.batch}",
amount: @subscription.plan.price,
currency: "USD"
)
response = PayPal::Recurring.new(options).send(action)
raise response.errors.inspect if response.errors.present?

response

end

I tried to put "custom" within the above options scope, i.e:
options = options.reverse_merge(
...
custom: "...Some thing..."
)

But PayPal::Recurring display system errors.

Reference:
1> http://stackoverflow.com/questions/1364360/testing-paypal-subscription-ipn
2> https://www.paypal.com/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside
3> http://railscasts.com/episodes/289-paypal-recurring-billing

Thank you in advance,
Dat

Coupon Code

Hi there!
what is reference in the parameters while creating profile?

thanks,

How to find out if the trial is still going on?

I see I can see the profile details but not the recurring.rb attributes, whish is where the trial length is. I had a customer with a 15-day trial and I tried finishing the trial early by setting trial_length to 0 and then checking out the "remaining" cycles, however, this still returned the days until the original trial was supposed to end. How can I figure out if the customer is still in trial?

Thanks

How to to encrypt parameters sent to Paypal ?

Here is my usage to the paypal-recurring gem in the checkout code:

ppr = PayPal::Recurring.new(
      return_url: new_subscription_url(:plan_id=>plan_id, :accounts_number => accounts_number),
      cancel_url: root_url,
      description: description,
      amount: price,
      currency: "USD"
    )

But, how to send parameters above encrypted to Paypal ?
I tried to encrypt them like this:

ppr = PayPal::Recurring.new(
      cmd: '_s-xclick',
      encrypted: paypal_encrypted(new_subscription_url(:plan_id=>plan_id, :accounts_number => accounts_number), root_url)
    )

But, I got this error:

undefined method `cmd=' for #<PayPal::Recurring::Base:0xbf9e4fc>

Any idea ?

How to use this gem for Rails4

Thank you fnando for great gem.

I was using this on Rails3 and it worked just fine.

After install this gem for Rails4, and provide config/initializer/paypal.rb, we had this error:

/config/initializers/paypal.rb:3:in <top (required)>': uninitialized constant Paypal (NameError) from /Users/danbrown/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0/lib/rails/engine.rb:648:inblock in load_config_initializer'
from /Users/danbrown/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.1.0/lib/active_support/notifications.rb:161:in instrument' from /Users/danbrown/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0/lib/rails/engine.rb:647:inload_config_initializer'

Payflow payment integration in ruby on rails

I'm using paypal for payment and here is main function and parameters which are used for payment.

def self.paypal_url(.....)
values = {
:business => '[email protected]',
:cmd => 'cart',
:upload => 1,
:return => return_url,
:invoice => "#{customer.id}#{sType.id}_#{Time.now}",
:notify_url => notify_url
}
values.merge!({
"amount_1" => amount,
"item_name_1" => sType.show_title,
"discount_amount_1" => discount

"quantity_1" => '1'

})
"https://www.paypal.com/cgi-bin/webscr?" + values.to_query
end
But now i want to use PayFlow. Kindly guide me which parameter i have to change and what will be the final url as for payment is "https://www.paypal.com/cgi-bin/webscr?" + values.to_query.

Kindly guide me.

Guest account support

Any way to enable guest account support, so that a Paypal account isn't required? I already have PayPal Account Optional enabled in my Paypal account and I'm still prompted to create a Paypal account if I don't already have one.

Rails 2.3.18, Profile id is Nil

Hey Guys,

Payment getting success but Profile ID not generating. I also tried to downgrade this gem version but same result. but the same code works in Rails 4

Note: I am using Rails 2.3.18 and Ruby 1.9.3

Modify profile

Hi Fernando, at first, thank you for your great work shared with us.

I was wondering if its possible (and how) to modify PayPal subscriptions.

Using you method update to change a user's plan, PayPal troughs an error that a profile can only get 20% raising price in a 180 days period. But I know that PayPal has the Modify button.

Can you share how to handle this scenario with your gem?

Thank you.

What is the difference between trial_length and trial_frequency?

I want to create a monthly subscription with a 5 month trial. Does this do the job?

ppr = PayPal::Recurring.new(
  token: paypal_payment_token,
  payer_id: paypal_customer_token,
  description: "#{plan.name} Monthly Subscription- Up to #{plan.listing_limit} listings for #{self.repository.name}.",
  amount: plan.amount,
  currency: "USD",
  period: :monthly,
  trial_length: 5,
  trial_period: :monthly,
  start_at: Time.now,
  failed: 1,
  outstanding: :next_billing
)

initial payment always executed

hi ,
just a question:

paypal-recurring always sets an initial payment or is just paypal executing always an initial payment ?

its because is set an start date in checkout request to 1 month from now, but in the creation of profile it always execute a payment

thanks

Recurring method tip

Maybe this is implied, but I think you should add this line in your documentation

puts response.success?

when creating the actual recurring profile. This gives back a true or false if the recurring profile was successfully completed.

Cancel or suspend?

To stop recurring payment what should I use - cancel or suspend? I couldn't understand from the code and the guide

IPN request handling?

Hello, at first, I would like to say thank you for this gem.

But I have one problem/question... how I should handle automatic recurring IPN requests?
I currently call .valid? and .recurring_payment? on the request, but .valid? returns false...
Version currently used is 0.1.6.

Started POST "/paypal/ipn" for 173.0.81.1 at 2012-09-02 19:08:11 +0200
Processing by PaymentsController#ipn as HTML
  Parameters: {"mc_gross"=>"1200.00", "period_type"=>" Regular", "outstanding_balance"=>"0.00",
  "next_payment_date"=>"03:00:00 Oct 02, 2012 PDT", "protection_eligibility"=>"Ineligible", "payment_cycle"=>"Monthly", "tax"=>"0.00", "payer_id"=>"[removed]", "payment_date"=>"10:07:51 Sep 02, 2012 PDT", "payment_status"=>"Completed", "product_name"=>"P\u001Aedplatn\xE9 pro 15000 adres", 
"charset"=>"windows-1252", "recurring_payment_id"=>"[removed]", "first_name"=>"[removed]", "mc_fee"=>"62.80", "notify_version"=>"3.6", "amount_per_cycle"=>"1200.00", "payer_status"=>"verified", "currency_code"=>"CZK", "business"=>"[removed]", "verify_sign"=>"[removed]", "payer_email"=>"[removed]",
"initial_payment_amount"=>"0.00", "profile_status"=>"Active", "amount"=>"1200.00", "txn_id"=>"[removed]",
"payment_type"=>"instant", "payer_business_name"=>"[removed]", "last_name"=>"[removed]",
"receiver_email"=>"[removed]", "payment_fee"=>"", "receiver_id"=>"[removed]",
"txn_type"=>"recurring_payment", "mc_currency"=>"CZK", "residence_country"=>"CZ",
"transaction_subject"=>"...", "payment_gross"=>"", "shipping"=>"0.00", "product_type"=>"1",
"time_created"=>"03:09:02 Jun 02, 2012 PDT", "ipn_track_id"=>"[removed]"}
    response = PayPal::Recurring::Notification.new(params)
    logger.info "completed?: #{response.completed?}"
    logger.info "verified?: #{response.verified?}"
    logger.info "valid?: #{response.valid?}"
    logger.info "amount: #{response.amount.inspect}" if response.respond_to?(:amount)
    logger.info "raw params: #{response.params.inspect}"
logger output:
completed?: true
verified?: true
valid?: false

Am I doing this right? Thanks in advance.

Unable to perform transaction for Multiple Items

I have tried to use gem for multiple item purchase, but i din't find any way to implement with this gem.

options = options.reverse_merge(
token: @subscription.paypal_payment_token,
description: @subscription.package_plan.description,
payer_id: @subscription.paypal_customer_token,
frequency: @subscription.package_plan.recurring_frequency,
item_name: @subscription.package_plan.name,
item_quantity: 1,
item_amount: @subscription.package_plan.price * @subscription.package_plan.recurring_frequency,
item_name: @subscription.package_add_ons.first.name,
item_quantity: 1,
item_amount: @subscription.package_add_ons.first.price * @subscription.package_plan.recurring_frequency,
amount: @subscription.package_plan.price * @subscription.package_plan.recurring_frequency,
currency: @subscription.package_plan.currency
)

Considers only one item..

Specifying total number of cycles

Example:
I'm subscribing for 12 months.
I'm telling Paypal that the period is monthly, but I currently can't tell Paypal to stop after 12 cycles. Would it be possible to implement this option?

Thanks!

start_at when creating recurring profile

When creating the recurring profile, I assumed that start_at would be Time.now. This causes a double charge with PayPal: the initial checkout charge, and the first payment for the recurring profile.

The start_at should be the date that the first recurring payment should be taken eg. a month from now if your frequency is monthly.

Could the docs be updated to reflect this as it's not explicit?

undefined method

undefined method `trial_period=' for #PayPal::Recurring::Base:0x00000129a98830

Paypal notification for cancel recurring payment.

Hi fnando,

We are able to cancel Paypal recurring profile by using your code as below:

ppr = PayPal::Recurring.new(:profile_id => "I-8260FSSRY1MW")
response2=ppr.cancel

Based on response2.response status, we are able to determine whether cancel is OK or FAILURE.

The issue is,
if user (customer) cancel their Recurring-Profile by using their PayPal account, we do not receive any notifcation ?

P/S:
For more information, we had setup IPN URL successfully when user create their Recurring profile.
But this IPN URL is not being triggered when user cancel Recurring Profile on PayPal system.

Is there any issue at here?

Thank you and best regards,
Dat

Use it without sandbox

How can I use the gem without the option of sandbox?

I would like to use it in production.

Thanks.

Samples require for IPN callback

I am able to make recurring profile successfully. Now we want to receive IPN notification on each successful/failure payment made on the billing date.

I have already posted it on paypal/ipn-code-samples#36 but I thought this is right place to ask for help.

Trial amount not considered

Hey,
I'm following the tutorial from RailsCasts and I have no error. But the difference is that I need to add a trial period:
Monthly fee: 7000yen
First month (trial): 6000yen

Here is my code in PaypalPayment.rb

  def make_recurring
    process :request_payment
    process :create_recurring_profile, 
      period: @subscription.plan.period,
      frequency: @subscription.plan.frequency,
      trial_frequency: @subscription.plan.trial_frequency,
      trial_length: @subscription.plan.trial_cycle,
      trial_period: @subscription.plan.trial_period,
      trial_amount: @subscription.plan.trial_amount,
      start_at: Time.zone.now
  end

private

  def process(action, options = {})
    options = options.reverse_merge(
      token: @subscription.paypal_payment_token,
      payer_id: @subscription.paypal_customer_token,
      description: @subscription.plan.name,
      amount: @subscription.plan.amount,
      currency: @subscription.plan.currency
    )
    response = PayPal::Recurring.new(options).send(action)
    raise response.errors.inspect if response.errors.present?
    response
  end

When the user complete the subscription, in "My recent activity" on the Paypal website I can see 2 things:

  1. 2 lines are added:
    2012 Nov 2 | Recurring Payment To | Seller X's Test Store | Created | ...
    2012 Nov 2 | Payment To | Seller X's Test Store | Completed | -¥7,000 JPY

  2. If I click on "Details" for the first line, I can see:
    Trial Period ¥6,000 JPY 1 1 Monthly
    Regular Recurring Payment ¥7,000 JPY indefinite indefinite Monthly

So my question is why the "completed" transaction was not 6000yen ?

Show amount during checkout

I implemented paypal-recurring according to the recent Railscast about it. Everything works except that the amount the user is setting up the recurring profile for is not shown.
I checked that the amount parameter is sent to Paypal when initiating the checkout action. Am I missing something?

How do I know when paypal recurring payment failed?

I'm new using paypal api and this gem, how can I check if paypal payment is approved or not to suspend subscription? I need to check this by myself?

Thanks a lot :)

EDIT:

ipn_url isn't working on PayPal::Recurring.new, it only redirects to return_url when user approves the payment.

Initial payment request then create profile?

Why do we request an express checkout payment initially and then create a recurring profile that does nothing for a month? Can we not have this initial payment processed as part of the recurring profile and omit the trails period etc. all together?

Im sure there must be a reason for this? The recurring profile created on PayPal could be confusing to some users as it shows a trial period and 0 value initial payment.

How to Setup PayPal's IPN

I have seen many questions concerning this, and I am having issues understanding this too. Can someone share how they were able to setup paypal notifications?

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.