ianfleeton-paypal-express 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +22 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +11 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE +20 -0
  8. data/README.rdoc +43 -0
  9. data/Rakefile +19 -0
  10. data/VERSION +1 -0
  11. data/ianfleeton-paypal-express.gemspec +24 -0
  12. data/lib/paypal.rb +86 -0
  13. data/lib/paypal/base.rb +19 -0
  14. data/lib/paypal/exception.rb +4 -0
  15. data/lib/paypal/exception/api_error.rb +94 -0
  16. data/lib/paypal/exception/http_error.rb +12 -0
  17. data/lib/paypal/express.rb +1 -0
  18. data/lib/paypal/express/request.rb +186 -0
  19. data/lib/paypal/express/response.rb +35 -0
  20. data/lib/paypal/ipn.rb +23 -0
  21. data/lib/paypal/nvp/request.rb +66 -0
  22. data/lib/paypal/nvp/response.rb +237 -0
  23. data/lib/paypal/payment/common/amount.rb +13 -0
  24. data/lib/paypal/payment/recurring.rb +43 -0
  25. data/lib/paypal/payment/recurring/activation.rb +14 -0
  26. data/lib/paypal/payment/recurring/billing.rb +39 -0
  27. data/lib/paypal/payment/recurring/summary.rb +11 -0
  28. data/lib/paypal/payment/request.rb +67 -0
  29. data/lib/paypal/payment/request/item.rb +26 -0
  30. data/lib/paypal/payment/response.rb +75 -0
  31. data/lib/paypal/payment/response/address.rb +7 -0
  32. data/lib/paypal/payment/response/info.rb +45 -0
  33. data/lib/paypal/payment/response/item.rb +41 -0
  34. data/lib/paypal/payment/response/payee_info.rb +7 -0
  35. data/lib/paypal/payment/response/payer.rb +7 -0
  36. data/lib/paypal/payment/response/reference.rb +23 -0
  37. data/lib/paypal/payment/response/refund.rb +17 -0
  38. data/lib/paypal/payment/response/refund_info.rb +7 -0
  39. data/lib/paypal/util.rb +27 -0
  40. data/spec/fake_response/BillAgreementUpdate/fetch.txt +1 -0
  41. data/spec/fake_response/BillAgreementUpdate/revoke.txt +1 -0
  42. data/spec/fake_response/CreateBillingAgreement/success.txt +1 -0
  43. data/spec/fake_response/CreateRecurringPaymentsProfile/failure.txt +1 -0
  44. data/spec/fake_response/CreateRecurringPaymentsProfile/success.txt +1 -0
  45. data/spec/fake_response/DoCapture/failure.txt +1 -0
  46. data/spec/fake_response/DoCapture/success.txt +1 -0
  47. data/spec/fake_response/DoExpressCheckoutPayment/failure.txt +1 -0
  48. data/spec/fake_response/DoExpressCheckoutPayment/success.txt +1 -0
  49. data/spec/fake_response/DoExpressCheckoutPayment/success_with_billing_agreement.txt +1 -0
  50. data/spec/fake_response/DoExpressCheckoutPayment/success_with_many_items.txt +1 -0
  51. data/spec/fake_response/DoReferenceTransaction/failure.txt +1 -0
  52. data/spec/fake_response/DoReferenceTransaction/success.txt +1 -0
  53. data/spec/fake_response/DoVoid/success.txt +1 -0
  54. data/spec/fake_response/GetExpressCheckoutDetails/failure.txt +1 -0
  55. data/spec/fake_response/GetExpressCheckoutDetails/success.txt +1 -0
  56. data/spec/fake_response/GetExpressCheckoutDetails/with_billing_accepted_status.txt +1 -0
  57. data/spec/fake_response/GetRecurringPaymentsProfileDetails/failure.txt +1 -0
  58. data/spec/fake_response/GetRecurringPaymentsProfileDetails/success.txt +1 -0
  59. data/spec/fake_response/GetTransactionDetails/failure.txt +1 -0
  60. data/spec/fake_response/GetTransactionDetails/success.txt +1 -0
  61. data/spec/fake_response/IPN/invalid.txt +1 -0
  62. data/spec/fake_response/IPN/valid.txt +1 -0
  63. data/spec/fake_response/ManageRecurringPaymentsProfileStatus/failure.txt +1 -0
  64. data/spec/fake_response/ManageRecurringPaymentsProfileStatus/success.txt +1 -0
  65. data/spec/fake_response/RefundTransaction/full.txt +1 -0
  66. data/spec/fake_response/SetExpressCheckout/failure.txt +1 -0
  67. data/spec/fake_response/SetExpressCheckout/success.txt +1 -0
  68. data/spec/helpers/fake_response_helper.rb +29 -0
  69. data/spec/paypal/exception/api_error_spec.rb +105 -0
  70. data/spec/paypal/exception/http_error_spec.rb +20 -0
  71. data/spec/paypal/express/request_spec.rb +578 -0
  72. data/spec/paypal/express/response_spec.rb +89 -0
  73. data/spec/paypal/ipn_spec.rb +19 -0
  74. data/spec/paypal/nvp/request_spec.rb +113 -0
  75. data/spec/paypal/nvp/response_spec.rb +175 -0
  76. data/spec/paypal/payment/common/amount_spec.rb +36 -0
  77. data/spec/paypal/payment/recurring/activation_spec.rb +19 -0
  78. data/spec/paypal/payment/recurring_spec.rb +170 -0
  79. data/spec/paypal/payment/request/item_spec.rb +27 -0
  80. data/spec/paypal/payment/request_spec.rb +136 -0
  81. data/spec/paypal/payment/response/address_spec.rb +26 -0
  82. data/spec/paypal/payment/response/info_spec.rb +93 -0
  83. data/spec/paypal/payment/response/item_spec.rb +78 -0
  84. data/spec/paypal/payment/response/payee_info_spec.rb +24 -0
  85. data/spec/paypal/payment/response/payer_spec.rb +26 -0
  86. data/spec/paypal/payment/response/reference_info_spec.rb +36 -0
  87. data/spec/paypal/payment/response/refund_info_spec.rb +18 -0
  88. data/spec/paypal/payment/response/refund_spec.rb +28 -0
  89. data/spec/paypal/payment/response_spec.rb +29 -0
  90. data/spec/paypal/util_spec.rb +32 -0
  91. data/spec/spec_helper.rb +25 -0
  92. metadata +319 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b3867967578bb74d22b8fc5d931c62a01fa890c
4
+ data.tar.gz: 97b4500f7158307eb8fb5183367cd3046bb968cf
5
+ SHA512:
6
+ metadata.gz: 1959ef947bd20eb3fb27d9a439dc657e51871be138e8f1f293307170fbf63781b11483de776cf4709b7dc39d5ba9adbf13237a3b12d0d801bac6a46ad8e415e1
7
+ data.tar.gz: 3f8fa18f46458fcb4f1390c3d8a2fbe91cafebdb3c16dce2908e0726f89f9f43ea96721f9924f7b921574e7a5d563529d18db6b14f986a1acc007236bbb90c75
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage*
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=documentation
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ before_install:
2
+ - gem install bundler
3
+
4
+ rvm:
5
+ - 2.2.7
6
+ - 2.3.4
7
+ - 2.4.1
8
+
9
+ env:
10
+ - RAILS_VERSION="~> 4.2"
11
+ - RAILS_VERSION="~> 5.0"
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ platform :jruby do
4
+ gem 'jruby-openssl', '>= 0.7'
5
+ end
6
+
7
+ if ENV['RAILS_VERSION']
8
+ gem 'activesupport', ENV['RAILS_VERSION']
9
+ end
10
+
11
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright © 2011 Ian Fleeton, nov matake
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = paypal-express
2
+
3
+ Handle PayPal Express Checkout.
4
+ Both Instance Payment and Recurring Payment are supported.
5
+ Express Checkout for Digital Goods is also supported.
6
+
7
+ {<img src="https://travis-ci.org/ianfleeton/paypal-express.svg" />}[https://travis-ci.org/ianfleeton/paypal-express]
8
+
9
+
10
+ == Why this fork?
11
+
12
+ The original gem is not maintained and has broken compatibility with current PayPal APIs.
13
+ You can use this fork which is actively maintained to ensure it is working properly.
14
+
15
+ == Installation
16
+
17
+ Add to your Gemfile
18
+ gem 'paypal-express', github: 'ianfleeton/paypal-express'
19
+ Or
20
+ gem 'ianfleeton-paypal-express'
21
+
22
+ == Usage
23
+
24
+ See Wiki on Github
25
+ https://github.com/nov/paypal-express/wiki
26
+
27
+ Play with Sample Rails App
28
+ https://github.com/nov/paypal-express-sample
29
+ https://paypal-express-sample.heroku.com
30
+
31
+ == Note on Patches/Pull Requests
32
+
33
+ * Fork the project.
34
+ * Make your feature addition or bug fix.
35
+ * Add tests for it. This is important so I don't break it in a
36
+ future version unintentionally.
37
+ * Commit, do not mess with rakefile, version, or history.
38
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
39
+ * Send me a pull request. Bonus points for topic branches.
40
+
41
+ == Copyright
42
+
43
+ Copyright © 2011 Ian Fleeton, nov matake. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ namespace :coverage do
8
+ desc "Open coverage report"
9
+ task :report do
10
+ require 'simplecov'
11
+ `open "#{File.join SimpleCov.coverage_path, 'index.html'}"`
12
+ end
13
+ end
14
+
15
+ task :spec do
16
+ Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
17
+ end
18
+
19
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8.2
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ianfleeton-paypal-express"
3
+ s.version = File.read(File.join(File.dirname(__FILE__), "VERSION"))
4
+ s.licenses = ['MIT']
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Ian Fleeton", "nov matake"]
7
+ s.description = %q{PayPal Express Checkout API Client for Instance, Recurring and Digital Goods Payment.}
8
+ s.summary = %q{PayPal Express Checkout API Client for Instance, Recurring and Digital Goods Payment.}
9
+ s.email = 'ianfleeton@gmail.com'
10
+ s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
11
+ s.rdoc_options = ["--charset=UTF-8"]
12
+ s.homepage = "http://github.com/ianfleeton/paypal-express"
13
+ s.require_paths = ["lib"]
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.add_dependency 'activesupport', '>= 2.3', '< 6'
18
+ s.add_dependency 'rest-client', '~> 2.0'
19
+ s.add_dependency 'attr_required', '~> 0.0', '>= 0.0.5'
20
+ s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
21
+ s.add_development_dependency 'simplecov', '~> 0'
22
+ s.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
23
+ s.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
24
+ end
data/lib/paypal.rb ADDED
@@ -0,0 +1,86 @@
1
+ require 'logger'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+ require 'attr_required'
5
+ require 'attr_optional'
6
+ require 'rest_client'
7
+
8
+ module Paypal
9
+ mattr_accessor :api_version
10
+ self.api_version = '204.0'
11
+
12
+ ENDPOINT = {
13
+ :production => 'https://www.paypal.com/cgi-bin/webscr',
14
+ :sandbox => 'https://www.sandbox.paypal.com/cgi-bin/webscr'
15
+ }
16
+ POPUP_ENDPOINT = {
17
+ :production => 'https://www.paypal.com/incontext',
18
+ :sandbox => 'https://www.sandbox.paypal.com/incontext'
19
+ }
20
+
21
+ def self.endpoint
22
+ if sandbox?
23
+ Paypal::ENDPOINT[:sandbox]
24
+ else
25
+ Paypal::ENDPOINT[:production]
26
+ end
27
+ end
28
+ def self.popup_endpoint
29
+ if sandbox?
30
+ Paypal::POPUP_ENDPOINT[:sandbox]
31
+ else
32
+ Paypal::POPUP_ENDPOINT[:production]
33
+ end
34
+ end
35
+
36
+ def self.log(message, mode = :info)
37
+ self.logger.send mode, message
38
+ end
39
+ def self.logger
40
+ @@logger
41
+ end
42
+ def self.logger=(logger)
43
+ @@logger = logger
44
+ end
45
+ @@logger = Logger.new(STDERR)
46
+ @@logger.progname = 'Paypal::Express'
47
+
48
+ def self.sandbox?
49
+ @@sandbox
50
+ end
51
+ def self.sandbox!
52
+ self.sandbox = true
53
+ end
54
+ def self.sandbox=(boolean)
55
+ @@sandbox = boolean
56
+ end
57
+ self.sandbox = false
58
+
59
+ end
60
+
61
+ require 'paypal/util'
62
+ require 'paypal/exception'
63
+ require 'paypal/exception/http_error'
64
+ require 'paypal/exception/api_error'
65
+ require 'paypal/base'
66
+ require 'paypal/ipn'
67
+ require 'paypal/nvp/request'
68
+ require 'paypal/nvp/response'
69
+ require 'paypal/payment/common/amount'
70
+ require 'paypal/express/request'
71
+ require 'paypal/express/response'
72
+ require 'paypal/payment/request'
73
+ require 'paypal/payment/request/item'
74
+ require 'paypal/payment/response'
75
+ require 'paypal/payment/response/info'
76
+ require 'paypal/payment/response/item'
77
+ require 'paypal/payment/response/payee_info'
78
+ require 'paypal/payment/response/payer'
79
+ require 'paypal/payment/response/reference'
80
+ require 'paypal/payment/response/refund'
81
+ require 'paypal/payment/response/refund_info'
82
+ require 'paypal/payment/response/address'
83
+ require 'paypal/payment/recurring'
84
+ require 'paypal/payment/recurring/activation'
85
+ require 'paypal/payment/recurring/billing'
86
+ require 'paypal/payment/recurring/summary'
@@ -0,0 +1,19 @@
1
+ module Paypal
2
+ class Base
3
+ include AttrRequired, AttrOptional, Util
4
+
5
+ def initialize(attributes = {})
6
+ if attributes.is_a?(Hash)
7
+ (required_attributes + optional_attributes).each do |key|
8
+ value = if numeric_attribute?(key)
9
+ Util.to_numeric(attributes[key])
10
+ else
11
+ attributes[key]
12
+ end
13
+ self.send "#{key}=", value
14
+ end
15
+ end
16
+ attr_missing!
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module Paypal
2
+ class Exception < StandardError
3
+ end
4
+ end
@@ -0,0 +1,94 @@
1
+ module Paypal
2
+ class Exception
3
+ class APIError < Exception
4
+ attr_accessor :response
5
+ def initialize(response = {})
6
+ @response = if response.is_a?(Hash)
7
+ Response.new response
8
+ else
9
+ response
10
+ end
11
+ end
12
+
13
+ def message
14
+ if response.respond_to?(:short_messages) && response.short_messages.any?
15
+ "PayPal API Error: " <<
16
+ response.short_messages.map{ |m| "'#{m}'" }.join(", ")
17
+ else
18
+ "PayPal API Error"
19
+ end
20
+ end
21
+
22
+ class Response
23
+ cattr_reader :attribute_mapping
24
+ @@attribute_mapping = {
25
+ :ACK => :ack,
26
+ :BUILD => :build,
27
+ :CORRELATIONID => :correlation_id,
28
+ :TIMESTAMP => :timestamp,
29
+ :VERSION => :version,
30
+ :ORDERTIME => :order_time,
31
+ :PENDINGREASON => :pending_reason,
32
+ :PAYMENTSTATUS => :payment_status,
33
+ :PAYMENTTYPE => :payment_type,
34
+ :REASONCODE => :reason_code,
35
+ :TRANSACTIONTYPE => :transaction_type
36
+ }
37
+ attr_accessor *@@attribute_mapping.values
38
+ attr_accessor :raw, :details
39
+ alias_method :colleration_id, :correlation_id # NOTE: I made a typo :p
40
+
41
+ class Detail
42
+ cattr_reader :attribute_mapping
43
+ @@attribute_mapping = {
44
+ :ERRORCODE => :error_code,
45
+ :SEVERITYCODE => :severity_code,
46
+ :LONGMESSAGE => :long_message,
47
+ :SHORTMESSAGE => :short_message
48
+ }
49
+ attr_accessor *@@attribute_mapping.values
50
+
51
+ def initialize(attributes = {})
52
+ @raw = attributes
53
+ attrs = attributes.dup
54
+ @@attribute_mapping.each do |key, value|
55
+ self.send "#{value}=", attrs.delete(key)
56
+ end
57
+
58
+ # warn ignored params
59
+ attrs.each do |key, value|
60
+ Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
61
+ end
62
+ end
63
+ end
64
+
65
+ def initialize(attributes = {})
66
+ attrs = attributes.dup
67
+ @raw = attributes
68
+ @@attribute_mapping.each do |key, value|
69
+ self.send "#{value}=", attrs.delete(key)
70
+ end
71
+ details = []
72
+ attrs.keys.each do |attribute|
73
+ key, index = attribute.to_s.scan(/^L_(\S+)(\d+)$/).first
74
+ next if [key, index].any?(&:blank?)
75
+ details[index.to_i] ||= {}
76
+ details[index.to_i][key.to_sym] = attrs.delete(attribute)
77
+ end
78
+ @details = details.collect do |_attrs_|
79
+ Detail.new _attrs_
80
+ end
81
+
82
+ # warn ignored params
83
+ attrs.each do |key, value|
84
+ Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
85
+ end
86
+ end
87
+
88
+ def short_messages
89
+ details.map(&:short_message).compact
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,12 @@
1
+ module Paypal
2
+ class Exception
3
+ class HttpError < Exception
4
+ attr_accessor :code, :message, :body
5
+ def initialize(code, message, body = '')
6
+ @code = code
7
+ @message = message
8
+ @body = body
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ require 'paypal'
@@ -0,0 +1,186 @@
1
+ module Paypal
2
+ module Express
3
+ class Request < NVP::Request
4
+
5
+ # Common
6
+
7
+ def setup(payment_requests, return_url, cancel_url, options = {})
8
+ params = {
9
+ RETURNURL: return_url,
10
+ CANCELURL: cancel_url
11
+ }
12
+ if options[:no_shipping]
13
+ params[:REQCONFIRMSHIPPING] = 0
14
+ params[:NOSHIPPING] = 1
15
+ end
16
+
17
+ params[:ALLOWNOTE] = 0 if options[:allow_note] == false
18
+
19
+ {
20
+ :solution_type => :SOLUTIONTYPE,
21
+ :landing_page => :LANDINGPAGE,
22
+ :email => :EMAIL,
23
+ :brand => :BRANDNAME,
24
+ :locale => :LOCALECODE,
25
+ :logo => :LOGOIMG,
26
+ :cart_border_color => :CARTBORDERCOLOR,
27
+ :payflow_color => :PAYFLOWCOLOR
28
+ }.each do |option_key, param_key|
29
+ params[param_key] = options[option_key] if options[option_key]
30
+ end
31
+ Array(payment_requests).each_with_index do |payment_request, index|
32
+ params.merge! payment_request.to_params(index)
33
+ end
34
+ response = self.request :SetExpressCheckout, params
35
+ Response.new response, options
36
+ end
37
+
38
+ def details(token)
39
+ response = self.request :GetExpressCheckoutDetails, { TOKEN: token }
40
+ Response.new response
41
+ end
42
+
43
+ def transaction_details(transaction_id)
44
+ response = self.request :GetTransactionDetails, {:TRANSACTIONID=> transaction_id}
45
+ Response.new response
46
+ end
47
+
48
+ def checkout!(token, payer_id, payment_requests)
49
+ params = {
50
+ TOKEN: token,
51
+ PAYERID: payer_id
52
+ }
53
+ Array(payment_requests).each_with_index do |payment_request, index|
54
+ params.merge! payment_request.to_params(index)
55
+ end
56
+ response = self.request :DoExpressCheckoutPayment, params
57
+ Response.new response
58
+ end
59
+
60
+ def capture!(authorization_id, amount, currency_code, complete_type = 'Complete')
61
+ params = {
62
+ :AUTHORIZATIONID => authorization_id,
63
+ :COMPLETETYPE => complete_type,
64
+ :AMT => amount,
65
+ :CURRENCYCODE => currency_code
66
+ }
67
+
68
+ response = self.request :DoCapture, params
69
+ Response.new response
70
+ end
71
+
72
+ def void!(authorization_id, params={})
73
+ params = {
74
+ :AUTHORIZATIONID => authorization_id,
75
+ :NOTE => params[:note]
76
+ }
77
+
78
+ response = self.request :DoVoid, params
79
+ Response.new response
80
+ end
81
+
82
+ # Recurring Payment Specific
83
+
84
+ def subscribe!(token, recurring_profile)
85
+ params = { TOKEN: token }
86
+ params.merge! recurring_profile.to_params
87
+ response = self.request :CreateRecurringPaymentsProfile, params
88
+ Response.new response
89
+ end
90
+
91
+ def subscription(profile_id)
92
+ params = { PROFILEID: profile_id }
93
+ response = self.request :GetRecurringPaymentsProfileDetails, params
94
+ Response.new response
95
+ end
96
+
97
+ def renew!(profile_id, action, options = {})
98
+ params = {
99
+ :PROFILEID => profile_id,
100
+ :ACTION => action
101
+ }
102
+ if options[:note]
103
+ params[:NOTE] = options[:note]
104
+ end
105
+ response = self.request :ManageRecurringPaymentsProfileStatus, params
106
+ Response.new response
107
+ end
108
+
109
+ def suspend!(profile_id, options = {})
110
+ renew!(profile_id, :Suspend, options)
111
+ end
112
+
113
+ def cancel!(profile_id, options = {})
114
+ renew!(profile_id, :Cancel, options)
115
+ end
116
+
117
+ def reactivate!(profile_id, options = {})
118
+ renew!(profile_id, :Reactivate, options)
119
+ end
120
+
121
+
122
+ # Reference Transaction Specific
123
+
124
+ def agree!(token, options = {})
125
+ params = { TOKEN: token }
126
+ if options[:max_amount]
127
+ params[:MAXAMT] = Util.formatted_amount options[:max_amount]
128
+ end
129
+ response = self.request :CreateBillingAgreement, params
130
+ Response.new response
131
+ end
132
+
133
+ def agreement(reference_id)
134
+ params = { REFERENCEID: reference_id }
135
+ response = self.request :BillAgreementUpdate, params
136
+ Response.new response
137
+ end
138
+
139
+ def charge!(reference_id, amount, options = {})
140
+ params = {
141
+ :REFERENCEID => reference_id,
142
+ :AMT => Util.formatted_amount(amount),
143
+ :PAYMENTACTION => options[:payment_action] || :Sale
144
+ }
145
+ if options[:currency_code]
146
+ params[:CURRENCYCODE] = options[:currency_code]
147
+ end
148
+ response = self.request :DoReferenceTransaction, params
149
+ Response.new response
150
+ end
151
+
152
+ def revoke!(reference_id)
153
+ params = {
154
+ :REFERENCEID => reference_id,
155
+ :BillingAgreementStatus => :Canceled
156
+ }
157
+ response = self.request :BillAgreementUpdate, params
158
+ Response.new response
159
+ end
160
+
161
+
162
+ # Refund Specific
163
+
164
+ def refund!(transaction_id, options = {})
165
+ params = {
166
+ :TRANSACTIONID => transaction_id,
167
+ :REFUNDTYPE => :Full
168
+ }
169
+ if options[:invoice_id]
170
+ params[:INVOICEID] = options[:invoice_id]
171
+ end
172
+ if options[:type]
173
+ params[:REFUNDTYPE] = options[:type]
174
+ params[:AMT] = options[:amount]
175
+ params[:CURRENCYCODE] = options[:currency_code]
176
+ end
177
+ if options[:note]
178
+ params[:NOTE] = options[:note]
179
+ end
180
+ response = self.request :RefundTransaction, params
181
+ Response.new response
182
+ end
183
+
184
+ end
185
+ end
186
+ end