Class: Dwolla::OffsiteGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/dwolla/offsite_gateway.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.additional_funding_sources=(value) ⇒ Object (writeonly)

Sets the attribute additional_funding_sources

Parameters:

  • value

    the value to set the attribute additional_funding_sources to.



36
37
38
# File 'lib/dwolla/offsite_gateway.rb', line 36

def additional_funding_sources=(value)
  @additional_funding_sources = value
end

.allow_funding_sources=(value) ⇒ Object (writeonly)

Sets the attribute allow_funding_sources

Parameters:

  • value

    the value to set the attribute allow_funding_sources to.



35
36
37
# File 'lib/dwolla/offsite_gateway.rb', line 35

def allow_funding_sources=(value)
  @allow_funding_sources = value
end

.callback=(value) ⇒ Object (writeonly)

Sets the attribute callback

Parameters:

  • value

    the value to set the attribute callback to.



33
34
35
# File 'lib/dwolla/offsite_gateway.rb', line 33

def callback=(value)
  @callback = value
end

.facilitator_amount=(value) ⇒ Object (writeonly)

Sets the attribute facilitator_amount

Parameters:

  • value

    the value to set the attribute facilitator_amount to.



37
38
39
# File 'lib/dwolla/offsite_gateway.rb', line 37

def facilitator_amount=(value)
  @facilitator_amount = value
end

.notes=(value) ⇒ Object (writeonly)

Sets the attribute notes

Parameters:

  • value

    the value to set the attribute notes to.



30
31
32
# File 'lib/dwolla/offsite_gateway.rb', line 30

def notes=(value)
  @notes = value
end

.order_id=(value) ⇒ Object (writeonly)

Sets the attribute order_id

Parameters:

  • value

    the value to set the attribute order_id to.



31
32
33
# File 'lib/dwolla/offsite_gateway.rb', line 31

def order_id=(value)
  @order_id = value
end

.redirect=(value) ⇒ Object (writeonly)

Sets the attribute redirect

Parameters:

  • value

    the value to set the attribute redirect to.



32
33
34
# File 'lib/dwolla/offsite_gateway.rb', line 32

def redirect=(value)
  @redirect = value
end

.shipping=(value) ⇒ Object (writeonly)

Sets the attribute shipping

Parameters:

  • value

    the value to set the attribute shipping to.



29
30
31
# File 'lib/dwolla/offsite_gateway.rb', line 29

def shipping=(value)
  @shipping = value
end

.tax=(value) ⇒ Object (writeonly)

Sets the attribute tax

Parameters:

  • value

    the value to set the attribute tax to.



28
29
30
# File 'lib/dwolla/offsite_gateway.rb', line 28

def tax=(value)
  @tax = value
end

.test_mode=(value) ⇒ Object (writeonly)

Sets the attribute test_mode

Parameters:

  • value

    the value to set the attribute test_mode to.



34
35
36
# File 'lib/dwolla/offsite_gateway.rb', line 34

def test_mode=(value)
  @test_mode = value
end

Class Method Details

.add_product(name = nil, description = nil, price = nil, quantity = 1) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/dwolla/offsite_gateway.rb', line 40

def self.add_product(name=nil, description=nil, price=nil, quantity=1)
    @products.push({
        :name => name,
        :description => description,
        :price => price,
        :quantity => quantity
    })
end

.clear_sessionObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dwolla/offsite_gateway.rb', line 14

def self.clear_session
    @products = []
    @discount = 0
    @tax = 0
    @shipping = 0
    @notes = nil
    @facilitator_amount = nil
    @test_mode = false
    @allow_funding_sources = true
    @additional_funding_sources = true
    @order_id = nil
end

.discount=(discount) ⇒ Object



60
61
62
# File 'lib/dwolla/offsite_gateway.rb', line 60

def self.discount=(discount)
    @discount = -(discount.abs)
end

.get_checkout_url(destinationId) ⇒ Object

Raises:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dwolla/offsite_gateway.rb', line 64

def self.get_checkout_url(destinationId)
    params = {
        :key => Dwolla::api_key,
        :secret => Dwolla::api_secret,
        :allowFundingSources => @allow_funding_sources,
        :additionalFundingSources => @additional_funding_sources,
        :test => @test_mode,
        :callback => @callback,
        :redirect => @redirect,
        :orderId => @order_id,
        :notes => @notes,
        :purchaseOrder => {
            :customerInfo => @customerInfo,
            :destinationId => destinationId,
            :orderItems => @products,
            :facilitatorAmount => @facilitator_amount,
            :discount => @discount,
            :shipping => @shipping,
            :tax => @tax,
            :total => self.calculate_total
        }
    }

    resp = Dwolla.request(:post, request_url, params, {}, false, false, true)

    return "No data received." unless resp.is_a?(Hash)
    raise APIError.new(resp['Message']) unless resp.has_key?('Result') and resp['Result'] == 'Success'

    return checkout_url + resp['CheckoutId']
end

.read_callback(body) ⇒ Object



95
96
97
98
99
100
# File 'lib/dwolla/offsite_gateway.rb', line 95

def self.read_callback(body)
    data = JSON.load(body)
    verify_callback_signature(data['signature'], data['checkoutId'], data['amount'])

    return data
end

.set_customer_info(first_name = nil, last_name = nil, email = nil, city = nil, state = nil, zip = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/dwolla/offsite_gateway.rb', line 49

def self.set_customer_info(first_name=nil, last_name=nil, email=nil, city=nil, state=nil, zip=nil)
    @customerInfo = {
        :firstName => first_name,
        :lastName => last_name,
        :email => email,
        :city => city,
        :state => state,
        :zip => zip
    }
end

.validate_webhook(signature, body) ⇒ Object



102
103
104
# File 'lib/dwolla/offsite_gateway.rb', line 102

def self.validate_webhook(signature, body)
    verify_webhook_signature(signature, body)
end