atpay_ruby 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,175 @@
1
+ <!-- yahoo template with wrap -->
2
+
3
+ <style>
4
+ a.not_yahoo {display:inline; display: inline !important;font-size: 20px !important;}
5
+ a.not_yahoosm {display:inline; display: inline !important;font-size: 12px !important;}
6
+
7
+ a.not_yahoo[fix] {display:inline; display: inline !important;font-size: 20px !important;}
8
+ a.not_yahoosm[fix] {display:inline; display: inline !important;font-size: 12px !important;}
9
+ a.yahoo[fix] {display:none; display: none !important;font-size: 0px !important;}
10
+ </style>
11
+
12
+ {% if analytic_url %}
13
+ <img src="{{analytic_url}}" width="1" height="1" />
14
+ {% endif %}
15
+
16
+
17
+ <center>
18
+ <table cellpadding='0' cellspacing='0' style='margin-bottom:20px;'>
19
+ <tr>
20
+ <td>
21
+ <table style='margin: auto; margin-bottom:5px; font-family: Lato; padding-bottom:10px; position:relative; padding-left:5px; padding-right:10px; margin-bottom:0px; margin-top:5px; padding:10px;padding-top:0; border-left: 1px solid #e4e2e2; border-top: 1px solid #e4e2e2; border-right: 1px solid #e4e2e2; '>
22
+ <tr>
23
+ <td colspan='3'>
24
+ <p style='margin-bottom:0px; color: #515050; font-size:12px; margin-top:2px; text-align:center;'>
25
+ {{wrap_text}}
26
+ </p>
27
+ </td>
28
+ </tr>
29
+ <tr>
30
+ <td>
31
+
32
+ <center>
33
+ <a border='0' class='yahoo' fix='email' href='{{yahoo_url}}' style='text-underline:none;'>
34
+ <table border='0' cellpadding='0' cellspacing='0' style='background-color:{{background_color}};'>
35
+ <tr class='main'>
36
+ <td class='main' style='padding:3px 5px 5px 5px;' width='145'>
37
+ <table>
38
+ <tr>
39
+ {% if image %}
40
+ <td>
41
+ <a class='yahoo' fix='email' href='{{yahoo_url}}' style='color:{{foreground_color}}; text-decoration:none; border:none; display:inline;'>
42
+ <img src='{{image}}' style='margin-left: 5px; margin-right:10px; margin-top:8px;'>
43
+ </a>
44
+ </td>
45
+ {% endif %}
46
+ <td>
47
+ <table border='0' cellpadding='0' cellspacing='0' style='float:left; margin:0; margin-left:5px;'>
48
+ <tr>
49
+ <td style='font-size: 11px; color: {{foreground_color}}; font-family: Tahoma; text-align:center; padding:0; margin:0;'>
50
+ {{title}}
51
+ </td>
52
+ </tr>
53
+ <tr>
54
+ <td>
55
+ <table border='0' cellpadding='0' cellspacing='0' style='margin:0; padding:0;'>
56
+ <tr>
57
+ <td style='padding:0; margin:0; font-size: 20px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top; line-height:25px;' valign='top'>
58
+ <a class='yahoo' fix='email' href='{{yahoo_url}}' style='color:{{foreground_color}}; text-decoration:none; border:none; display:inline;'>
59
+ {{dollar}}
60
+ </a>
61
+ </td>
62
+ <td style='padding:0; margin:0; font-size:14px; text-decoration:underline;padding-left:2px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top;' valign='top'>
63
+ <a class='yahoosm' fix='email' href='{{yahoo_url}}' style='color:{{foreground_color}}; text-decoration:none; border:none; display:inline;'>
64
+ {{cents}}
65
+ </a>
66
+ </td>
67
+ </tr>
68
+ </table>
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </td>
73
+ </tr>
74
+ </table>
75
+ </td>
76
+ </tr>
77
+ </table>
78
+ </a>
79
+ <a border='0' class='not_yahoo' fix='email' href='{{url}}' style='text-underline:none; display:none; font-size:0px; text-indent:-9999999;'>
80
+ <table border='0' cellpadding='0' cellspacing='0' style='background-color:{{background_color}};'>
81
+ <tr class='main'>
82
+ <td class='main' style='padding:3px 5px 5px 5px;' width='145'>
83
+ <table>
84
+ <tr>
85
+ {% if image %}
86
+ <td>
87
+ <a class='not_yahoo' href='{{url}}' style='color:{{foreground_color}}; text-decoration:none; border:none;'>
88
+ <img src='{{image}}' style='margin-left: 5px; margin-right:10px; margin-top:8px;'>
89
+ </a>
90
+ </td>
91
+ {% endif %}
92
+ <td>
93
+ <table border='0' cellpadding='0' cellspacing='0' style='float:left; margin:0; margin-left:5px;'>
94
+ <tr>
95
+ <td style='font-size: 11px; color: {{foreground_color}}; font-family: Tahoma; text-align:center; padding:0; margin:0;'>
96
+ {{title}}
97
+ </td>
98
+ </tr>
99
+ <tr>
100
+ <td>
101
+ <table border='0' cellpadding='0' cellspacing='0' style='margin:0; padding:0;'>
102
+ <tr>
103
+ <td style='padding:0; margin:0; font-size: 20px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top; line-height:25px;' valign='top'>
104
+ <a class='not_yahoo' fix='email' href='{{url}}' style='color:{{foreground_color}}; text-decoration:none; border:none;'>
105
+ {{dollar}}
106
+ </a>
107
+ </td>
108
+ <td style='padding:0; margin:0; font-size:14px; text-decoration:underline;padding-left:2px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top;' valign='top'>
109
+ <a class='not_yahoosm' fix='email' href='{{url}}' style='color:{{foreground_color}}; text-decoration:none; border:none;'>
110
+ {{cents}}
111
+ </a>
112
+ </td>
113
+ </tr>
114
+ </table>
115
+ </td>
116
+ </tr>
117
+ </table>
118
+ </td>
119
+ </tr>
120
+ </table>
121
+ </td>
122
+ </tr>
123
+ </table>
124
+ </a>
125
+ </center>
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+ </td>
139
+ </tr>
140
+ </table>
141
+ </td>
142
+ </tr>
143
+ <tr>
144
+ <td>
145
+ <table cellpadding='0' cellspacing='0' style='width:100%;' width='100%'>
146
+ <tr>
147
+ <td valign='top'>
148
+ <table cellpadding='0' cellspacing='0' height='10' style='font-size: 1px; line-height: 1px; border-left: 1px #e4e2e2 solid; border-bottom: 1px #e4e2e2 solid; height:10px; width: 100%;'>
149
+ <tr>
150
+ <td>
151
+ &nbsp;
152
+ </td>
153
+ </tr>
154
+ </table>
155
+ </td>
156
+ <td width='155'>
157
+ <center>
158
+ <img src='https://atpay.com/wp-content/uploads/2013/05/email_chout_tag.png'>
159
+ </center>
160
+ </td>
161
+ <td valign='top' width='20'>
162
+ <table cellpadding='0' cellspacing='0' height='10' style='font-size: 1px; line-height: 1px; border-right: 1px #e4e2e2 solid; border-bottom: 1px #e4e2e2 solid; height:10px; width: 100%;'>
163
+ <tr>
164
+ <td>
165
+ &nbsp;
166
+ </td>
167
+ </tr>
168
+ </table>
169
+ </td>
170
+ </tr>
171
+ </table>
172
+ </td>
173
+ </tr>
174
+ </table>
175
+ </center>
@@ -0,0 +1,111 @@
1
+ <!-- yahoo template with no wrap -->
2
+
3
+ <style>
4
+ a.not_yahoo {display:inline; display: inline !important;font-size: 20px !important;}
5
+ a.not_yahoosm {display:inline; display: inline !important;font-size: 12px !important;}
6
+
7
+ a.not_yahoo[fix] {display:inline; display: inline !important;font-size: 20px !important;}
8
+ a.not_yahoosm[fix] {display:inline; display: inline !important;font-size: 12px !important;}
9
+ a.yahoo[fix] {display:none; display: none !important;font-size: 0px !important;}
10
+ </style>
11
+
12
+ {% if analytic_url %}
13
+ <img src="{{analytic_url}}" width="1" height="1" />
14
+ {% endif %}
15
+
16
+
17
+ <center>
18
+ <a border='0' class='yahoo' fix='email' href='{{yahoo_url}}' style='text-underline:none;'>
19
+ <table border='0' cellpadding='0' cellspacing='0' style='background-color:{{background_color}};'>
20
+ <tr class='main'>
21
+ <td class='main' style='padding:3px 5px 5px 5px;' width='145'>
22
+ <table>
23
+ <tr>
24
+ {% if image %}
25
+ <td>
26
+ <a class='yahoo' fix='email' href='{{yahoo_url}}' style='color:{{foreground_color}}; text-decoration:none; border:none; display:inline;'>
27
+ <img src='{{image}}' style='margin-left: 5px; margin-right:10px; margin-top:8px;'>
28
+ </a>
29
+ </td>
30
+ {% endif %}
31
+ <td>
32
+ <table border='0' cellpadding='0' cellspacing='0' style='float:left; margin:0; margin-left:5px;'>
33
+ <tr>
34
+ <td style='font-size: 11px; color: {{foreground_color}}; font-family: Tahoma; text-align:center; padding:0; margin:0;'>
35
+ {{title}}
36
+ </td>
37
+ </tr>
38
+ <tr>
39
+ <td>
40
+ <table border='0' cellpadding='0' cellspacing='0' style='margin:0; padding:0;'>
41
+ <tr>
42
+ <td style='padding:0; margin:0; font-size: 20px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top; line-height:25px;' valign='top'>
43
+ <a class='yahoo' fix='email' href='{{yahoo_url}}' style='color:{{foreground_color}}; text-decoration:none; border:none; display:inline;'>
44
+ {{dollar}}
45
+ </a>
46
+ </td>
47
+ <td style='padding:0; margin:0; font-size:14px; text-decoration:underline;padding-left:2px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top;' valign='top'>
48
+ <a class='yahoosm' fix='email' href='{{yahoo_url}}' style='color:{{foreground_color}}; text-decoration:none; border:none; display:inline;'>
49
+ {{cents}}
50
+ </a>
51
+ </td>
52
+ </tr>
53
+ </table>
54
+ </td>
55
+ </tr>
56
+ </table>
57
+ </td>
58
+ </tr>
59
+ </table>
60
+ </td>
61
+ </tr>
62
+ </table>
63
+ </a>
64
+ <a border='0' class='not_yahoo' fix='email' href='{{url}}' style='text-underline:none; display:none; font-size:0px; text-indent:-9999999;'>
65
+ <table border='0' cellpadding='0' cellspacing='0' style='background-color:{{background_color}};'>
66
+ <tr class='main'>
67
+ <td class='main' style='padding:3px 5px 5px 5px;' width='145'>
68
+ <table>
69
+ <tr>
70
+ {% if image %}
71
+ <td>
72
+ <a class='not_yahoo' href='{{url}}' style='color:{{foreground_color}}; text-decoration:none; border:none;'>
73
+ <img src='{{image}}' style='margin-left: 5px; margin-right:10px; margin-top:8px;'>
74
+ </a>
75
+ </td>
76
+ {% endif %}
77
+ <td>
78
+ <table border='0' cellpadding='0' cellspacing='0' style='float:left; margin:0; margin-left:5px;'>
79
+ <tr>
80
+ <td style='font-size: 11px; color: {{foreground_color}}; font-family: Tahoma; text-align:center; padding:0; margin:0;'>
81
+ {{title}}
82
+ </td>
83
+ </tr>
84
+ <tr>
85
+ <td>
86
+ <table border='0' cellpadding='0' cellspacing='0' style='margin:0; padding:0;'>
87
+ <tr>
88
+ <td style='padding:0; margin:0; font-size: 20px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top; line-height:25px;' valign='top'>
89
+ <a class='not_yahoo' fix='email' href='{{url}}' style='color:{{foreground_color}}; text-decoration:none; border:none;'>
90
+ {{dollar}}
91
+ </a>
92
+ </td>
93
+ <td style='padding:0; margin:0; font-size:14px; text-decoration:underline;padding-left:2px; color: {{foreground_color}}; font-family: Tahoma; vertical-align:top;' valign='top'>
94
+ <a class='not_yahoosm' fix='email' href='{{url}}' style='color:{{foreground_color}}; text-decoration:none; border:none;'>
95
+ {{cents}}
96
+ </a>
97
+ </td>
98
+ </tr>
99
+ </table>
100
+ </td>
101
+ </tr>
102
+ </table>
103
+ </td>
104
+ </tr>
105
+ </table>
106
+ </td>
107
+ </tr>
108
+ </table>
109
+ </a>
110
+ </center>
111
+
Binary file
@@ -0,0 +1,27 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'atpay_ruby'
5
+ s.version = '0.0.5'
6
+ s.summary = 'Ruby bindings for the @Pay API'
7
+ s.description = ""
8
+ s.authors = ['James Kassemi']
9
+ s.email = ['james@atpay.com']
10
+ s.homepage = 'https://atpay.com'
11
+ s.license = 'MIT'
12
+
13
+ s.add_runtime_dependency('rbnacl-libsodium', '~> 0.6.0')
14
+ s.add_runtime_dependency('trollop', '~> 2.0')
15
+ s.add_runtime_dependency('liquid', '~> 2.6.1')
16
+ s.add_runtime_dependency('thor', '~> 0.18.1')
17
+ s.add_runtime_dependency('httpi')
18
+ s.add_runtime_dependency('multi_json')
19
+
20
+ s.add_development_dependency('rspec', '~> 3.0.0')
21
+ s.add_development_dependency('rspec-mocks', '~> 3.0.2')
22
+
23
+ s.files = `git ls-files`.split($/)
24
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
25
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ s.require_paths = ['lib']
27
+ end
data/bin/atpay ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'atpay'
6
+ require 'thor'
7
+ require 'pry'
8
+
9
+ module AtPay
10
+ module CLI
11
+ class Token < Thor
12
+ class_option :private_key, desc: "Your @Pay private key"
13
+ class_option :public_key, desc: "Your @Pay public key"
14
+ class_option :partner_id, type: :numeric, desc: "Your @Pay partner ID"
15
+
16
+ desc 'invoice', 'Generate an invoice token'
17
+ option :amount, type: :numeric, required: true, desc: "Dollar amount to process"
18
+ option :email, type: :string, required: true, desc: "Email address expected to complete the transaction"
19
+ option :user_data, default: nil, desc: "Additional data to append to transaction details"
20
+ def invoice
21
+ puts AtPay::Token::Invoice.new(session, options[:amount], options[:email], options[:user_data]).to_s
22
+ end
23
+
24
+ desc 'bulk', 'Generate a bulk token'
25
+ option :amount, type: :numeric, required: true, desc: "Dollar amount to process"
26
+ option :user_data, default: '', desc: "Additional data to append to transaction details"
27
+ option :url, type: :string, required: true, desc: "URL for customers with no card on file to complete transaction"
28
+ def bulk
29
+ puts AtPay::Token::Bulk.new(session, options[:amount], options[:url], options[:user_data]).to_s
30
+ end
31
+
32
+ private
33
+ def session
34
+ AtPay::Session.new(options[:partner_id], options[:public_key], options[:private_key])
35
+ end
36
+ end
37
+
38
+ class Button < Thor
39
+ desc 'generic', 'Generates a button for a token'
40
+ option :amount, type: :numeric, required: true, desc: "Display amount"
41
+ option :merchant, type: :string, required: true, desc: "Merchant name"
42
+ def generic
43
+ token = $stdin.read
44
+ puts AtPay::Button.new(token, options[:amount], options[:merchant]).render
45
+ end
46
+ end
47
+
48
+ class Main < Thor
49
+ desc 'token [SUBCOMMAND ...ARGS]', 'Token generation functions'
50
+ subcommand 'token', Token
51
+
52
+ desc 'button [SUBCOMMAND ...ARGS]', 'Button generation functions'
53
+ subcommand 'button', Button
54
+ end
55
+ end
56
+ end
57
+
58
+ AtPay::CLI::Main.start(ARGV)
data/lib/atpay.rb ADDED
@@ -0,0 +1,14 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'atpay/session'
4
+ require 'atpay/error'
5
+ require 'atpay/button'
6
+ require 'atpay/token/invoice'
7
+ require 'atpay/token/bulk'
8
+ require 'atpay/hook'
9
+ require 'atpay/railtie' if defined?(Rails)
10
+ require 'base64'
11
+
12
+ module AtPay
13
+ PUBLIC_KEY = Base64.decode64(ENV["ATPAY_PUB_KEY"] || ENV["ATPAY_PUBLIC_KEY"] || "QZuSjGhUz2DKEvjule1uRuW+N6vCOoMuR2PgCl57vB0=")
14
+ end
@@ -0,0 +1,125 @@
1
+ require 'rubygems'
2
+ require 'liquid'
3
+ require 'cgi'
4
+ require 'uri'
5
+
6
+ module AtPay
7
+ class Button
8
+ OPTIONS = {
9
+ subject: 'Email Order Form',
10
+ title: 'Pay',
11
+ background_color: '#6dbe45',
12
+ foreground_color: '#ffffff',
13
+ image: 'https://www.atpay.com/wp-content/themes/atpay/images/bttn_cart.png',
14
+ processor: ENV['ATPAY_PAYMENT_ADDRESS'] || 'payment@transaction-l4.atpay.com',
15
+ templates: File.join(File.dirname(__FILE__), '..', '..', 'assets', 'button', 'templates'),
16
+ analytic_url: nil,
17
+ wrap: false,
18
+ wrap_text: 'Made for Mobile'
19
+ }
20
+
21
+ def initialize(token, amount, merchant_name, options={})
22
+ @token = token
23
+ @amount = amount
24
+ @merchant_name = merchant_name
25
+ @options = OPTIONS.merge(options)
26
+ @options[:image] = nil if @options[:image] == ''
27
+ end
28
+
29
+ def default_mailto
30
+ "mailto:#{@options[:processor]}?subject=#{mailto_subject}&body=#{mailto_body}"
31
+ end
32
+
33
+ def render(args={})
34
+ @options.update args
35
+
36
+ template.render({
37
+ 'url' => default_mailto,
38
+ 'outlook_url' => outlook_mailto,
39
+ 'yahoo_url' => yahoo_mailto,
40
+ 'content' => amount,
41
+ 'dollar' => amount.match(/\$\d+(?=\.)/).to_s,
42
+ 'cents' => ".#{amount.match(/(?<=\.)[^.]*/).to_s}",
43
+ }.update(string_hash @options))
44
+ end
45
+
46
+ private
47
+ def amount
48
+ "$%.2f" % @amount.to_f
49
+ end
50
+
51
+ def string_hash(hsh)
52
+ hsh.inject({}) do |result, key|
53
+ result[key[0].to_s] = key[1]
54
+ result
55
+ end
56
+ end
57
+
58
+ def provider
59
+ return :default if @options[:email].nil?
60
+
61
+ if ["yahoo.com", "ymail.com", "rocketmail.com"].any? { |c| @options[:email].include? c }
62
+ :yahoo
63
+ else
64
+ :default
65
+ end
66
+ end
67
+
68
+ def token
69
+ @token.chars.each_slice(50).map(&:join).join("\n")
70
+ end
71
+
72
+ def mailto_subject
73
+ URI.encode(@options[:subject])
74
+ end
75
+
76
+ def yahoo_mailto
77
+ "http://compose.mail.yahoo.com/?to=#{@options[:processor]}&subject=#{mailto_subject}&body=#{mailto_body}"
78
+ end
79
+
80
+ def outlook_mailto
81
+ "https://www.hotmail.com/secure/start?action=compose&to=#{@options[:processor]}&subject=#{mailto_subject}&body=#{mailto_body}"
82
+ end
83
+
84
+ # Load the mailto body template from the specified location
85
+ def mailto_body_template
86
+ Liquid::Template.parse(File.read(File.join(@options[:templates], "mailto_body.liquid")))
87
+ end
88
+
89
+ # Parse the mailto body, this is where we inject the token, merchant_name and amount values we received in
90
+ # the options.
91
+ #
92
+ # @return [String]
93
+ def mailto_body
94
+ part_a = URI.encode(mailto_body_template.render({
95
+ 'amount' => amount,
96
+ 'merchant_name' => @merchant_name}))
97
+ part_b = CGI.escape(token)
98
+ part_z = "#{part_a}%0A%0A#{part_b}"
99
+ return part_z
100
+ end
101
+
102
+ # This is processed as liquid - in the future we can allow overwriting the
103
+ # template here and creating custom buttons.
104
+ def template
105
+ Liquid::Template.parse(template_content(template_name))
106
+ end
107
+
108
+ def template_name
109
+ wrap_prefix = @options[:wrap] ? "wrap_" : ""
110
+
111
+ case provider
112
+ when :yahoo
113
+ "#{wrap_prefix}yahoo.liquid"
114
+ when :default
115
+ "#{wrap_prefix}default.liquid"
116
+ end
117
+ end
118
+
119
+ # Determine which template to load based on the domain of the email address.
120
+ # This preserves the mailto behavior across email environments.
121
+ def template_content(template_name)
122
+ File.read(File.join(@options[:templates], template_name))
123
+ end
124
+ end
125
+ end