chargebee / chargebee-ruby Goto Github PK
View Code? Open in Web Editor NEWRuby library for the Chargebee API.
Home Page: https://apidocs.chargebee.com/docs/api?lang=ruby
License: MIT License
Ruby library for the Chargebee API.
Home Page: https://apidocs.chargebee.com/docs/api?lang=ruby
License: MIT License
Recently, you guys added the Chargebee::Entitlements model, but I think you forgot to include it in lib/chargebee.rb
so it's callable.
Hello,
Why is there a downgrade of the rest-client gem? Your commit message is empty...
Please clarify the motivation and fix this in order to use the latest version. It is important to use always the latest gem version to avoid bugs and security issues.
As latest browser versions are removing the support for SSL Certificates signed with SHA1, we will be updating our SSL Certificate to SHA256 hash algorithm on Dec 16th, 2015, to improve application security.
So if you are using Chargebee API, please make sure that you are using the latest certificate bundles when accessing Chargebee as a client.
What is the reason for holding back the json_pure version?
If it's to support older versions of ruby, someone in that situation can deal with that by holding the version back themselves in their own Gemfile.
Hi there.
I might be missing something but I'm fighting with this bug when creating a simple subscription as stated in the doc here. Any idea on this?
ChargeBee::IOError: IO Exception when trying to connect to chargebee with url https://snapshift-test.chargebee.com/api/v2/subscriptions . Reason undefined method
[]' for #<Set: {#<MIME::Type: application/json>}>`
The following test is failing on master:
rspec spec
F.......
Failures:
1) ChargeBee::ListResult returns list object, with next offset attribute
Failure/Error: list.next_offset.should =~ ["1345724673000", "1510"]
expected: ["1345724673000", "1510"]
got: "[\"1345724673000\", \"1510\"]" (using =~)
# ./spec/chargebee/list_result_spec.rb:51:in `block (2 levels) in <top (required)>'
Hey all,
I'm getting the following error after hitting the invoice.sync_usages:
{
"message":"This API operation is not enabled for this site. Please contact [email protected] to get this enabled",
"api_error_code":"configuration_incompatible",
"error_code":"api_restricted",
"error_msg":"This API operation is not enabled for this site. Please contact [email protected] to get this enabled",
"http_status_code":400
}
There is nothing about this endpoint being a special endpoint in the documentation https://apidocs.chargebee.com/docs/api/invoices?prod_cat_ver=2&lang=curl#sync_usages so I was wondering if I'm using it wrong or missing something else?
When executing ChargeBee::Subscription.retrieve(subscription_id).subscription.as_json
The following error occurs
Response not in JSON format. Probably not a ChargeBee response
"\u001F\x8B\b\u0000\u0000\u0000\u0000\u0000
The recent changes in the UI allowed users to insert custom attributes with spaces.
This is causing a bug in the API.
::ChargeBee::Customer.retrieve('test-custome-id', environment).customer
NameError: `@cf_my My customer field' is not allowed as an instance variable name
from /usr/local/bundle/gems/chargebee-2.31.1/lib/chargebee/models/model.rb:39:in `instance_variable_set'
I am using the 2.10 version and I can confirm that my product catalog is using version 2.0. However, I am getting the following error "This API operation is not enabled for this site. Please contact [email protected] to get this enabled (ChargeBee::APIError)" for requests such as ChargeBee::Plan.list.
Any suggestions on moving forward? Thanks!
Using v2.6.5.
There's a ChargeBee::Error
class but this code does not handle all exceptions so RestClient::BadRequest
squeaks through.
The exception is not documented (as most Ruby libs and their exceptions aren't) but it and others are placed into the RestClient::Exceptions::EXCEPTION_MAP
constant.
No JSON exceptions are caught here.
There's probably more but that's what I've seen so far.
Also note that RESTClient seems dead. But, maybe that's okay.
Hi there,
I've found a bug in Chargebee Gem (1.4.6), where the offset parameter is being ignored when called in the ChargeBee::Customer.list({:limit => limit, :offset => offset}) function. Where limit is an int and offset is returned from a previous call to ChargeBee::Customer.list().
I should be able to pass in an offset returned from the last call, and get the next set of results as per the documentation here: https://apidocs.chargebee.com/docs/api/customers#list_customers
However, I always get the same results regardless of what offset value is supplied.
I've prepared a gist to help illustrate the point here: https://gist.github.com/sebastiansibelle/4a374f1ffa4ebfc40633
I need to use this function very soon, so the quicker you could turn around a fix the better!
Thanks,
Sebastian
warning: URI.escape is obsolete
ruby 2.1.8
chargebee-2.2.7/lib/chargebee/models/model.rb:59:in `block in uri_path': warning: URI.escape is obsolete
CGI '0.1.0' gem is vulnerable (https://www.ruby-lang.org/en/news/2021/11/24/cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819/), there's a patch for it '0.1.1' .
I'm trying to leverage both the Stripe and Chargebee APIs to create subscriptions and I'm running into an issue with the card
parameters.
According to the documentation, if the card[tmp_token]
is set, there is no need to provide additional parameters.
If this value is specified, there is no need to specify other card details (like number, cvv, etc).
Here's a simplified version of the code I'm sandboxing at the moment:
require "stripe"
require "chargebee"
Stripe.api_key = "sk_test_************************"
ChargeBee.configure(
site: "******-test",
api_key: "test_********************************"
)
token = Stripe::Token.create(
card: {
number: "4242424242424242",
exp_month: 8,
exp_year: 2018,
cvc: "314",
},
)
result = ChargeBee::Subscription.create(
{
plan_id: "standard",
customer: {}, # ...
billing_address: {}, # ...
card: {
tmp_token: token.id, # tok_************************
},
}
)
The Stripe-part will later be replaced with Stripe.js for PCI compliance reasons, but I'm using it here to sandbox and prepare working code for my development environment.
By the time the Ruby interpreter calls ChargeBee::Subscription.create
, it raises the following exception:
/Users/michael/.gem/ruby/2.4.0/gems/chargebee-2.3.3/lib/chargebee/rest.rb:78:in `handle_for_error': card[billing_addr1] : cannot be blank (ChargeBee::PaymentError)
It's complaining that it wants the billing_addr1
property, while the documentation states it isn't required. But, even if I, in addition to the tmp_token
add the billing_addr1
property, it still continues to raise the same exception.
Any idea why this is happening? Thanks!
I'm encountering the following error. Not sure whether it's an API or client issue.
IO Exception when trying to connect to chargebee with url https://imazen.chargebee.com/api/v2/subscriptions/[redacted] . Reason cookie store unavailable: :hash
/app/vendor/bundle/ruby/2.5.0/bundler/gems/chargebee-ruby-143900d4d74f/lib/chargebee/rest.rb:53:in `rescue in request'
/app/vendor/bundle/ruby/2.5.0/bundler/gems/chargebee-ruby-143900d4d74f/lib/chargebee/rest.rb:44:in `request'
/app/vendor/bundle/ruby/2.5.0/bundler/gems/chargebee-ruby-143900d4d74f/lib/chargebee/request.rb:18:in `send'
/app/vendor/bundle/ruby/2.5.0/bundler/gems/chargebee-ruby-143900d4d74f/lib/chargebee/models/subscription.rb:44:in `retrieve'
I have been trying to follow the API guide to generate a hosted page link for customers to update their card info. Apparently ChargeBee::HostedPage.update_payment_method
is not defined.
I have also tried ChargeBee::HostedPage.update_card
but it gave me this error:
ChargeBee::APIError:
from /Users/.../gems/chargebee-1.5.0/lib/chargebee/rest.rb:85:in `handle_for_error'
Any idea?
The model class https://github.com/chargebee/chargebee-ruby/blob/master/lib/chargebee/models/contract_term.rb
Is not included in
https://github.com/chargebee/chargebee-ruby/blob/master/lib/chargebee.rb
To reproduce try https://apidocs.chargebee.com/docs/api/subscriptions?prod_cat_ver=1&lang=ruby#list_contract_terms_for_a_subscription
require 'chargebee'
ChargeBee.configure(:site => "{site}",
:api_key => "{site_api_key}")
list = ChargeBee::Subscription.contract_terms_for_subscription("__test__8asukSOXdty0Mv")
list.each do |entry|
contract_term = entry.contract_term
end
=> (uninitialized constant ChargeBee::Result::ContractTerm)
Did you mean? ChargeBee::Contact
Reproduction steps:
Assuming that you have ChargeBee already configured, run
begin
ChargeBee::Addon.retrieve(1) # or any other ID which does NOT exit in your environment
rescue ChargeBee::Error => e
p e.message
end
Current output:
nil
Expected output:
Sorry, we couldn't find that resource
Cause:
ChargeBee::APIError
(indirectly) inherits from StandardError
and passes message from json_obj[:message]
as a parameter to StandardError
constructor. Normally that should make message accessible as .message
, but APIError
defines attr_accessor :message
which is never initialized.
It looks like the rest-client
gem no longer has any active maintainers and has not had a commit since 2019. A different http lib should be used that has active maintainers who are fixing bugs and security issues.
Ruby version: 3.0.0
URI.encode removed in Ruby 3.
irb(main):001:0> URI.encode
Traceback (most recent call last):
4: from /Users/bojacobson/.rbenv/versions/3.0.0/bin/irb:23:in `<main>'
3: from /Users/bojacobson/.rbenv/versions/3.0.0/bin/irb:23:in `load'
2: from /Users/bojacobson/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
1: from (irb):1:in `<main>'
NoMethodError (undefined method `encode' for URI:Module)
Chargebee::Subscription.retreive("subscription-id")
=> NoMethodError (undefined method `encode' for URI:Module)
here is the culprit: b9b6a69#diff-c9a289b8798c75c2b395c35fb0b44ec0a272ab762005e9bc3b259140035874f3R59
I was able to fix this by defining the URI.encode:
module URI
def self.encode(string)
return URI.encode_www_form_component(string)
end
end
Could you please add license to gemspec file? Coditsu is reporting that it's missing.
We could create a subscription without any errors.
But when trying to get a subscription by customer id in a short time, we couldn't get the subscription.
This happens sometimes.
# Create subscription
ChargeBee::Subscription.create_for_customer(chargebee_customer_id, params)
# Get subscription by customer id
list = ChargeBee::Subscription.list({"customer_id[is]" => chargebee_customer_id, limit: 1})
subscription = list.first.subscription # ERROR: undefined method `subscription' for nil:NilClass
I think there should be a delay on Chargebee and it should take few seconds to create a subscription.
What is the way to fix this issue and how long does it take to be created?
After the recent availability problems of the ChargeBee service, I had problems in my own service that relies on chargebee due to the long timeouts set in the ChargeBee ruby client. Therefore I would like to propose that the SDK allows a user to specify to set their own HTTP timeout limits as a configuration parameter.
Hi team,
Could you provide something like this for test webhooks behaviour in ruby test?
https://developers.braintreepayments.com/reference/general/webhooks/subscription/ruby
In my case, I created a class that provides a Chargebee webhook response, but I think that a official solution could be great. Here's my code: https://gist.github.com/patriciojofre/03464fa01b3267a6da0cabc5c99ec4b7
(I copied response from a real webhook received and then create dynamic objects)
Thanks!
I'm trying to simply do a puts chargebee_result
, but this gets printed out:
https://github.com/chargebee/chargebee-ruby/blob/master/lib/chargebee/models/model.rb#L49
It might be better to have that output to STDERR
, so as to not interfere with scripts trying to simply print out the result object.
This commit made #to_s
public, which is actually very important.
But then this later commit made it private again. (The private
statement appears twice in the file now, and looks like a copy & paste error.)
This is blocking me from upgrading. (I'm currently using my own private fork where I've fixed this.)
Just in case you're not aware
rest-client/rest-client#740
I had to set rest-client in my Gemfile to 2.0.2 to avoid this issue.
Currently in you Gemfile you have this dependency:
s.add_dependency('json_pure', '~> 1.5')
You should update that to use '~> 2.0'
or at least use '>= 1.5'
.
The outdated dependency also causes incompatibility with the AWS official gem that also depends on json_pure
.
At least some timeout errors do not have valid JSON, and although their body contains the reason they end up here https://github.com/chargebee/chargebee-ruby/blob/master/lib/chargebee/rest.rb#L82 resulting with a generic error.
Also, rest.rb
has JSON parsing on two places, which should be unified.
A/C: Properly handle timeout errors and eventually use this code for them: https://github.com/chargebee/chargebee-ruby/blob/master/lib/chargebee/rest.rb#L65
Bonus points: create different exception types for different failure reasons.
ChargeBee::Customer.list({
limit: 2,
"email[is]" => "[email protected]"
})
The above code fails to find the user with the specified email. Instead it just lists all customers, most recent first.
EDIT: I have verified that this does work with curl, so it's not an API bug.
EDIT: I have tested this in 1.7.2 and 1.6.3
EDIT: Just realised I'm using V2 API code with V1 API client (1.7.2), hence why it's not working
According to the Chargebee documentations, when a coupon with nested attributes is serialized, the path of the nested attributes should be preserved and double-nested arrays should be json encoded as arrays.
{"item_constraints": [{"item_price_ids": ["id1"]}]}
Is expected to be serialized to parameters as:
item_constraints[item_price_ids][0]=["id1"]
However when this resource is serialized using this library, the nested array is not correctly nested
ChargeBee::Util.serialize({item_constraints: [{item_price_ids: ['id1']}]})
=> {"item_price_ids[0]"=>"id1"}
SyntaxError: /usr/lib/ruby/gems/1.8/gems/chargebee-2.0.9/lib/chargebee/rest.rb:7: syntax error, unexpected ')', expecting '='
/usr/lib/ruby/gems/1.8/gems/chargebee-2.0.9/lib/chargebee/rest.rb:90: syntax error, unexpected kEND, expecting $end
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in require_without_desert' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in
new_constants_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in require_without_desert' from /usr/lib/ruby/gems/1.8/gems/desert-0.5.3/lib/desert/ruby/object.rb:8:in
require'
from /usr/lib/ruby/gems/1.8/gems/desert-0.5.3/lib/desert/ruby/object.rb:32:in __each_matching_file' from /usr/lib/ruby/gems/1.8/gems/desert-0.5.3/lib/desert/ruby/object.rb:7:in
require'
from /usr/lib/ruby/gems/1.8/gems/chargebee-2.0.9/lib/chargebee.rb:2
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in
require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in require_without_desert' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in
new_constants_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in require_without_desert' from /usr/lib/ruby/gems/1.8/gems/desert-0.5.3/lib/desert/ruby/object.rb:8:in
require'
from /usr/lib/ruby/gems/1.8/gems/desert-0.5.3/lib/desert/ruby/object.rb:32:in __each_matching_file' from /usr/lib/ruby/gems/1.8/gems/desert-0.5.3/lib/desert/ruby/object.rb:7:in
require'
hi, while debugging other stuff i noticed that you have typo in dependencies. also i had to upgrade rspec version to get specs working
it should be:
s.add_development_dependency('rspec', '~> 3.0.0')
instead:
s.add_development_dependency('rpsec', '~> 2.9.0')
typo ^ ^ version
Hi,
I'm creating Chargebee subscriptions (in sandbox) using a Braintree nonce, specific the fake-invalid-nonce
. When I call ChargeBee::Subscription.create_for_customer("customer_id", {})
method, this respond like a valid nonce. Instead, if I use ChargeBee::Subscription.create({})
sent nonce is rejected as expected.
The chargebee.gemspec
doesn't contain a link to the changelog of the project, this prevent Dependabot to automatically fetch the changes made in new versions.
Here's a screenshot for the latest version of Chargebee-ruby:
A simple way to fix is to add the following key in chargebee.gemspec
:
s.metadata = {
"changelog_uri" => "https://github.com/chargebee/chargebee-ruby/blob/master/CHANGELOG.md",
}
You can find the documentation about the metadata key here.
I have a requirement of getting the total number of Subscriptions
of specific plan within duration of one month.
A work around is to use ChargeBee::Subscription.list( ... ).count
and set the limit to a very big number (and use next_offset
, if ever needed).
To save resources, is there a better way of getting the total items count?
Script to replicate the issue:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'chargebee', '~> 2'
end
ChargeBee::Item
Running this gives following error:
Traceback (most recent call last):
chargebee_check.rb:9:in `<main>': uninitialized constant ChargeBee::Item (NameError)
We are unable to access these Items APIs.
Item
and related models should be added to require
list here.
It'd be handy to have some mock result objects to use in testing, for various kinds of models in ChargeBee.
It'd help application developers write more reliable apps. E.g., how Rails uses version numbers. Thanks for your consideration!
Hi,
Any chance you'd consider switching your JSON dependency to MultiJson? This allows the user to decide the JSON implementation themselves, while still allowing json_pure as an option for those that want it.
The reason for this is that json_pure
defines ::JSON
and is not always API compatible with other implementations. If another gem uses a different library that also defines ::JSON
, the two implementations can fight and slightly different behaviours can occur. Including Chargebee in the project has caused a lot of JSON errors elsewhere for me because of issues like this.
HTML encode requests for customer and subscription data.
In Chargebee we setup a customer with an ID like the following Customer [Dotcom]
. The Chargebee UI allows this as a valid name. When calling for the customer data via the gem ChargeBee::Customer.retrieve(team.chargebee_customer_id)
the gem throws a bad uri error
bad URI(is not URI?): "https://captionhub.chargebee.com/api/v2/customers/Customer%20[Dotcom]"
It looks like the gem could benefit from some further encoding
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.