ccbill_ruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5f17c7f42a9062584e7ea2c733453a305cbdb2d
4
+ data.tar.gz: ba9ff6bcda4f7cdf1a405ad0a69a6cb62848df71
5
+ SHA512:
6
+ metadata.gz: 657b6f24d71f39d9ea0a7d7363134e10053e54a849862008bc56d739270029ecf2b9a1e2fdb350c49664ddefd4eac047e6fbd9d2c9242d17198711c8e2d93a28
7
+ data.tar.gz: 949d77be90c1ee5012a33d80c7ddc3961ce5af4b1edb89427691a13050382f65c531daad9b87bc8345de95f86893586292bc5fa62c4f6f8658970691869e38c3
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ # Ignore application configuration
11
+ /
12
+ # Ignore application configuration
13
+ /asdasdasdasd}
14
+ # Ignore application configuration
15
+ /asdasdasdasd
16
+ /asdasdasdasd
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dmytro.vasin@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ccbill_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dmytro Vasin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,352 @@
1
+ # GEM IS UNDER CONSNSTRUCTION!
2
+
3
+ Please Mail me if any - 'dmytro.vasin@gmail.com'
4
+
5
+ # CCBill SDK for Ruby
6
+
7
+ Unofficial CCBill SDK for Ruby.
8
+
9
+ This gem provides:
10
+ - Easy Install
11
+ - Getting started guide
12
+ - Generator that creates
13
+ - Approve/Deny callback paths
14
+ - Background Post path
15
+ - Url/Form Generator for test and live mode
16
+
17
+ # Getting started
18
+
19
+ ```ruby
20
+ gem 'ccbill_ruby'
21
+ ```
22
+
23
+ Then run `bundle install`
24
+
25
+ Next, you need to run the generator:
26
+
27
+ ```console
28
+ $ rails generate ccbill:install
29
+ ```
30
+
31
+ This will create a controller (if one does not exist) and configure it with the default actions. The generator also configures your config/routes.rb file to point to the CCBill controller.
32
+
33
+
34
+ ## Example of usage:
35
+
36
+ ```ruby
37
+ form = Ccbill::DynamicPricing.new({
38
+ initial_price_in_cents: 355
39
+ initial_period: 30,
40
+ order_id: 'Any configuration information'
41
+ })
42
+
43
+ form.valid? #=> True/False
44
+ form.url #=> URL
45
+ ```
46
+
47
+
48
+ ## Controller and methods:
49
+
50
+ Before reading this part - please read [Setup guide](#setup-guide)
51
+
52
+ `rails generate ccbill:install` will generate next:
53
+
54
+ ```ruby
55
+ # config/routes.rb
56
+ namespace :callbacks do
57
+ resource :ccbill, only: [:show, :create]
58
+ end
59
+ ```
60
+
61
+ ```ruby
62
+ # config/initializers/ccbill.rb
63
+ CCBill.configure do |config|
64
+ config.mode = :test
65
+ config.salt = 'Encryption Key'
66
+ config.default_currency = '840' # USD
67
+ config.account = 'account_id'
68
+ config.sub_account = '0000'
69
+ config.flexform_id = 'flexform_id'
70
+ end
71
+ ```
72
+
73
+ ```ruby
74
+ # app/controllers/callbacks/ccbills_controller.rb
75
+ module Callbacks
76
+ class CcbillsController < ApplicationController
77
+ # before_action :check_ccbill_callback, only: :create
78
+
79
+ # GET: Redirect from payment system after approval/deny.
80
+ def show
81
+ case response_params[:mppResponse]
82
+ when 'CheckoutSuccess'
83
+ flash[:notice] = "Payment was successfully paid"
84
+ when 'CheckoutFail'
85
+ flash[:alert] = "Payment was declined. We're sorry"
86
+ else
87
+ fail 'Unknown mmpResponse'
88
+ end
89
+
90
+ redirect_to root_url
91
+ end
92
+
93
+ # POST: Post Back
94
+ def create
95
+ postback = CCBill::Postback.new(response_params)
96
+
97
+ if postback.approval?
98
+ # Do something "Approval" postback.
99
+ else
100
+ # Do something "Deny" postback.
101
+ end
102
+
103
+ head :no_content
104
+ end
105
+
106
+ private
107
+
108
+ def response_params
109
+ @response_params ||= params.except(:controller, :action).to_unsafe_h
110
+ end
111
+ end
112
+ end
113
+ ```
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ # Payment Flow
128
+
129
+ TODO: Video or Etc...
130
+ TODO: NGrok.
131
+ TODO: User should be logged in in the admin panel.
132
+ TODO: Deny redirect happens only after three attempt.
133
+
134
+ The payment form is the CCBill form that will be displayed to customers after they choose to check out using CCBill. The payment form accepts customer payment information, processes the payment, and returns the customer to your Site through callbacks ( GET ) where you can catche the response and do proper redirect:
135
+
136
+ ```ruby
137
+ callbacks_ccbill GET /callbacks/ccbill(.:format) callbacks/ccbills#show
138
+ POST /callbacks/ccbill(.:format) callbacks/ccbills#create
139
+ ```
140
+
141
+ > Important!
142
+ > CCBill provides two types of payment forms. FlexForms is our newest (and recommended) system. In this gem we use ONLY FlexForms.
143
+
144
+
145
+
146
+
147
+
148
+
149
+ !!! https://kb.ccbill.com/How+do+I+set+up+a+user+to+process+test+transactions
150
+
151
+
152
+ !!! All prices must be between $2.95 and $100.
153
+
154
+ !!! CVV only metters!
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ # Setup guide
182
+
183
+ ## Instructions:
184
+
185
+ In order to set up a CCBill payment method, a CCBill Merchant account needs to be created.
186
+
187
+ ### Main Account
188
+
189
+ All CCBill clients have an account number for tracking purposes. The standard format is 9xxxxx-xxxx, where 6-digit number (9xxxxx) is the main account.
190
+
191
+ You can retrieve your main account number at the top bar near **Client Account** section.
192
+
193
+ Please enter the main account number to **Main Account** field.
194
+
195
+ ### Sub Account
196
+ After sign up for a website billing, you will be able to create a subaccount. The subaccount is a 4-digit number (xxxx) which is a part of main account.
197
+
198
+ To create a subaccount, go to **Account Info** menu item / **Sub Account Admin** section / **Create Subaccount**. After follow the instructions provided by CCBill to complete the subaccount.
199
+
200
+ ### Secret Key
201
+
202
+ You may obtain Salt value in 2 different ways:
203
+
204
+ - Contact CCBill Client Support and receive Salt value.
205
+ - You may create your own Salt value and provide it to CCBill Client Support.
206
+
207
+ Please note that Salt value is an alphanumeric string up to 32 characters long.
208
+
209
+
210
+ ### Form Secret Key ( flexform_id ):
211
+ In you CCBill Merchant Area you will be available to choose one of the CCBill Global Forms.
212
+
213
+ To retrieve one, go to **Flexform System** / **FlexForm Payment Links**. After click on **Forms Library**. Here will be displayed all forms that already in use (If you see nothing - that means you should create at least one `Payment Flow` )
214
+
215
+ After select an appropriate form you can customize it and preview it. ( How to customize form look into [FAQ](https://kb.ccbill.com/FlexForms+FAQs) of the CCBill )
216
+
217
+
218
+ ### Callbacks URLs:
219
+
220
+ **Success** and **Failure** callback URLs need to be set up.
221
+
222
+ This urls you can setup at:
223
+ - click **Account Info**
224
+ - click **Sub Account Admin**
225
+ - select Any subaccount
226
+ - click **Advansed** section
227
+ - Set **Approval Post URL** and **Denial Post URL**
228
+
229
+ For local machine ( development env ) I use [Ngrok](https://ngrok.com/download) to set valid path.
230
+
231
+ > Important!
232
+ > You gotta be logged in to the CCBill admin to be able to see your forms in the sandbox.
233
+
234
+ ## Configure your CCBill Account:
235
+
236
+ The following CCBill settings must be correct for the payment module to work correctly.
237
+
238
+ ### Dynamic Pricing
239
+
240
+ Please work with your CCBill support representative to activate Dynamic Pricing for your account ( sub-account ). You can verify that Dynamic Pricing is active at **Account Info** > **Manage the subaccount menu** > **Pick 0000 subaccount from select menu** > **Feature Summary** at the bottom. in the Admin Portal. Your Dynamic Pricing status appears at the bottom of the **Billing Tools** section.
241
+
242
+ ![Billing Tools](https://raw.githubusercontent.com/DmytroVasin/ccbill_ruby/master/images/billing_tools.png)
243
+
244
+ Please note that if Dynamic Pricing is enabled on the subaccount level, ALL signup forms on that subaccount must use Dynamic Pricing in order to function correctly. This includes forms created on the subaccount prior to Dynamic Pricing being enabled. If Dynamic Pricing is enabled only on a particular form and not the entire subaccount, other forms on that subaccount will not be required to use Dynamic Pricing.
245
+
246
+ ![URL Library](https://raw.githubusercontent.com/DmytroVasin/ccbill_ruby/master/images/url_library.png)
247
+
248
+ ### Creating a Salt / Encryption Key
249
+
250
+ A "salt" is a string of random data used to make your encryption more secure. **Sub Account Admin** > **Advanced**. It will appear in the **Encryption Key** field of the **Upgrade Security Setup Information section**.
251
+
252
+ Make note of the Salt: this value will be entered into the your configuration file. ( `config/initializers/ccbill.rb` )
253
+
254
+ ![ENCRYPTION KEY](https://raw.githubusercontent.com/DmytroVasin/ccbill_ruby/master/images/encryption_key.png)
255
+
256
+ ### Disabling User Management
257
+
258
+ Since this sub-account will be used for Dynamic Pricing transactions (not managing user subscriptions), User Management must be disabled.
259
+
260
+ - Sign in to the **Admin Portal**.
261
+ - On the **Account Info** megamenu, click **Sub Account Admin**, then **User Management** on the left menu.
262
+ - Select **Turn off User Management** in the top section.
263
+ - Select **Do Not Collect Usernames and Passwords** in the **Username Settings** section.
264
+
265
+ ![Disabling User Management](https://raw.githubusercontent.com/DmytroVasin/ccbill_ruby/master/images/disabling_user_management.png)
266
+
267
+ ### Creating a New FlexForms Payment Form
268
+ Here is standart [Getting Started with Flex Froms](https://kb.ccbill.com/FlexForms+Quick+Start+Guide).
269
+
270
+ #### Visit FlexForms:
271
+ - Ensure All is selected in the top Client Account drop-down menu. FlexForms are not specific to sub accounts, and cannot be managed when a sub account is selected.
272
+ - Navigate to the FlexForms Systems tab in the top menu bar and select FlexForms Payment Links. All existing forms will be displayed in a table.
273
+ - Make sure that you in sendbox ( Top left corner )
274
+
275
+ #### Create an Approval URL
276
+
277
+ - Click the **URLs Library** button in the upper-right to create a new URL. The Saved URLs Editor dialog displays.
278
+ - Create Payment Success URL
279
+ - Use the fields under **Add New** to create a new URL with the following properties.
280
+ - URL Name. Enter a meaningful name for this URL. Forexample: **Payment Success**
281
+ - URL. Under URL, enter the base URL for your Site store. Forexample: `http://[SiteHost or Ngrok]/callbacks/ccbill?mppResponse=CheckoutSuccess`
282
+ - Create Payment Decline URL. Forexample: `http://[SiteHost or Ngrok]/callbacks/ccbill?mppResponse=CheckoutFail`
283
+ - Click Save to commit your changes.
284
+
285
+ > Important:
286
+ > 1. Do not create alot of flex-form. You can't delete them!
287
+ > 2. This is URLS ( GET ) where user will be redirected after success/deny payment.
288
+ > 3. We set `mppResponse=CheckoutSuccess` and `mppResponse=CheckoutFail` because we use this attribute at `callbacks/ccbills#show` action.
289
+
290
+ ![URLs Editor](https://raw.githubusercontent.com/DmytroVasin/ccbill_ruby/master/images/url_editor.png)
291
+
292
+ #### Create a New FlexForm
293
+
294
+ - Click the `Add New** button in the upper-left to create a new form.
295
+ - The **A New Form** dialog is displayed:
296
+ - **Payment Flow Name**. At the top, enter a name for the new payment flow (this will be different than the form name, as a single form can be used in multiple flows). Forexample: 'Dev Form'
297
+ - **Form Name**. Under Form Name, enter a name for the form. Forexample: '001ff'
298
+ - **Dynamic Pricing**. Under Pricing, check the box to enable dynamic pricing.
299
+ - **Layout**. Select your desired layout
300
+ - Save the form
301
+ - Edit the Flow
302
+ - Approval redirect to the Site
303
+ - Click the arrow button to the left of your new flow to view the details. ( Screenshot below )
304
+ - Under the green Approve arrow, click the square to modify the action.
305
+ - **Approval URL**. In the left menu, select A URL. Select **Select a Saved URL** and select the URL your created earlier (e.g. Payment Success).
306
+ - **Redirect Time**. Select a redirect time of 1 second using the slider at the bottom and save the form. ( e.g. 4 seconds )
307
+ - Deny redirect to the Site
308
+ - Under the red Deny arrow, click the square to modify the action.
309
+ - **Approval URL. In the left menu, select A URL. Select **Select a Saved URL** and select the URL your created earlier (e.g. Payment Decline`).
310
+ - **Redirect Time**. Select a redirect time of 1 second using the slider at the bottom and save the form. ( e.g. 7 seconds )
311
+ - Flex ID. Make note of the Flex ID: this value will be entered into the your configuration file. ( `config/initializers/ccbill.rb` )
312
+
313
+
314
+ #### Background Post
315
+
316
+ While still in the **Sub Account Admin** section, select **Advanced** from the left menu. Notice the top section titled **Background Post Information**. We will be modifying the **Approval Post URL** and **Denial Post URL** fields.
317
+
318
+ Path | URL
319
+ --- | ---
320
+ **Approval Post URL** | `http://[SiteHost or Ngrok]/callbacks/ccbill`
321
+ **Denial Post URL** | `http://[SiteHost or Ngrok]/callbacks/ccbill`
322
+
323
+ CCBill calls this URL in background.
324
+
325
+ Note: That will be `POST` request. In our case It will call `callbacks/ccbills#create` action. In this action based on patams we will find-out what request was called.
326
+
327
+ ![Background Post Information](https://raw.githubusercontent.com/DmytroVasin/ccbill_ruby/master/images/background_post_information.png)
328
+
329
+ **Your CCBill account is now configured**
330
+
331
+
332
+ # Go To LIVE:
333
+
334
+ TODO:
335
+
336
+ The LINKS that you get from the Sandbox Mode page are different from the links that you get from the Live Mode page
337
+
338
+ Please read next:
339
+ - [FlexForms Sandbox](https://kb.ccbill.com/FlexForms+Sandbox?page_ref_id=452)
340
+ - [FlexForms Form Status and Live Mode](https://kb.ccbill.com/FlexForms+Form+Status+and+Live+Mode?page_ref_id=453)
341
+
342
+ # Useful Links:
343
+ * [Dynamic Pricing](https://kb.ccbill.com/Dynamic+Pricing)
344
+ * [FlexForm FAQs](https://kb.ccbill.com/FlexForms+FAQs)
345
+ * [FlexForms Quick Start Guide](https://kb.ccbill.com/FlexForms+Quick+Start+Guide)
346
+ * [FlexForms Sandbox](https://kb.ccbill.com/FlexForms+Sandbox?page_ref_id=452)
347
+ * [FlexForms Form Status and Live Mode](https://kb.ccbill.com/FlexForms+Form+Status+and+Live+Mode?page_ref_id=453)
348
+ * [Test Transactions and Credit Cards](https://kb.ccbill.com/How+do+I+set+up+a+user+to+process+test+transactions)
349
+
350
+ # License
351
+
352
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/ccbill ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "./lib/ccbill_ruby/cli.rb"
4
+
5
+ CCBill::CLI.start( ARGV )
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ccbill_ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ccbill_ruby/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ccbill_ruby"
8
+ gem.version = CCBill::VERSION
9
+ gem.authors = ["Dmytro Vasin"]
10
+ gem.email = ["dmytro.vasin@gmail.com"]
11
+
12
+ gem.summary = "Unofficial CCBill SDK for Ruby"
13
+ gem.description = "Provides interfaces to interact with CCBill services."
14
+ gem.homepage = "https://github.com/DmytroVasin/ccbill_ruby/"
15
+ gem.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if gem.respond_to?(:metadata)
20
+ # gem.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ gem.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ gem.bindir = "exe"
30
+ gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ gem.require_paths = ["lib"]
32
+
33
+ gem.add_dependency "thor", "~> 0.19.4"
34
+
35
+ gem.add_development_dependency "bundler", "~> 1.14"
36
+ gem.add_development_dependency "rake", "~> 10.0"
37
+ gem.add_development_dependency "rspec", "~> 3.6.0"
38
+ gem.add_development_dependency "pry"
39
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ CCBill.configure do |config|
2
+ config.mode = :test
3
+ config.salt = 'Encryption Key'
4
+ config.default_currency = '840' # USD
5
+ config.account = 'account_id'
6
+ config.sub_account = '0000'
7
+ config.flexform_id = 'flexform_id'
8
+ end
@@ -0,0 +1,38 @@
1
+ module Callbacks
2
+ class CcbillsController < ApplicationController
3
+ # before_action :check_ccbill_callback, only: :create
4
+
5
+ # GET: Redirect from payment system after approval/deny.
6
+ def show
7
+ case response_params[:mppResponse]
8
+ when 'CheckoutSuccess'
9
+ flash[:notice] = "Payment was successfully paid"
10
+ when 'CheckoutFail'
11
+ flash[:alert] = "Payment was declined. We're sorry"
12
+ else
13
+ fail 'Unknown mmpResponse'
14
+ end
15
+
16
+ redirect_to root_url
17
+ end
18
+
19
+ # POST: Post Back
20
+ def create
21
+ postback = CCBill::Postback.new(response_params)
22
+
23
+ if postback.approval?
24
+ # Do something "Approval" postback.
25
+ else
26
+ # Do something "Deny" postback.
27
+ end
28
+
29
+ head :no_content
30
+ end
31
+
32
+ private
33
+
34
+ def response_params
35
+ @response_params ||= params.except(:controller, :action).to_unsafe_h
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require 'thor/group'
2
+
3
+ module CCBill
4
+ class CLI < Thor
5
+ class Install < Thor::Group
6
+ include Thor::Actions
7
+
8
+ def self.source_root
9
+ File.expand_path('../install', __FILE__)
10
+ end
11
+
12
+ def copy_config_file
13
+ copy_file('ccbill.rb', 'config/initializers/ccbill.rb')
14
+ end
15
+
16
+ def copy_controller_file
17
+ copy_file('ccbill_controller.rb', 'app/controllers/callbacks/ccbill_controller.rb')
18
+ end
19
+
20
+ def ignore_configuration
21
+ inject_into_file 'config/routes.rb', before: /^end/ do
22
+ <<-EOF
23
+
24
+ namespace :callbacks do
25
+ resource :ccbill, only: [:show, :create]
26
+ end
27
+ EOF
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ require 'thor'
2
+
3
+ module CCBill
4
+ class CLI < Thor
5
+ desc 'install', "Install CCBill Ruby configuration files"
6
+
7
+ # method_option "path",
8
+ # aliases: ["-p"],
9
+ # default: "config/application.yml",
10
+ # desc: "Specify a configuration file path"
11
+
12
+ def install
13
+ require './lib/ccbill_ruby/cli/install'
14
+ Install.start
15
+ end
16
+
17
+ # # figaro heroku:set
18
+
19
+ # desc "heroku:set", "Send Figaro configuration to Heroku"
20
+
21
+ # method_option "app",
22
+ # aliases: ["-a"],
23
+ # desc: "Specify a Heroku app"
24
+ # method_option "environment",
25
+ # aliases: ["-e"],
26
+ # desc: "Specify an application environment"
27
+ # method_option "path",
28
+ # aliases: ["-p"],
29
+ # default: "config/application.yml",
30
+ # desc: "Specify a configuration file path"
31
+ # method_option "remote",
32
+ # aliases: ["-r"],
33
+ # desc: "Specify a Heroku git remote"
34
+
35
+ # define_method "heroku:set" do
36
+ # require "figaro/cli/heroku_set"
37
+ # HerokuSet.run(options)
38
+ # end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ module CCBill
2
+ class Configuration
3
+ TEST_ENDPOINT = 'https://sandbox-api.ccbill.com/wap-frontflex/flexforms/'
4
+ LIVE_ENDPOINT = 'https://api.ccbill.com/wap-frontflex/flexforms/'
5
+
6
+ attr_accessor :mode
7
+
8
+ attr_accessor :salt
9
+ attr_accessor :default_currency
10
+
11
+ attr_accessor :account
12
+ attr_accessor :sub_account
13
+
14
+ attr_accessor :flexform_id
15
+ attr_accessor :test_endpoint
16
+ attr_accessor :live_endpoint
17
+
18
+ def initialize
19
+ @mode = :test
20
+ @default_currency = '840' # USD
21
+
22
+ @test_endpoint = TEST_ENDPOINT
23
+ @live_endpoint = LIVE_ENDPOINT
24
+ end
25
+
26
+ def test?
27
+ mode.to_sym == :test
28
+ end
29
+
30
+ def endpoint
31
+ if test?
32
+ test_endpoint
33
+ else
34
+ live_endpoint
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,125 @@
1
+ module CCBill
2
+ class DynamicPricingError < StandardError; end
3
+
4
+ class DynamicPricing
5
+ attr_accessor :variables, :config, :errors
6
+
7
+ def initialize(options = {})
8
+ modified_options = modify_params(options)
9
+
10
+ self.config = CCBill.configuration
11
+ self.variables = {
12
+ account: config.account,
13
+ sub_account: config.sub_account,
14
+ currency_code: config.default_currency
15
+ }.merge(modified_options)
16
+ end
17
+
18
+ def url
19
+ raise DynamicPricingError.new(errors.join(' ')) if !valid?
20
+
21
+ variables[:form_digest] = encode_form_digest
22
+
23
+ config.endpoint + config.flexform_id + '?' + URI.encode_www_form(transformed_variables)
24
+ end
25
+
26
+ def valid?
27
+ @errors = []
28
+
29
+ required_fields.each do |field|
30
+ @errors << "#{field} is required." if !variables[field]
31
+ end
32
+
33
+ unless (2.96..99.99).include?(variables[:initial_price].to_f)
34
+ @errors << 'Price must be between $2.95 and $100.'
35
+ end
36
+
37
+ @errors.empty?
38
+ end
39
+
40
+ private
41
+
42
+ def encode_form_digest
43
+ hashed_fields = if recurring?
44
+ [
45
+ variables[:initial_price],
46
+ variables[:initial_period],
47
+ variables[:recurring_price],
48
+ variables[:recurring_period],
49
+ variables[:rebills],
50
+ variables[:currency_code],
51
+ config.salt
52
+ ]
53
+ else
54
+ [
55
+ variables[:initial_price],
56
+ variables[:initial_period],
57
+ variables[:currency_code],
58
+ config.salt
59
+ ]
60
+ end
61
+
62
+ Digest::MD5.hexdigest(hashed_fields.join)
63
+ end
64
+
65
+ def recurring?
66
+ variables[:recurring_price] || variables[:recurring_period] || variables[:rebills]
67
+ end
68
+
69
+ def required_fields
70
+ req = [
71
+ :initial_price,
72
+ :initial_period
73
+ ]
74
+
75
+ if recurring?
76
+ req += [
77
+ :recurring_price,
78
+ :recurring_period,
79
+ :rebills
80
+ ]
81
+ end
82
+
83
+ req
84
+ end
85
+
86
+ def ccbill_field(internal)
87
+ {
88
+ account: 'clientAccnum',
89
+ sub_account: 'clientSubacc',
90
+ initial_price: 'initialPrice',
91
+ initial_period: 'initialPeriod',
92
+ currency_code: 'currencyCode',
93
+ recurring_price: 'recurringPrice',
94
+ recurring_period: 'recurringPeriod',
95
+ rebills: 'numRebills',
96
+ form_digest: 'formDigest'
97
+ }[internal] || internal
98
+ end
99
+
100
+ def transformed_variables
101
+ transform_keys(variables) { |key| ccbill_field(key) }
102
+ end
103
+
104
+ # From Active Support:
105
+ def transform_keys(_hash)
106
+ result = {}
107
+ _hash.keys.each do |key|
108
+ result[yield(key)] = _hash[key]
109
+ end
110
+ result
111
+ end
112
+
113
+
114
+ def modify_params(options)
115
+ initial_cents = options.delete(:initial_price_in_cents)
116
+ options[:initial_price] = convert_to_price(initial_cents) if initial_cents
117
+
118
+ options
119
+ end
120
+
121
+ def convert_to_price(cents)
122
+ '%.2f' % (cents / 100.to_f)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,44 @@
1
+ module CCBill
2
+ class Postback
3
+ attr_accessor :response_params
4
+
5
+ def initialize(response_params = {})
6
+ self.response_params = response_params
7
+ end
8
+
9
+ def approval?
10
+ !denial?
11
+ end
12
+
13
+ def denial?
14
+ [:reasonForDeclineCode, :reasonForDecline, :denialId].any? do |key|
15
+ !response_params[key].to_s.strip.empty?
16
+ end
17
+ end
18
+
19
+ def verified?
20
+ fail 'NOTE: Does not work on test env - Did not check for production.'
21
+ response_params[:responseDigest] == encode_digest_response
22
+ end
23
+
24
+ private
25
+
26
+ def encode_digest_response
27
+ verify_fields = if approval?
28
+ [
29
+ response_params[:subscription_id],
30
+ '1',
31
+ CCBill.configuration.salt
32
+ ]
33
+ else
34
+ [
35
+ response_params[:denialId],
36
+ '0',
37
+ CCBill.configuration.salt
38
+ ]
39
+ end
40
+
41
+ Digest::MD5.hexdigest(verify_fields.join)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module CCBill
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'ccbill_ruby/version'
2
+ require 'ccbill_ruby/configuration'
3
+ require 'ccbill_ruby/dynamic_pricing'
4
+ require 'ccbill_ruby/postback'
5
+
6
+ module CCBill
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.configure
16
+ yield(configuration) if block_given?
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ccbill_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Vasin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.6.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Provides interfaces to interact with CCBill services.
84
+ email:
85
+ - dmytro.vasin@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/ccbill
98
+ - bin/console
99
+ - bin/setup
100
+ - ccbill_ruby.gemspec
101
+ - images/background_post_information.png
102
+ - images/billing_tools.png
103
+ - images/disabling_user_management.png
104
+ - images/encryption_key.png
105
+ - images/url_editor.png
106
+ - images/url_library.png
107
+ - lib/ccbill_ruby.rb
108
+ - lib/ccbill_ruby/cli.rb
109
+ - lib/ccbill_ruby/cli/install.rb
110
+ - lib/ccbill_ruby/cli/install/ccbill.rb
111
+ - lib/ccbill_ruby/cli/install/ccbill_controller.rb
112
+ - lib/ccbill_ruby/configuration.rb
113
+ - lib/ccbill_ruby/dynamic_pricing.rb
114
+ - lib/ccbill_ruby/postback.rb
115
+ - lib/ccbill_ruby/version.rb
116
+ homepage: https://github.com/DmytroVasin/ccbill_ruby/
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.6.11
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Unofficial CCBill SDK for Ruby
140
+ test_files: []