openpay 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/OpenPay.iml +614 -0
- data/.idea/dictionaries/ronnie.xml +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/all_specs.xml +41 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +13 -0
- data/OpenPay.gemspec +24 -0
- data/README.md +370 -0
- data/Rakefile +1 -0
- data/lib/OpenPay/Cards.rb +76 -0
- data/lib/OpenPay/Charges.rb +79 -0
- data/lib/OpenPay/Customers.rb +195 -0
- data/lib/OpenPay/Fees.rb +5 -0
- data/lib/OpenPay/Payouts.rb +59 -0
- data/lib/OpenPay/Plans.rb +28 -0
- data/lib/OpenPay/Subscriptions.rb +58 -0
- data/lib/OpenPay/Transfers.rb +43 -0
- data/lib/OpenPay/bankaccounts.rb +66 -0
- data/lib/OpenPay/errors/open_pay_exception.rb +51 -0
- data/lib/OpenPay/errors/open_pay_exception_factory.rb +58 -0
- data/lib/OpenPay/errors/openpay_connection_exception.rb +3 -0
- data/lib/OpenPay/errors/openpay_transaction_exception.rb +5 -0
- data/lib/OpenPay/open_pay_resource.rb +242 -0
- data/lib/OpenPay/open_pay_resource_factory.rb +10 -0
- data/lib/OpenPay/openpay_api.rb +63 -0
- data/lib/OpenPay/version.rb +3 -0
- data/lib/openpay.rb +34 -0
- data/test/Factories.rb +258 -0
- data/test/spec/bankaccounts_spec.rb +187 -0
- data/test/spec/cards_spec.rb +411 -0
- data/test/spec/charges_spec.rb +377 -0
- data/test/spec/customers_spec.rb +230 -0
- data/test/spec/exceptions_spec.rb +138 -0
- data/test/spec/fees_spec.rb +113 -0
- data/test/spec/openpayresource_spec.rb +52 -0
- data/test/spec/payouts_spec.rb +197 -0
- data/test/spec/plans_spec.rb +229 -0
- data/test/spec/subscriptions_spec.rb +228 -0
- data/test/spec/transfers_spec.rb +221 -0
- data/test/spec_helper.rb +16 -0
- metadata +135 -0
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/OpenPay.iml" filepath="$PROJECT_DIR$/.idea/OpenPay.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
9
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
2
|
+
<configuration default="false" name="Run spec 'bankaccounts_spec': OpenPay" type="RSpecRunConfigurationType" factoryName="RSpec">
|
3
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
4
|
+
<module name="OpenPay" />
|
5
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
6
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/test/spec" />
|
7
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
8
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
9
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
10
|
+
<envs>
|
11
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
12
|
+
</envs>
|
13
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
14
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
15
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
16
|
+
<COVERAGE_PATTERN ENABLED="true">
|
17
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
18
|
+
</COVERAGE_PATTERN>
|
19
|
+
</EXTENSION>
|
20
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
21
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
22
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/test/spec/bankaccounts_spec.rb" />
|
23
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
24
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
25
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
26
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
27
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
28
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
29
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
30
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
31
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
32
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
33
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
34
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
35
|
+
<method />
|
36
|
+
</configuration>
|
37
|
+
</component>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
2
|
+
<configuration default="false" name="Run spec 'customers_spec': OpenPay" type="RSpecRunConfigurationType" factoryName="RSpec">
|
3
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
4
|
+
<module name="OpenPay" />
|
5
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
6
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/test/spec" />
|
7
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
8
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
9
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
10
|
+
<envs>
|
11
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
12
|
+
</envs>
|
13
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
14
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
15
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
16
|
+
<COVERAGE_PATTERN ENABLED="true">
|
17
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
18
|
+
</COVERAGE_PATTERN>
|
19
|
+
</EXTENSION>
|
20
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
21
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
22
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/test/spec/customers_spec.rb" />
|
23
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
24
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
25
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
26
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
27
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
28
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
29
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
30
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
31
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
32
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
33
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
34
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
35
|
+
<method />
|
36
|
+
</configuration>
|
37
|
+
</component>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
2
|
+
<configuration default="false" name="all_specs" type="RSpecRunConfigurationType" factoryName="RSpec">
|
3
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
4
|
+
<module name="OpenPay" />
|
5
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
6
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/test/spec" />
|
7
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
8
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
9
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
10
|
+
<envs>
|
11
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
12
|
+
</envs>
|
13
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
14
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
15
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
16
|
+
<COVERAGE_PATTERN ENABLED="true">
|
17
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
18
|
+
</COVERAGE_PATTERN>
|
19
|
+
</EXTENSION>
|
20
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
21
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="$MODULE_DIR$/test/spec" />
|
22
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
|
23
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
24
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
25
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
26
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="ALL_IN_FOLDER" />
|
27
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
28
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
29
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
30
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
31
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
32
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
33
|
+
<RunnerSettings RunnerId="RubyCover" />
|
34
|
+
<RunnerSettings RunnerId="RubyDebugRunner" />
|
35
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
36
|
+
<ConfigurationWrapper RunnerId="RubyCover" />
|
37
|
+
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
38
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
39
|
+
<method />
|
40
|
+
</configuration>
|
41
|
+
</component>
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2014 Openpay SAPI de C.V.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/OpenPay.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'openpay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "openpay"
|
8
|
+
spec.version = Openpay::VERSION
|
9
|
+
spec.authors = ["ronnie_bermejo"]
|
10
|
+
spec.email = ["ronnie.bermejo.mx@gmail.com"]
|
11
|
+
spec.description = %q{ruby client for Openpay API services (version 1.0.0)}
|
12
|
+
spec.summary = %q{ruby api for openpay resources}
|
13
|
+
spec.homepage = "http://openpay.mx/"
|
14
|
+
spec.license = "Apache"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
19
|
+
spec.require_paths = ["lib","lib/openpay"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.post_install_message = "Thanks for installing openpay. Enjoy !"
|
24
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,370 @@
|
|
1
|
+
# openpay
|
2
|
+
|
3
|
+
|
4
|
+
##Description
|
5
|
+
|
6
|
+
ruby client for *Openpay api* services (version 1.0.0)
|
7
|
+
|
8
|
+
This is a ruby client implementing the payment services for *Openpay* at openpay.mx
|
9
|
+
|
10
|
+
For more information about Openpay visit:
|
11
|
+
- http://openpay.mx/
|
12
|
+
|
13
|
+
For the full *Openpay api* documentation take a look at:
|
14
|
+
- http://docs.openpay.mx/
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add the following line to your Gem file
|
19
|
+
|
20
|
+
# gem install --source https://code.stripe.com stripe
|
21
|
+
|
22
|
+
gem 'openpay'
|
23
|
+
|
24
|
+
Update your bundle:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it from the command line:
|
29
|
+
|
30
|
+
$ gem install openpay-1.0.0.gem
|
31
|
+
|
32
|
+
###Requirements
|
33
|
+
|
34
|
+
* ruby 1.8.7 or higher
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
|
39
|
+
### Initialization
|
40
|
+
```ruby
|
41
|
+
require 'openpay'
|
42
|
+
|
43
|
+
|
44
|
+
#merchant and private key
|
45
|
+
merchant_id='mywvupjjs9xdnryxtplq'
|
46
|
+
private_key='sk_92b25d3baec149e6b428d81abfe37006'
|
47
|
+
|
48
|
+
|
49
|
+
#An openpay resource factory instance is created out of the OpenpayApi
|
50
|
+
#it points to the development environment by default.
|
51
|
+
openpay=OpenpayApi.new(merchant_id,private_key)
|
52
|
+
|
53
|
+
#To enable production mode you should pass a third argument as true.
|
54
|
+
#openpay_prod=OpenPayApi.new(merchant_id,private_key,true)
|
55
|
+
```
|
56
|
+
|
57
|
+
The openpay factory instance is in charge to generate the required resources through a factory method (create).
|
58
|
+
Resource classes should be initialized using the factory method as described below.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
#creating an instance for each available resource
|
62
|
+
bankaccounts=openpay.create(:bankaccounts)
|
63
|
+
cards=openpay.create(:cards)
|
64
|
+
charges=openpay.create(:charges)
|
65
|
+
customers=openpay.create(:customers)
|
66
|
+
fees=openpay.create(:fees)
|
67
|
+
payouts=openpay.create(:payouts)
|
68
|
+
plans=openpay.create(:plans)
|
69
|
+
subscriptions=openpay.create(:subscriptions)
|
70
|
+
transfers=openpay.create(:transfers)
|
71
|
+
```
|
72
|
+
|
73
|
+
According to the current version of the *Openpay api* the available resources are:
|
74
|
+
|
75
|
+
- *bankaccounts*
|
76
|
+
- *cards*
|
77
|
+
- *charges*
|
78
|
+
- *customers*
|
79
|
+
- *fees*
|
80
|
+
- *payouts*
|
81
|
+
- *plans*
|
82
|
+
- *subscriptions*
|
83
|
+
- *transfers*
|
84
|
+
|
85
|
+
Each rest resource exposed in the rest *Openpay api* is represented by a class in this ruby API, being **OpenpayResource** the base class.
|
86
|
+
|
87
|
+
|
88
|
+
### Implementation
|
89
|
+
Each resource depending of its structure and available methods, will have one or more of the methods described under the methods subsection.
|
90
|
+
Below a short description about the implementation high level details. For detailed documentation take a look a the openpay api documentation.
|
91
|
+
|
92
|
+
|
93
|
+
#### Arguments
|
94
|
+
Given most resources belong, either to a merchant or a customer, the api was designed taking this in consideration, so:
|
95
|
+
|
96
|
+
The first argument represent the json/hash object, while the second argument which is optional represents the **customer_id**.
|
97
|
+
So if just one argument is provided the action will be performed at the merchant level,
|
98
|
+
but if the second argument is provided passing the **customer_id**, the action will be performed at the customer level.
|
99
|
+
|
100
|
+
|
101
|
+
The following illustrates the api design.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
#Merchant
|
105
|
+
hash_out=open_pay_resource.create(hash_in)
|
106
|
+
json_out=open_pay_resource.create(json_in)
|
107
|
+
|
108
|
+
|
109
|
+
#Customer
|
110
|
+
hash_out=open_pay_resource.create(hash_in,customer_id)
|
111
|
+
json_out=open_pay_resource.create(json_in,customer_id)
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
#### Methods Inputs/Outputs
|
117
|
+
|
118
|
+
This api supports both ruby hashes and json strings as inputs and outputs. (See previous example)
|
119
|
+
If a ruby hash is passed in as in input, a hash will be returned as the method output.
|
120
|
+
if a json string is passed in as an input, a json string will be returned as the method function output.
|
121
|
+
|
122
|
+
This code excerpt from a specification demonstrates how you can use hashes and json strings interchangeably.
|
123
|
+
|
124
|
+
Methods without inputs will return a ruby hash.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
it 'creates a fee using a json message' do
|
128
|
+
#create new customer
|
129
|
+
customer_hash= FactoryGirl.build(:customer)
|
130
|
+
customer=@customers.create(customer_hash)
|
131
|
+
|
132
|
+
#create customer card , using factory girl to build the hash for us
|
133
|
+
card_hash=FactoryGirl.build(:valid_card)
|
134
|
+
card=@cards.create(card_hash, customer['id'])
|
135
|
+
|
136
|
+
#create charge
|
137
|
+
charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000)
|
138
|
+
charge=@charges.create(charge_hash, customer['id'])
|
139
|
+
|
140
|
+
#create customer fee , using json as input, we get json as ouput
|
141
|
+
fee_json =%^{"customer_id":"#{customer['id']}","amount":"12.50","description":"Cobro de Comisión"}^
|
142
|
+
expect(@fees.create(fee_json)).to have_json_path('amount')
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
Here you can see how the **card_hash** representation looks like.
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
require 'pp'
|
150
|
+
pp card_hash =>
|
151
|
+
|
152
|
+
{:bank_name=>"visa",
|
153
|
+
:holder_name=>"Vicente Olmos",
|
154
|
+
:expiration_month=>"09",
|
155
|
+
:card_number=>"4111111111111111",
|
156
|
+
:expiration_year=>"14",
|
157
|
+
:bank_code=>"bmx",
|
158
|
+
:cvv2=>"111",
|
159
|
+
:address=>
|
160
|
+
{:postal_code=>"76190",
|
161
|
+
:state=>"QRO",
|
162
|
+
:line1=>"LINE1",
|
163
|
+
:line2=>"LINE2",
|
164
|
+
:line3=>"LINE3",
|
165
|
+
:country_code=>"MX",
|
166
|
+
:city=>"Queretaro"}}
|
167
|
+
```
|
168
|
+
|
169
|
+
Next, how we can construct the preceding hash using **FactoryGirl**.
|
170
|
+
**FactoryGirl** was used in our test suite to facilitate hash construction.
|
171
|
+
It may help you as well at your final implementation if you decide to use hashes.
|
172
|
+
(more examples at *test/Factories.rb*)
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
|
176
|
+
FactoryGirl.define do
|
177
|
+
factory :valid_card, class:Hash do
|
178
|
+
bank_name 'visa'
|
179
|
+
holder_name 'Vicente Olmos'
|
180
|
+
expiration_month '09'
|
181
|
+
card_number '4111111111111111'
|
182
|
+
expiration_year '14'
|
183
|
+
bank_code 'bmx'
|
184
|
+
cvv2 '111'
|
185
|
+
address {{
|
186
|
+
postal_code: '76190',
|
187
|
+
state: 'QRO',
|
188
|
+
line1: 'LINE1',
|
189
|
+
line2: 'LINE2',
|
190
|
+
line3: 'LINE3',
|
191
|
+
country_code: 'MX',
|
192
|
+
city: 'Queretaro',
|
193
|
+
}}
|
194
|
+
initialize_with { attributes }
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
198
|
+
|
199
|
+
####API Methods
|
200
|
+
|
201
|
+
This ruby API standardize the method names across all different resources using the **create**,**get**,**update** and **delete** verbs.
|
202
|
+
|
203
|
+
For full method documentation take a look at:
|
204
|
+
- http://docs.openpay.mx/
|
205
|
+
|
206
|
+
The test suite at *test/spec* is a good source of reference.
|
207
|
+
|
208
|
+
#####create
|
209
|
+
|
210
|
+
Creates the given resource
|
211
|
+
```ruby
|
212
|
+
open_pay_resource.create(representation,customer_id=nil)
|
213
|
+
```
|
214
|
+
|
215
|
+
#####get
|
216
|
+
|
217
|
+
Gets an instance of a given resource
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
open_pay_resource.get(object_id,customer_id=nil)
|
221
|
+
```
|
222
|
+
|
223
|
+
#####update
|
224
|
+
|
225
|
+
Updates an instance of a given resource
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
open_pay_resource.update(representation,customer_id=nil)
|
229
|
+
```
|
230
|
+
|
231
|
+
#####delete
|
232
|
+
|
233
|
+
Deletes an instance of the given resource
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
open_pay_resource.delete(object_id,customer_id=nil)
|
237
|
+
```
|
238
|
+
|
239
|
+
#####all
|
240
|
+
Returns an array of all instances of a resource
|
241
|
+
```ruby
|
242
|
+
open_pay_resource.all(customer_id=nil)
|
243
|
+
```
|
244
|
+
|
245
|
+
#####each
|
246
|
+
Returns a block for each instance resource
|
247
|
+
```ruby
|
248
|
+
open_pay_resource.each(customer_id=nil)
|
249
|
+
```
|
250
|
+
|
251
|
+
#####delete_all(available only under the development environment)
|
252
|
+
|
253
|
+
Deletes all instances of the given resource
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
#in case this method is executed under the production environment an OpenpayException will be raised.
|
257
|
+
open_pay_resource.delete_all(customer_id=nil)
|
258
|
+
```
|
259
|
+
|
260
|
+
|
261
|
+
#### Exceptions
|
262
|
+
|
263
|
+
This API generates 3 different Exception classes.
|
264
|
+
|
265
|
+
|
266
|
+
- **OpenpayApiError**: Generic base api exception class, for generic api exceptions.
|
267
|
+
|
268
|
+
- Internal server error (500 Internal Server Error)
|
269
|
+
- OpenpayApi factory method, invalid resource name.
|
270
|
+
|
271
|
+
Example:
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
#production mode
|
275
|
+
openpayprod=OpenpayApi.new(@merchant_id,@private_key,true)
|
276
|
+
cust.delete_all # will raise an OpenpayException
|
277
|
+
```
|
278
|
+
|
279
|
+
- **OpenpayApiConnectionError**: Exception class for connection related issues, errors happening prior the server connection.
|
280
|
+
|
281
|
+
- Authentication Error (401 Unauthorized)
|
282
|
+
- Connection Errors.
|
283
|
+
- SSL Errors.
|
284
|
+
|
285
|
+
Example:
|
286
|
+
```ruby
|
287
|
+
#invalid id and key
|
288
|
+
merchant_id='santa'
|
289
|
+
private_key='invalid'
|
290
|
+
|
291
|
+
openpay=OpenpayApi.new(merchant_id, private_key)
|
292
|
+
customers=openpay.create(:customers)
|
293
|
+
|
294
|
+
begin
|
295
|
+
customers.get('23444422211')
|
296
|
+
rescue OpenpayApiConnectionError => e
|
297
|
+
e.http_code # => 401
|
298
|
+
e.error_code # => 1002
|
299
|
+
e.description# => 'The api key or merchant id are invalid.'
|
300
|
+
e.json_body # {"category":"request","description":"The api key or merchant id are invalid.","http_code":401,"error_code":1002,"request_id":null}
|
301
|
+
end
|
302
|
+
```
|
303
|
+
|
304
|
+
- **OpenpayApiTransactionError**: Errors happening after the initial connection has been initiated, errors during transactions.
|
305
|
+
|
306
|
+
- Bad Request (e.g. Malformed json,Invalid data)
|
307
|
+
- Unprocessable Entity (e.g. invalid data)
|
308
|
+
- Resource not found (404 Not Found)
|
309
|
+
- Conflict (e.g. resource already exists)
|
310
|
+
- PaymentRequired (e.g. insufficient funds)
|
311
|
+
- UnprocessableEntity ( e.g. stolen card )
|
312
|
+
|
313
|
+
*Bad Request* Example:
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
email='foo'
|
317
|
+
customer_hash = FactoryGirl.build(:customer, email: email)
|
318
|
+
begin
|
319
|
+
customers.create(customer_hash)
|
320
|
+
rescue OpenpayApiTransactionError => e
|
321
|
+
e.http_code# => 400
|
322
|
+
e.error_code# => 1001
|
323
|
+
e.description# => 'email\' not a well-formed email address'
|
324
|
+
end
|
325
|
+
```
|
326
|
+
|
327
|
+
*Resource not found* Example:
|
328
|
+
|
329
|
+
```ruby
|
330
|
+
begin
|
331
|
+
#non existing customer
|
332
|
+
customers.delete('1111')
|
333
|
+
rescue OpenpayApiTransactionError => e
|
334
|
+
e.http_code# => 404
|
335
|
+
e.error_code# =>1005
|
336
|
+
e.description# =>"The customer with id '1111' does not exist"
|
337
|
+
end
|
338
|
+
```
|
339
|
+
|
340
|
+
|
341
|
+
###These exceptions have the following attributes:
|
342
|
+
|
343
|
+
- *category*
|
344
|
+
- *description*
|
345
|
+
- *http_code*
|
346
|
+
- *error_code*
|
347
|
+
- *json_message*
|
348
|
+
|
349
|
+
For more information about categories, descriptions and codes take a look at:
|
350
|
+
- http://docs.openpay.mx/#errores
|
351
|
+
- http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
352
|
+
|
353
|
+
|
354
|
+
##Debug
|
355
|
+
|
356
|
+
In the Openpay dashboard you are able to see every request and its corresponding request/response.
|
357
|
+
- https://sandbox-dashboard.openpay.mx
|
358
|
+
|
359
|
+
|
360
|
+
##Developer Notes
|
361
|
+
|
362
|
+
- bank accounts for merchant cannot be created using the api. It should be done through the dashboard.
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
## More information
|
367
|
+
|
368
|
+
For more use cases take a look at the *test/spec* folder
|
369
|
+
|
370
|
+
1. http://docs.openpay.mx/
|