braintree_lyre 0.0.3 → 0.0.4

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.
@@ -1,7 +1,24 @@
1
+ require 'zlib'
1
2
  module BraintreeLyre
2
3
 
3
4
  module Helpers
4
5
 
6
+ def gzip(content)
7
+ StringIO.new.tap do |io|
8
+ gz = Zlib::GzipWriter.new(io)
9
+
10
+ begin
11
+ gz.write(content)
12
+ ensure
13
+ gz.close
14
+ end
15
+ end.string
16
+ end
17
+
18
+ def gzipped_response(status_code, uncompressed_content)
19
+ [status_code, { "Content-Encoding" => "gzip" }, gzip(uncompressed_content)]
20
+ end
21
+
5
22
  def camelize(str)
6
23
  segments = str.split('_')
7
24
 
@@ -4,6 +4,8 @@ require 'lyre'
4
4
  module BraintreeLyre
5
5
  class Lyre < Lyre::App
6
6
 
7
+ include BraintreeLyre::Helpers
8
+
7
9
  ENVIRONMENT = :development
8
10
  MERCHANT_ID = "0000"
9
11
  PUBLIC_KEY = "pubkey"
@@ -31,9 +33,113 @@ module BraintreeLyre
31
33
 
32
34
  # Braintree::TransparentRedirect.confirm
33
35
  post "/merchants/:merchant_id/transparent_redirect_requests/:id/confirm" do
34
- debugger
35
- "REDIRECT CONFIRM"
36
+ hash = {
37
+ :id=>params[:id],
38
+ :status=>"submitted_for_settlement",
39
+ :type=>"sale",
40
+ :currency_iso_code=>"USD",
41
+ :amount=>"99.00",
42
+ :merchant_account_id=>params[:merchant_id],
43
+ :order_id=>nil,
44
+ :created_at=>'2013-02-19 20:19:41 UTC',
45
+ :updated_at=>'2013-02-19 20:19:41 UTC',
46
+ :customer=>{
47
+ :id=>"9807292",
48
+ :first_name=>nil,
49
+ :last_name=>nil,
50
+ :company=>nil,
51
+ :email=>nil,
52
+ :website=>nil,
53
+ :phone=>nil,
54
+ :fax=>nil
55
+ },
56
+ :billing=>{
57
+ :id=>"r2",
58
+ :first_name=>nil,
59
+ :last_name=>nil,
60
+ :company=>nil,
61
+ :street_address=>nil,
62
+ :extended_address=>nil,
63
+ :locality=>nil,
64
+ :region=>nil,
65
+ :postal_code=>"02446",
66
+ :country_name=>nil,
67
+ :country_code_alpha2=>nil,
68
+ :country_code_alpha3=>nil,
69
+ :country_code_numeric=>nil
70
+ },
71
+ :refund_id=>nil,
72
+ :refund_ids=>[],
73
+ :refunded_transaction_id=>nil,
74
+ :settlement_batch_id=>nil,
75
+ :shipping=>{
76
+ :id=>nil,
77
+ :first_name=>nil,
78
+ :last_name=>nil,
79
+ :company=>nil,
80
+ :street_address=>nil,
81
+ :extended_address=>nil,
82
+ :locality=>nil,
83
+ :region=>nil,
84
+ :postal_code=>nil,
85
+ :country_name=>nil,
86
+ :country_code_alpha2=>nil,
87
+ :country_code_alpha3=>nil,
88
+ :country_code_numeric=>nil
89
+ },
90
+ :custom_fields=>"\n ",
91
+ :avs_error_response_code=>nil,
92
+ :avs_postal_code_response_code=>"M",
93
+ :avs_street_address_response_code=>"I",
94
+ :cvv_response_code=>"I",
95
+ :gateway_rejection_reason=>nil,
96
+ :processor_authorization_code=>"HWR67T",
97
+ :processor_response_code=>"1000",
98
+ :processor_response_text=>"Approved",
99
+ :purchase_order_number=>nil,
100
+ :tax_amount=>nil,
101
+ :tax_exempt=>false,
102
+ :credit_card=>{
103
+ :token=>"7tndh",
104
+ :bin=>"411111",
105
+ :last_4=>"1111",
106
+ :card_type=>"Visa",
107
+ :expiration_month=>"01",
108
+ :expiration_year=>"2018",
109
+ :customer_location=>"US",
110
+ :cardholder_name=>nil,
111
+ :prepaid=>"Unknown",
112
+ :healthcare=>"Unknown",
113
+ :debit=>"Unknown",
114
+ :durbin_regulated=>"Unknown",
115
+ :commercial=>"Unknown",
116
+ :payroll=>"Unknown",
117
+ :issuing_bank=>"Unknown",
118
+ :country_of_issuance=>"Unknown"
119
+ },
120
+ :status_history=>[
121
+ {:timestamp=>'2013-02-19 20:19:41 UTC', :status=>"authorized", :amount=>"99.00", :user=>"sortfolio_sandbox", :transaction_source=>"API"},
122
+ {:timestamp=>'2013-02-19 20:19:41 UTC', :status=>"submitted_for_settlement", :amount=>"99.00", :user=>"sortfolio_sandbox", :transaction_source=>"API"}
123
+ ],
124
+ :plan_id=>nil,
125
+ :subscription_id=>nil,
126
+ :subscription=>{
127
+ :billing_period_end_date=>nil,
128
+ :billing_period_start_date=>nil
129
+ },
130
+ :add_ons=>[],
131
+ :discounts=>[],
132
+ :descriptor=>{
133
+ :name=>nil,
134
+ :phone=>nil
135
+ },
136
+ :recurring=>false,
137
+ :channel=>nil
138
+ }
139
+
140
+ gzipped_response(201, hash.to_xml(:root => 'transaction'))
36
141
  end
37
142
 
38
143
  end
39
- end
144
+ end
145
+
@@ -4,7 +4,7 @@ module BraintreeLyre::TransparentRedirect
4
4
 
5
5
  class CreateTransaction
6
6
 
7
- attr_reader :merchant_id, :redirect_url
7
+ attr_reader :merchant_id, :redirect_url, :kind
8
8
 
9
9
  def initialize(params)
10
10
  _, query = *params['tr_data'].split("|", 2)
@@ -12,19 +12,21 @@ module BraintreeLyre::TransparentRedirect
12
12
 
13
13
  @merchant_id = params['merchant_id']
14
14
  @redirect_url = tr_data['redirect_url']
15
+ @kind = tr_data['kind']
15
16
  end
16
17
 
17
18
  def return_url
18
- id = create_id(merchant_id)
19
- query = base_query(id)
20
- URI.parse(redirect_url).merge("?#{query}&hash=#{hash(query)}")
19
+ query = base_query
20
+ uri = URI.parse(redirect_url).merge("?#{query}&hash=#{hash(query)}")
21
+ uri.to_s
21
22
  end
22
23
 
23
24
  private
24
25
 
25
26
  #MOVE TO HELPER?
26
- def base_query(id)
27
- "http_status=200&id=#{id}"
27
+ def base_query
28
+ id = create_id(merchant_id)
29
+ "http_status=200&id=#{id}&kind=#{kind}"
28
30
  end
29
31
 
30
32
  #MOVE TO HELPER?
@@ -1,3 +1,3 @@
1
1
  module BraintreeLyre
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree_lyre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lyre