Class: ZuoraInterface

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

Instance Method Summary collapse

Instance Method Details

#create(objs) ⇒ Object



103
104
105
# File 'lib/zuora_interface.rb', line 103

def create(objs)
  return @z.create(objs)
end

#create_active_account(name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
94
# File 'lib/zuora_interface.rb', line 49

def (name)

  val = false
  session_start
   = (name)
  result = create([])
#    puts result.first.inspect

  if result.first.success

    accountId = result.first.id
    payment = make_payment_method(accountId)
    result = create([payment])

    if result.first.success

      paymentId = result.first.id
      con = make_contact(accountId)
      result = create([con])

      if result.first.success
        conId = result.first.id

        .id = accountId
        .status = 'Active'
        .billToId = conId
        .soldToId = conId
        result = update([])

        if result.first.success
          val = 
        else
          add_errors(result)
        end

      else
        add_errors(result)
      end
    else
      add_errors(result)
    end
  else
    add_errors(result)
  end
  return val
end

#delete(type, ids) ⇒ Object



115
116
117
118
119
120
# File 'lib/zuora_interface.rb', line 115

def delete(type, ids)
  d = ZUORA::Delete.new
  d.type = type
  d.ids = ids
  return @z.delete(d)
end

#driverObject



148
149
150
# File 'lib/zuora_interface.rb', line 148

def driver
  get_driver
end

#generate(objs) ⇒ Object



107
108
109
# File 'lib/zuora_interface.rb', line 107

def generate(objs)
  return @z.generate(objs)
end

#get_driverObject



144
145
146
# File 'lib/zuora_interface.rb', line 144

def get_driver
  @z ||= Zuora::Billing::Api.instance.driver
end

#get_object(query) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/zuora_interface.rb', line 126

def get_object(query)
  object = lookup(query)
  unless object.result.size == 0
    return object.result.records.first
  else
    return nil
  end
end

#get_object_array(query) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/zuora_interface.rb', line 135

def get_object_array(query)
  object = lookup(query)
  unless object.result.size == 0
    return object.result.records
  else
    return []
  end
end

#loginObject



152
153
154
155
156
157
158
# File 'lib/zuora_interface.rb', line 152

def 
  loginargs = ZUORA::Login.new
  loginargs.username = $ZUORA_USER
  loginargs.password = $ZUORA_PASSWORD
  @session = ZUORA::SessionHeader.new
  @session.session = @z.(loginargs).result.session
end

#make_account(accountName) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/zuora_interface.rb', line 5

def (accountName)
  acc = ZUORA::Account.new
  acc.allowInvoiceEdit = 0
  acc.name = accountName
  acc.currency = "USD"
  acc.autoPay = 0
  acc.status = "Draft"
  acc.paymentTerm = "Due Upon Receipt"
  acc.batch = "Batch1"
  acc.billCycleDay = "01"
  return acc
end

#make_contact(accountId) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zuora_interface.rb', line 18

def make_contact(accountId)
  con = ZUORA::Contact.new
  con.accountId = accountId
  con.address1 = '4901 Morena Blvd';
  con.city = 'San Diego';
  con.country = 'United States';
  con.firstName = 'Robert';
  con.lastName = 'Smith';
  con.postalCode = '92117';
  con.state = 'Virginia';
  con.workEmail = '[email protected]';
  return con
end

#make_payment_method(accountId) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zuora_interface.rb', line 32

def make_payment_method(accountId)
  pmt = ZUORA::PaymentMethod.new
  pmt.accountId = accountId
  pmt.creditCardAddress1 = '52 Vexford Lane';
  pmt.creditCardCity = 'Anaheim';
  pmt.creditCardCountry = 'United States';
  pmt.creditCardExpirationMonth = '12';
  pmt.creditCardExpirationYear = '2010';
  pmt.creditCardHolderName = 'Firstly Lastly';
  pmt.creditCardNumber = '4111111111111111';
  pmt.creditCardPostalCode = '22042';
  pmt.creditCardState = 'California';
  pmt.creditCardType = 'Visa';
  pmt.type = 'CreditCard';
  return pmt
end

#query(query) ⇒ Object



96
97
98
99
100
101
# File 'lib/zuora_interface.rb', line 96

def query(query)
  q = ZUORA::Query.new
  q.queryString = query
  results = @z.query(q)
  return results
end

#session_cleanupObject



169
170
171
# File 'lib/zuora_interface.rb', line 169

def session_cleanup
  @z.headerhandler.delete(@session) if @session
end

#session_start(custom_fields) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/zuora_interface.rb', line 160

def session_start(custom_fields)
  get_driver
  @z.do_init(custom_fields)
  session_cleanup
  
  @z.headerhandler.set @session
  @z.wiredump_dev = STDERR if $ZUORA_VERBOSE
end

#subscribe(sub) ⇒ Object



122
123
124
# File 'lib/zuora_interface.rb', line 122

def subscribe(sub)
  return @z.subscribe(sub)
end

#update(objs) ⇒ Object



111
112
113
# File 'lib/zuora_interface.rb', line 111

def update(objs)
  return @z.update(objs)
end