atpay_buttons 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +22 -0
- data/README.md +210 -0
- data/Rakefile +21 -0
- data/atpay_buttons.gemspec +23 -0
- data/bin/atpay_buttons +62 -0
- data/circle.yml +17 -0
- data/imgs/sample_button.png +0 -0
- data/lib/atpay/button/generator.rb +109 -0
- data/lib/atpay/button/template.rb +109 -0
- data/lib/atpay/button/templates/default.liquid +102 -0
- data/lib/atpay/button/templates/mailto_body.liquid +1 -0
- data/lib/atpay/button/templates/wrap_default.liquid +160 -0
- data/lib/atpay/button/templates/wrap_yahoo.liquid +166 -0
- data/lib/atpay/button/templates/yahoo.liquid +102 -0
- data/lib/atpay_buttons.rb +5 -0
- data/spec/command_line_spec.rb +31 -0
- data/spec/fixtures/templates/default.liquid +1 -0
- data/spec/fixtures/templates/mailto_body.liquid +1 -0
- data/spec/fixtures/templates/wrap_default.liquid +1 -0
- data/spec/fixtures/templates/wrap_yahoo.liquid +1 -0
- data/spec/fixtures/templates/yahoo.liquid +1 -0
- data/spec/generator_spec.rb +86 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/template_spec.rb +66 -0
- data/test_data.txt +3 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc892b9c316fd7e96cc99f42ebe7a0bba1f53949
|
4
|
+
data.tar.gz: b8c61bd615e5e89262731cce90b096a188f7e0c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edc1c99a639364a7ecd3cee17dfe41b2f92cb74174d224c9b3cd43d4e8bdcb21e5e4171b1b16cd66014a1f60a8dd0744f0c88211dab1a66090676ad0b6e7f276
|
7
|
+
data.tar.gz: ff483113e4bd40af28c2635c9c720daf2411da5c98a64ad140efbeef6aefa8ac4988ee8806e5f9b4f2adc31fa084b551e71e39215a3124fe5f736aa39367c1e2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in atpay-button-generator.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'liquid'
|
7
|
+
gem 'atpay_tokens'
|
8
|
+
gem 'activesupport', '4.0.0'
|
9
|
+
gem 'trollop'
|
10
|
+
|
11
|
+
# Test-specific gems
|
12
|
+
group :test do
|
13
|
+
gem 'capybara', '~> 1.1.0'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :development, :test do
|
17
|
+
gem 'pry'
|
18
|
+
gem 'minitest', '> 3.1.0'
|
19
|
+
gem 'minitest-reporters', '>= 0.5.0', :github => "atpay/minitest-reporters", :require => false
|
20
|
+
gem 'simplecov'
|
21
|
+
gem 'mocha'
|
22
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
# @Pay Payment Button Generator
|
2
|
+
|
3
|
+
The @Pay payment button generator creates @Pay two-click buttons that you can send
|
4
|
+
to your mailing list to collect funds via email.
|
5
|
+
|
6
|
+
When using two-click buttons in emails, you want to make sure that they are compatible
|
7
|
+
in as many environments (clients/browsers/devices) as possible. This can be a painstaking
|
8
|
+
task because all environments render buttons differently. Buttons generated with this
|
9
|
+
tool are cross-platform and cross-browser compatible. This means that the two-click
|
10
|
+
experience can be enjoyed on over 93% of browser, platform, and device combinations.
|
11
|
+
The generator uses domain targeting and outputs html from a specific template depending
|
12
|
+
on the email parameter. These templates include two sets of buttons. A CSS rule set will
|
13
|
+
determine which button will be displayed on the end users device and browser. For more
|
14
|
+
information on cross compatibility,
|
15
|
+
visit https://www.atpay.com/cross-compatible-mailto-links-mobile-browsers.
|
16
|
+
|
17
|
+
You can use this library directly from your Ruby-based application, or you can
|
18
|
+
interface with it via the command line from most any language.
|
19
|
+
|
20
|
+
The provided Liquid templates are customizable here, or can be used as
|
21
|
+
a starting point for your own implementation.
|
22
|
+
|
23
|
+
This library is a convenience wrapper around the [@Pay Client
|
24
|
+
Library](https://github.com/atpay/atpay-client). You may use both together or
|
25
|
+
each independently, though this library does internally depend on the client
|
26
|
+
library.
|
27
|
+
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
If your application is based on Ruby and you use Bundler, add the following line
|
32
|
+
to your application's Gemfile:
|
33
|
+
|
34
|
+
gem 'atpay-button-generator'
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
If you'd like to use the command line interface, or are not using Bundler, you
|
41
|
+
can install the gem on your system with:
|
42
|
+
|
43
|
+
$ gem install atpay-button-generator
|
44
|
+
|
45
|
+
## Requirements
|
46
|
+
|
47
|
+
Ruby >= 1.9
|
48
|
+
|
49
|
+
## Command Line Usage
|
50
|
+
|
51
|
+
You'll need a partner id, public key and private key from your @Pay signup. More
|
52
|
+
advanced implementations may be using OAuth to collect this information from
|
53
|
+
multiple partners and can generate buttons on behalf of merchants that use their
|
54
|
+
system.
|
55
|
+
|
56
|
+
After installing the atpay-button-generator gem, you'll have
|
57
|
+
`atpay-button-generator` script in your gem binpath. Run it with
|
58
|
+
the help flag to get information on how to use it:
|
59
|
+
|
60
|
+
|
61
|
+
$ atpay-button-generator --help
|
62
|
+
|
63
|
+
The button generator requires a few flags up front:
|
64
|
+
|
65
|
+
### Parameters
|
66
|
+
|
67
|
+
<p><strong>amount (required): </strong> <br />
|
68
|
+
<i> The amount a user should be charged for transactions after clicking this button</i></p>
|
69
|
+
|
70
|
+
<p><strong>private-key (required):</strong> <br />
|
71
|
+
<i> The private key given to you by @Pay</i></p>
|
72
|
+
|
73
|
+
<p><strong>public-key (required):</strong> <br />
|
74
|
+
<i> @Pay's public key, given to you by @Pay</i></p>
|
75
|
+
|
76
|
+
<p><strong>partner-id (required):</strong> <br />
|
77
|
+
<i> The partner ID given to you by @Pay</i></p>
|
78
|
+
|
79
|
+
<p><strong>subject:</strong> <br />
|
80
|
+
<i> The subject of the mailto: email <br/> (the message that a user will be sending to @Pay's servers after clicking the button)</i></p>
|
81
|
+
|
82
|
+
<p><strong>image:</strong> <br />
|
83
|
+
<i> The URL to a small thumbnail image to be used in the button <br /> Default: https://www.atpay.com/wp-content/themes/atpay/images/bttn_cart.png</i></p>
|
84
|
+
|
85
|
+
<p><strong>color:</strong> <br />
|
86
|
+
<i> The background color of the button <br /> Default: #6dbe45</i></p>
|
87
|
+
|
88
|
+
<p><strong>title:</strong> <br />
|
89
|
+
<i> The title for each button</i></p>
|
90
|
+
|
91
|
+
<p><strong>wrap:</strong> <br />
|
92
|
+
<i> Will use wrapped (with a styled div container) version of template <br /> Default: false</i></p>
|
93
|
+
|
94
|
+
<p><strong>templates:</strong> <br />
|
95
|
+
<i> Location of button templates <br /> Default: ./lib/atpay/button/templates</i></p>
|
96
|
+
|
97
|
+
<p><strong>env:</strong> <br />
|
98
|
+
<i> The environment you want to generate buttons for; currently sandbox or production<br /> Default: production</i></p>
|
99
|
+
|
100
|
+
<p><strong>user_data:</strong> <br />
|
101
|
+
<i> Optional user data to be passed in as a string for your use </i></p>
|
102
|
+
|
103
|
+
<p><strong>input: </strong> <br />
|
104
|
+
<i> Input File
|
105
|
+
<br /> Default: $stdin<sup>*</sup></i></p>
|
106
|
+
|
107
|
+
<sup>*</sup>Reads from STDIN a comma delimmited file with each line containing the
|
108
|
+
email address you're sending the button to and the credit card token you've
|
109
|
+
received from @Pay for that button:
|
110
|
+
|
111
|
+
test1@example.com,TL1UwJFXVN7e4p6+0B5N8hy4qQyqeNxVllmC663MLcMupuAWXdHJ9g8PRAnlIh+AMZBgpaIrfWStZ5/3hYi6vCAV7q6+3M6LLqxk
|
112
|
+
test2@example.com,XKCF2E9QZPwdOSwfTQJzZC7byLt3PH8Tr1KhmLkfRHwfNJD5XbDRMrxGYOiSnfrLEKNzm9+a4r++bpUG2hNrPyYLpNgph3BXAAfC
|
113
|
+
test3@example.com,iQOxdBV4KrFuPFgyywxytfbsD/rURrzmlADmg1QFP2VHd/kTnkXNpnp2Utv4RS0Zz2YeOloilMhljsOcRVA2YwSu9knwF1h6tNjE
|
114
|
+
|
115
|
+
### Example
|
116
|
+
|
117
|
+
$ atpay-button-generator --title "Pay" --amount 50.00 --subject "Payment for fifty bucks" --private-key "" --public-key "" --partner-id 20 --input input.txt
|
118
|
+
|
119
|
+
Where input.txt contains
|
120
|
+
|
121
|
+
test1@example.com,TL1UwJFXVN7e4p6+0B5N8hy4qQyqeNxVllmC663MLcMupuAWXdHJ9g8PRAnlIh+AMZBgpaIrfWStZ5/3hYi6vCAV7q6+3M6LLqxk
|
122
|
+
test2@example.com,XKCF2E9QZPwdOSwfTQJzZC7byLt3PH8Tr1KhmLkfRHwfNJD5XbDRMrxGYOiSnfrLEKNzm9+a4r++bpUG2hNrPyYLpNgph3BXAAfC
|
123
|
+
test3@example.com,iQOxdBV4KrFuPFgyywxytfbsD/rURrzmlADmg1QFP2VHd/kTnkXNpnp2Utv4RS0Zz2YeOloilMhljsOcRVA2YwSu9knwF1h6tNjE
|
124
|
+
|
125
|
+
will output three buttons, one for each of the email addresses above, in HTML
|
126
|
+
format, one per line. If you're sending out one offer per email, you'll simply
|
127
|
+
include each line in the outgoing message to the recipient (one to
|
128
|
+
test1@example.com, one to test2@example.com, and one to test3@example.com).
|
129
|
+
|
130
|
+
A button from the example above looks like this:
|
131
|
+
|
132
|
+

|
133
|
+
|
134
|
+
|
135
|
+
## Library Usage
|
136
|
+
|
137
|
+
After following the installation instructions above, you'll have the @Pay button
|
138
|
+
generator library loaded in your application. Let's create an array containing
|
139
|
+
hashes with our users' email address and html code for a button to deliver to
|
140
|
+
htem:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
require 'rubygems'
|
144
|
+
require 'atpay-button-generator'
|
145
|
+
|
146
|
+
button_maker = AtPay::Button::Generator.new({
|
147
|
+
public_key: ATPAY_PUBLIC,
|
148
|
+
private_key: ATPAY_PRIVATE,
|
149
|
+
partner_id: ATPAY_PARTNER,
|
150
|
+
environment: :sandbox,
|
151
|
+
amount: 20
|
152
|
+
})
|
153
|
+
|
154
|
+
output = []
|
155
|
+
|
156
|
+
User.active.each do |user|
|
157
|
+
output << {
|
158
|
+
email: user.email,
|
159
|
+
button_html: button_maker.generate(user.email, user.source)
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
puts output.inspect
|
164
|
+
```
|
165
|
+
|
166
|
+
### ActionMailer Example
|
167
|
+
|
168
|
+
Assume you have a model that represents an offer you'd like to send to a user:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
class OfferMailer < ActionMailer::Base
|
172
|
+
default from: 'offers@example.com'
|
173
|
+
|
174
|
+
def offer_email(offer)
|
175
|
+
@button = generator.generate({
|
176
|
+
email: offer.recipient.email,
|
177
|
+
source: offer.recipient.card_token
|
178
|
+
})
|
179
|
+
|
180
|
+
mail({
|
181
|
+
to: offer.recipient.email,
|
182
|
+
subject: offer.name
|
183
|
+
})
|
184
|
+
end
|
185
|
+
|
186
|
+
private
|
187
|
+
def generator
|
188
|
+
AtPay::Button::Generator.new({
|
189
|
+
amount: offer.amount
|
190
|
+
}.update(atpay_config))
|
191
|
+
end
|
192
|
+
|
193
|
+
# NOTE: Just throw this in an initializer if you can
|
194
|
+
def atpay_config
|
195
|
+
{
|
196
|
+
public_key: ATPAY_PUBLIC,
|
197
|
+
private_key: ATPAY_PRIVATE,
|
198
|
+
partner_id: ATPAY_PARTNER,
|
199
|
+
environment: (Rails.env != "production") ? :sandbox : :production
|
200
|
+
}
|
201
|
+
end
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
## Templates
|
206
|
+
|
207
|
+
|
208
|
+
The generator uses a set of four default templates located in "lib/atpay/button/templates/". The yahoo.liquid template will be used for yahoo emails. The default.liquid template is for all other email providers. There are also versions prefixed with "wrap_" that will be used if the wrap parameter is set to "true". These "wrapped" templates are simply versions with a styled div that hold the buttons.
|
209
|
+
|
210
|
+
To use your own custom templates, you can download the provided default versions. After making the desired modifications, set the template parameter to the location of your modified templates.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
require "rake/clean"
|
5
|
+
require "rbnacl/rake_tasks"
|
6
|
+
|
7
|
+
file "lib/libsodium.so" => :build_libsodium do
|
8
|
+
cp $LIBSODIUM_PATH, "lib/libsodium.so"
|
9
|
+
end
|
10
|
+
|
11
|
+
task "ci:sodium" => "lib/libsodium.so"
|
12
|
+
|
13
|
+
task :ci => %w(ci:sodium spec)
|
14
|
+
|
15
|
+
CLEAN.add "lib/libsodium.*"
|
16
|
+
|
17
|
+
Rake::TestTask.new do |t|
|
18
|
+
t.libs << "spec"
|
19
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
20
|
+
t.verbose = true
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "atpay_buttons"
|
7
|
+
spec.version = '1.0.0'
|
8
|
+
spec.date = '2013-08-02'
|
9
|
+
spec.authors = ["Thomas Pastinsky", "Glen Holcomb", "James Kassemi", "Isaiah Baca"]
|
10
|
+
spec.email = ["dev@atpay.com"]
|
11
|
+
spec.description = 'Atpay button generator'
|
12
|
+
spec.summary = 'Command line tool and Ruby library for generating @Pay 2 click email buttons'
|
13
|
+
spec.homepage = "http://atpay.com"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_runtime_dependency "atpay_tokens"
|
22
|
+
spec.add_runtime_dependency "liquid"
|
23
|
+
end
|
data/bin/atpay_buttons
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'trollop'
|
4
|
+
require_relative '../lib/atpay_buttons.rb'
|
5
|
+
|
6
|
+
|
7
|
+
@opts = Trollop::options do
|
8
|
+
version "atpay-button-generator v0.1"
|
9
|
+
banner <<-USAGE
|
10
|
+
To generate an Atpay Button, follow these steps:
|
11
|
+
Create a text file, e.g. data.txt, containing an email address and the associated credit card token separated by a comma. Enter multiple lines for multiple buttons:
|
12
|
+
|
13
|
+
test1@example.com,TL1UwJFXVN7e4p6+0B5N8hy4qQyqeNxVllmC663MLcMupuAWXdHJ9g8PRAnlIh+AMZBgpaIrfWStZ5/3hYi6vCAV7q6+3M6LLqxk
|
14
|
+
test2@example.com,XKCF2E9QZPwdOSwfTQJzZC7byLt3PH8Tr1KhmLkfRHwfNJD5XbDRMrxGYOiSnfrLEKNzm9+a4r++bpUG2hNrPyYLpNgph3BXAAfC
|
15
|
+
test3@example.com,iQOxdBV4KrFuPFgyywxytfbsD/rURrzmlADmg1QFP2VHd/kTnkXNpnp2Utv4RS0Zz2YeOloilMhljsOcRVA2YwSu9knwF1h6tNjE
|
16
|
+
|
17
|
+
Then run the following from the console in the same location as the file you created:
|
18
|
+
|
19
|
+
$ atpay-button-generator --title "Pay" --amount 50.00 --subject "Payment for fifty bucks" --private-key "plBs9X+Zvr65z6iCa0oLNdAEGYZ85Dzf74Qy1yPTris=" --public-key "06zK82iu9NUUMmDiZsEvoUH25tbIE6R3R+zPnDK8YGQ=" --partner-id 20 --input data.txt
|
20
|
+
USAGE
|
21
|
+
|
22
|
+
opt :amount, "The amount a user should be charged for transactions after clicking the generated button", :default => 5.0, :required => true
|
23
|
+
opt :private_key, "The private key given to you by @Pay", :type => :string, :required => true
|
24
|
+
opt :public_key, "@Pay's public key, given to you by @Pay", :type => :string, :required => true
|
25
|
+
opt :partner_id, "The partner ID given to you by @Pay", :type => :integer, :required => true
|
26
|
+
opt :subject, "The subject of the mailto: email (the message that a user will be sending to @Pay's servers after clicking the button", :type => :string
|
27
|
+
opt :image_url, "The URL to a small thumbnail image to be used in the button. Default: https://www.atpay.com/wp-content/themes/atpay/images/bttn_cart.png", :type => :string, :default => "https://www.atpay.com/wp-content/themes/atpay/images/bttn_cart.png"
|
28
|
+
opt :color, "The background color of the button. Default: #6dbe45", :type => :string, :default => "#6dbe45"
|
29
|
+
opt :title, "The title for each button", :type => :string
|
30
|
+
opt :wrap, "Will use wrapped (with a styled div container) version of the template. Default: false", :type => :boolean, :default => false
|
31
|
+
opt :env, "The environment you want to generate buttons for. Currently sandbox or production", :default => 'production'
|
32
|
+
opt :templates, "Location of button templates.", :type => :string, :default => File.dirname(__FILE__) + '/../lib/atpay/button/templates'
|
33
|
+
opt :user_data, "Optional user data to be passed in for your use", :type => :string
|
34
|
+
opt :type, "Optional the default is payment", :type => :string
|
35
|
+
opt :input, "Input File", :default => $stdin
|
36
|
+
end
|
37
|
+
|
38
|
+
Trollop::die :amount, "must not be negative" if @opts[:amount] < 0
|
39
|
+
Trollop::die :input, "must exist" unless File.exist?(@opts[:input]) if @opts[:input]
|
40
|
+
|
41
|
+
def symbolize_values
|
42
|
+
@opts[:env] = @opts[:env].to_sym
|
43
|
+
@opts[:type] = @opts[:type].to_sym if @opts[:type]
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse
|
47
|
+
@targets = []
|
48
|
+
|
49
|
+
symbolize_values
|
50
|
+
@generator = AtPay::Button::Generator.new @opts.dup
|
51
|
+
|
52
|
+
while !@opts[:input].eof?
|
53
|
+
data = @opts[:input].readline.strip.split(',')
|
54
|
+
|
55
|
+
@generator.build([[data[0], data[1]]]).each do |pair|
|
56
|
+
pair[1] = pair[1].gsub(/\s+/, " ")
|
57
|
+
puts pair.join(",")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
parse
|
data/circle.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
dependencies:
|
2
|
+
pre:
|
3
|
+
- curl -O http://download.dnscrypt.org/libsodium/releases/libsodium-0.4.1.tar.gz
|
4
|
+
- tar -xvzf libsodium-0.4.1.tar.gz
|
5
|
+
- cd libsodium-0.4.1 && ./configure && make
|
6
|
+
- cp libsodium-0.4.1/src/libsodium/.libs/libsodium.so ./lib/
|
7
|
+
|
8
|
+
test:
|
9
|
+
override:
|
10
|
+
- bundle exec rake test
|
11
|
+
|
12
|
+
machine:
|
13
|
+
environment:
|
14
|
+
LD_LIBRARY_PATH: lib
|
15
|
+
|
16
|
+
ruby:
|
17
|
+
version: 2.0.0-p195
|
Binary file
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module AtPay
|
2
|
+
module Button
|
3
|
+
class LengthError < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class Generator
|
7
|
+
# TODO: This should really move to the underlying token library.
|
8
|
+
TOKEN_TYPES = {
|
9
|
+
payment: nil,
|
10
|
+
validation: 1
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@options = {
|
15
|
+
:title => "Pay",
|
16
|
+
:type => :payment,
|
17
|
+
:group => nil,
|
18
|
+
:user_data => nil,
|
19
|
+
:template => {}
|
20
|
+
}.update options
|
21
|
+
|
22
|
+
@options[:version] = TOKEN_TYPES[@options[:type]] if TOKEN_TYPES[@options[:type]]
|
23
|
+
|
24
|
+
validate_user_data
|
25
|
+
@options[:amount] = amount
|
26
|
+
end
|
27
|
+
|
28
|
+
def amount
|
29
|
+
@amount ||= @options[:amount].respond_to?(:gsub) ? @options[:amount].gsub(/[^0-9\.]/, "").to_f : @options[:amount]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Custom data that is to be added to the token can't exceed 2,500 characters.
|
33
|
+
def validate_user_data
|
34
|
+
return unless @options[:user_data]
|
35
|
+
|
36
|
+
raise LengthError.new "user_data can't be longer than 2,500 characters, you provided #{@options[:user_data].length} characters" if @options[:user_data].length > 2500
|
37
|
+
end
|
38
|
+
|
39
|
+
# Builds an @Pay Payment token for injection into a mailto button.
|
40
|
+
#
|
41
|
+
# @param type [Symbol] The button type: :email, :card, :member
|
42
|
+
# @param source [String] The coresponding type value
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
def token(type, source)
|
46
|
+
session.security_key(@options.merge({type => source})).email_token
|
47
|
+
end
|
48
|
+
|
49
|
+
# Instanciate a button template instance for a specific email address. The email is necessary
|
50
|
+
# for selecting the correct template files. There are some special cases depending on the
|
51
|
+
# environment that the button is being viewed in.
|
52
|
+
#
|
53
|
+
# @param email [String] the email address the button is intended for.
|
54
|
+
#
|
55
|
+
# @return [AtPay::Button::Template]
|
56
|
+
def template(email)
|
57
|
+
Template.new(@options.update(:email => email, :amount => amount))
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_html(token, email)
|
61
|
+
@options.update({:token => token})
|
62
|
+
template(email).render(token: token, :email => email)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Generate the actual button HTML. There are three options available :source (the card token),
|
66
|
+
# :email (the email address the button is intended for), :type (the type of the source identifier)
|
67
|
+
# :type defaults to card.
|
68
|
+
#
|
69
|
+
# @param options [Hash] there are three options that matter: :source, :email and :type
|
70
|
+
#
|
71
|
+
# @return [String]
|
72
|
+
def generate(options)
|
73
|
+
options[:source] ? source = options[:source] : source = options[:email]
|
74
|
+
options[:type] ? type = options[:type] : type = :card
|
75
|
+
email = options[:email]
|
76
|
+
|
77
|
+
to_html token(type, source), email
|
78
|
+
end
|
79
|
+
|
80
|
+
# Build buttons for the provided collection. build will accept an array of email addresses ['bob@bob', 'sue@sue'],
|
81
|
+
# or any "paired" collection: For example [['bob@bob', 'card_token'], ['sue@sue', 'card_token']] will work,
|
82
|
+
# as will 'bob@bob' => 'card_token', 'sue@sue' => 'card_token'. If providing only a list of email
|
83
|
+
# addresses build will create email tokens. Only use this behavior if you are sure it is what both you
|
84
|
+
# and your customer want. An email token isn't ultra-specific about the card it charges. It will charge
|
85
|
+
# the first card for that individual it finds that your @Pay account has permission to use.
|
86
|
+
#
|
87
|
+
# @param token_map [Enumerable]
|
88
|
+
#
|
89
|
+
# @return [Array] a list of tuples containing the email address and button code as [String]s
|
90
|
+
def build(token_map)
|
91
|
+
token_map.collect do |email, card|
|
92
|
+
card ? [email, generate(email: email, source: card)] : [email, generate(email: email, type: :email)]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def session
|
100
|
+
@session ||= AtPay::Session.new({
|
101
|
+
public_key: @options[:public_key],
|
102
|
+
private_key: @options[:private_key],
|
103
|
+
partner_id: @options[:partner_id],
|
104
|
+
environment: @options[:env]
|
105
|
+
})
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|