chargebee 2.25.0 → 2.26.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6802473f9e53098c12e06f210e96a9067fa92b23
4
- data.tar.gz: fa7fdb9c0533e6c5d8751517fa26516bce474130
3
+ metadata.gz: e8f49942d789e63f0f1c44b234e16de02983f15f
4
+ data.tar.gz: e5feb8906f49350edc3136a2845e248b58d9e7f5
5
5
  SHA512:
6
- metadata.gz: 8ed018f8398ebf065b7a25b92a70bf47bb0dd8a702ab85cc061ade52fd305155c10389fae40c043661e9bf8b1798a88d0b95a13384e090a954c1553021f94cb3
7
- data.tar.gz: 9237adea2f062d4fad042d1c9dda997e8d621bbe2ea820132e313679746555fd73d090455d01bdce7da3e3f573d923cf4e20cfedcbbd70ab425a61bcaf39b320
6
+ metadata.gz: 0358f0b36273e2a6d50f44f10bb36ef8b6106f3924c073ff21ad127c95f29485bfbdfa1b9097a3c59e157121dc04ae63c78f806b4586ec478c9b83bd0cd4668b
7
+ data.tar.gz: 3ed155cb9b0f10d70ee68a3cf8422fc21c3f3e43b0b773d93f2cf30120c0180b5d9823f55a1cf101f605ebd617c7f2a35a4c4335d0ad8a1949aba34a33af2f0b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ### v2.26.1 (2023-05-16)
2
+ * * *
3
+
4
+ * Fixed test action failures.
5
+
6
+
7
+ ### v2.26.0 (2023-05-16)
8
+ * * *
9
+
10
+ #### New Feature:
11
+ * Added utility to pass **Idempotency key** along with request headers to allow a safe retry of POST requests.
12
+ * Added is_idempotency_replayed() utility to differentiate between original and replayed requests.
13
+ * Added get_response_headers() utility to fetch the response headers.
14
+
15
+
1
16
  ### v2.25.0 (2023-04-28)
2
17
  * * *
3
18
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chargebee (2.25.0)
4
+ chargebee (2.26.1)
5
5
  cgi (>= 0.1.0, < 1.0.0)
6
6
  json_pure (~> 2.1)
7
7
  rest-client (>= 1.8, <= 2.0.2)
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Chargebee Ruby Client Library - API V2
2
+
3
+ [![gem](https://img.shields.io/gem/v/chargebee.svg?maxAge=2592000)](https://rubygems.org/gems/chargebee)
4
+ [![gem](https://img.shields.io/gem/dtv/chargebee.svg?maxAge=2592000)](https://rubygems.org/gems/chargebee)
5
+
6
+ This is the Ruby Library for integrating with Chargebee. Sign up for a Chargebee account {here}[https://www.chargebee.com].
7
+
8
+ Chargebee now supports two API versions - [V1](https://apidocs.chargebee.com/docs/api/v1) and [V2](https://apidocs.chargebee.com/docs/api), of which V2 is the latest release and all future developments will happen in V2. This library is for <b>API version V2</b>. If you’re looking for V1, head to [chargebee-v1 branch](https://github.com/chargebee/chargebee-ruby/tree/chargebee-v1).
9
+
10
+ ## Installation
11
+
12
+ Install the latest version of the gem with the following command...
13
+
14
+ $ sudo gem install chargebee -v '~>2'
15
+
16
+
17
+ ## Requirements
18
+
19
+ * Ruby 1.9.3 or above.
20
+ * rest-client
21
+
22
+ ## Documentation
23
+
24
+ See our [Ruby API Reference](https://apidocs.chargebee.com/docs/api?lang=ruby "API Reference").
25
+
26
+ ## Usage
27
+
28
+ ### To create a new subscription:
29
+
30
+ ```ruby
31
+ ChargeBee.configure({:api_key => "your_api_key" , :site => "your_site"})
32
+ result = ChargeBee::Subscription.create({
33
+ :id => "sub_KyVqDh__dev__NTn4VZZ1",
34
+ :plan_id => "basic",
35
+ })
36
+ subscription = result.subscription
37
+ puts "created subscription is #{subscription}"
38
+ ```
39
+
40
+ ### Create an Idempotent Request
41
+
42
+ [Idempotency keys](https://apidocs.chargebee.com/docs/api) are passed along with request headers to allow a safe retry of POST requests.
43
+
44
+ ```ruby
45
+ require 'chargebee'
46
+ ChargeBee.configure({:api_key => "your_api_key" , :site => "your_site"})
47
+ result = ChargeBee::Customer.create({
48
+ :first_name => "John",
49
+ :last_name => "Doe",
50
+ :email => "john@test.com",
51
+ :locale => "fr-CA",
52
+ :billing_address => {
53
+ :first_name => "John",
54
+ :last_name => "Doe",
55
+ :line1 => "PO Box 9999",
56
+ :city => "Walnut",
57
+ :state => "California",
58
+ :zip => "91789",
59
+ :country => "US"
60
+ }
61
+ },
62
+ nil,
63
+ {"chargebee-idempotency-key" => "<<UUID>>"} # Replace <<UUID>> with a unique string
64
+ )
65
+ customer = result.customer
66
+ card = result.card
67
+ responseHeader = result.get_response_headers # Retrieves response headers
68
+ puts(responseHeader)
69
+ idempotencyReplayedValue = result.is_idempotency_replayed # Retrieves Idempotency replayed header value
70
+ puts(idempotencyReplayedValue)
71
+ ```
72
+ `is_idempotency_replayed` method can be accessed to differentiate between original and replayed requests.
73
+
74
+ ## License
75
+
76
+ See the LICENSE file.
77
+
data/chargebee.gemspec CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
  s.required_ruby_version = '>= 1.9.3'
6
6
  s.name = 'chargebee'
7
- s.version = '2.25.0'
8
- s.date = '2023-04-28'
7
+ s.version = '2.26.1'
8
+ s.date = '2023-05-16'
9
9
  s.summary = "Ruby client for Chargebee API."
10
10
  s.description = "Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com."
11
11
 
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  Gemfile
32
32
  Gemfile.lock
33
33
  LICENSE
34
+ README.md
34
35
  README.rdoc
35
36
  Rakefile
36
37
  chargebee.gemspec
@@ -10,12 +10,17 @@ module ChargeBee
10
10
 
11
11
  attr_reader :next_offset
12
12
 
13
- def initialize(response, next_offset=nil)
13
+ def initialize(response, next_offset=nil, rheaders = nil)
14
14
  @response = response
15
+ @rheaders = rheaders
15
16
  @list = Array.new
16
17
  @next_offset = JSON.parse(next_offset).to_s if next_offset
17
18
  initItems()
18
19
  end
20
+
21
+ def get_response_headers()
22
+ @rheaders
23
+ end
19
24
 
20
25
  private
21
26
  def initItems()
@@ -15,11 +15,11 @@ module ChargeBee
15
15
  def self.send(method, url, params={}, env=nil, headers={})
16
16
  env ||= ChargeBee.default_env
17
17
  ser_params = Util.serialize(params)
18
- resp = Rest.request(method, url, env, ser_params||={}, headers)
18
+ resp, rheaders = Rest.request(method, url, env, ser_params||={}, headers)
19
19
  if resp.has_key?(:list)
20
- ListResult.new(resp[:list], resp[:next_offset])
20
+ ListResult.new(resp[:list], resp[:next_offset], rheaders)
21
21
  else
22
- Result.new(resp)
22
+ Result.new(resp, rheaders)
23
23
  end
24
24
  end
25
25
 
@@ -54,6 +54,7 @@ module ChargeBee
54
54
  rescue Exception => e
55
55
  raise IOError.new("IO Exception when trying to connect to chargebee with url #{opts[:url]} . Reason #{e}",e)
56
56
  end
57
+ rheaders = response.headers
57
58
  rbody = response.body
58
59
  rcode = response.code
59
60
  begin
@@ -68,7 +69,7 @@ module ChargeBee
68
69
  end
69
70
  end
70
71
  resp = Util.symbolize_keys(resp)
71
- resp
72
+ return resp, rheaders
72
73
  end
73
74
 
74
75
  def self.handle_for_error(e, rcode=nil, rbody=nil)
@@ -1,10 +1,26 @@
1
1
  module ChargeBee
2
2
  class Result
3
3
 
4
- def initialize(response)
5
- @response = response
4
+ IDEMPOTENCY_REPLAYED_HEADER = :chargebee_idempotency_replayed
5
+
6
+ def initialize(response, rheaders = nil)
7
+ @response = response
8
+ @rheaders = rheaders
9
+ end
10
+
11
+ def get_response_headers()
12
+ @rheaders
6
13
  end
7
14
 
15
+ def is_idempotency_replayed()
16
+ replayed_header = get_response_headers[IDEMPOTENCY_REPLAYED_HEADER]
17
+ if replayed_header != nil
18
+ return !!replayed_header
19
+ else
20
+ return false
21
+ end
22
+ end
23
+
8
24
  def subscription()
9
25
  subscription = get(:subscription, Subscription,
10
26
  {:subscription_items => Subscription::SubscriptionItem, :item_tiers => Subscription::ItemTier, :charged_items => Subscription::ChargedItem, :addons => Subscription::Addon, :event_based_addons => Subscription::EventBasedAddon, :charged_event_based_addons => Subscription::ChargedEventBasedAddon, :coupons => Subscription::Coupon, :shipping_address => Subscription::ShippingAddress, :referral_info => Subscription::ReferralInfo, :contract_term => Subscription::ContractTerm, :discounts => Subscription::Discount});
data/lib/chargebee.rb CHANGED
@@ -68,7 +68,7 @@ require File.dirname(__FILE__) + '/chargebee/models/token.rb'
68
68
 
69
69
  module ChargeBee
70
70
 
71
- VERSION = '2.25.0'
71
+ VERSION = '2.26.1'
72
72
 
73
73
  @@default_env = nil
74
74
  @@verify_ca_certs = true
@@ -55,8 +55,10 @@ describe "chargebee" do
55
55
  end
56
56
 
57
57
  it "should properly convert the response json into proper object" do
58
- @request.expects(:execute).once.returns(mock_response(simple_subscription))
58
+ @request.expects(:execute).once.returns(mock_response(simple_subscription, headers))
59
59
  result = ChargeBee::Subscription.retrieve("simple_subscription")
60
+ h = result.get_response_headers
61
+ expect(h).to eq(headers)
60
62
  s = result.subscription
61
63
  expect(s.id).to eq("simple_subscription")
62
64
  expect(s.plan_id).to eq('basic')
@@ -66,7 +68,7 @@ describe "chargebee" do
66
68
  end
67
69
 
68
70
  it "should properly convert the nested response json into proper object with sub types" do
69
- @request.expects(:execute).once.returns(mock_response(nested_subscription))
71
+ @request.expects(:execute).once.returns(mock_response(nested_subscription, headers))
70
72
  result = ChargeBee::Subscription.retrieve("nested_subscription")
71
73
  s = result.subscription
72
74
  expect(s.id).to eq("nested_subscription")
@@ -78,7 +80,7 @@ describe "chargebee" do
78
80
  end
79
81
 
80
82
  it "should properly convert the list response json into proper result object" do
81
- @request.expects(:execute).once.returns(mock_response(list_subscriptions))
83
+ @request.expects(:execute).once.returns(mock_response(list_subscriptions, headers))
82
84
  result = ChargeBee::Subscription.list({:limit => 2})
83
85
  expect(result.length).to eq(2)
84
86
  result.each do |i|
@@ -87,7 +89,7 @@ describe "chargebee" do
87
89
  end
88
90
 
89
91
  it "should parse event api response and provide the content properly" do
90
- @request.expects(:execute).once.returns(mock_response(sample_event))
92
+ @request.expects(:execute).once.returns(mock_response(sample_event, headers))
91
93
  result = ChargeBee::Event.retrieve("sample_event")
92
94
  event = result.event
93
95
  s = event.content.subscription
@@ -12,6 +12,17 @@ def api_index_urls()
12
12
  }
13
13
  end
14
14
 
15
+ def headers
16
+ {
17
+ :cache_control=>"no-store, no-cache, must-revalidate",
18
+ :pragma=>"no-cache",
19
+ :content_type=>"application/json;charset=utf-8",
20
+ :content_length=>"986",
21
+ :date=>"Tue, 16 May 2023 08:12:00 GMT",
22
+ :server=>"ChargeBee"
23
+ }
24
+ end
25
+
15
26
  def simple_subscription
16
27
  {
17
28
  :subscription => {
data/spec/spec_helper.rb CHANGED
@@ -9,12 +9,13 @@ RSpec.configure do |config|
9
9
  config.mock_with :mocha
10
10
  end
11
11
 
12
- def mock_response(body, code=200)
12
+ def mock_response(body, code=200, headers)
13
13
  body = body.to_json if !(body.kind_of? String)
14
14
  m = mock
15
- m.instance_variable_set('@resp_values', { :body => body, :code => code })
15
+ m.instance_variable_set('@resp_values', { :body => body, :code => code, :headers => headers })
16
16
  def m.body; @resp_values[:body]; end
17
17
  def m.code; @resp_values[:code]; end
18
+ def m.headers; @resp_values[:headers]; end
18
19
  m
19
20
  end
20
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargebee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.25.0
4
+ version: 2.26.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajaraman S
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-28 00:00:00.000000000 Z
12
+ date: 2023-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_pure
@@ -107,6 +107,7 @@ files:
107
107
  - Gemfile
108
108
  - Gemfile.lock
109
109
  - LICENSE
110
+ - README.md
110
111
  - README.rdoc
111
112
  - Rakefile
112
113
  - chargebee.gemspec