Class: CyberSourceMergedSpec::InvoicesController

Inherits:
BaseController show all
Defined in:
lib/cyber_source_merged_spec/controllers/invoices_controller.rb

Overview

InvoicesController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from CyberSourceMergedSpec::BaseController

Instance Method Details

#create_invoice(create_invoice_request) ⇒ ApiResponse

The invoicing product enables you to bill any customer with an email address and accept digital payments securely from any connected device. You can either use the system generated email or use the invoice payment link in your own communication. You can add discounts and taxes for the entire invoice or for each line item. To customize the invoice to match your brand see [Invoice Settings](https://developer.cybersource.com/api-reference-assets/index.htm l#invoicing_invoice-settings_update-invoice-settings). The invoice payment page uses Unified Checkout to process the payments. The availability of API features for a merchant can depend on the portfolio configuration and may need to be enabled at the portfolio level before they can be added to merchant accounts. TODO: type description here

Parameters:

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 24

def create_invoice(create_invoice_request)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/invoicing/v2/invoices',
                                 Server::DEFAULT)
               .body_param(new_parameter(create_invoice_request)
                            .is_required(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesPost202Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Invalid request.',
                             InvoicingV2InvoicesPost400ResponseException)
                .local_error('404',
                             'The specified resource is not found.',
                             InvoicingV2InvoicesPost404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesPost502ResponseException))
    .execute
end

#get_all_invoices(offset, limit, status: nil) ⇒ ApiResponse

Provides a (filtered) list of invoices that have been created in your account. You can filter the list based on Invoice Status by setting the status query parameter to one of DRAFT, CREATED, SENT, PARTIAL, PAID or CANCELED. would like returned. Possible values: - DRAFT - CREATED - SENT - PARTIAL - PAID - CANCELED

Parameters:

  • offset (Integer)

    Required parameter: Page offset number.

  • limit (Integer)

    Required parameter: Maximum number of items you

  • status (String) (defaults to: nil)

    Optional parameter: The status of the invoice.

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



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
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 61

def get_all_invoices(offset,
                     limit,
                     status: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/invoicing/v2/invoices',
                                 Server::DEFAULT)
               .query_param(new_parameter(offset, key: 'offset')
                             .is_required(true))
               .query_param(new_parameter(limit, key: 'limit')
                             .is_required(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .query_param(new_parameter(status, key: 'status'))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesAllGet200Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Invalid invoice status. The status should be one of: `DRAFT`,'\
                              ' `CREATED`, `SENT`, `PARTIAL`, `PAID`, or `CANCELED`.',
                             InvoicingV2InvoicesAllGet400ResponseException)
                .local_error('404',
                             'No invoices found.',
                             InvoicingV2InvoicesAllGet404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesAllGet502ResponseException))
    .execute
end

#get_invoice(id) ⇒ ApiResponse

You can retrieve details of a specific invoice. This can be used to check the Invoice status and get a list of invoice payments in the invoice history section of the response. For each payment transaction you can use the Transaction Details API to get more details on the payment transaction.

Parameters:

  • id (String)

    Required parameter: The invoice number.

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 99

def get_invoice(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/invoicing/v2/invoices/{id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesGet200Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Invoicing service is not enabled.',
                             InvoicingV2InvoicesGet400ResponseException)
                .local_error('404',
                             'Invoice does not exist.',
                             InvoicingV2InvoicesGet404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesGet502ResponseException))
    .execute
end

#perform_cancel_action(id) ⇒ ApiResponse

You can cancel an invoice if no payment is made to it. You cannot cancel partially or fully paid invoices.

Parameters:

  • id (String)

    Required parameter: The invoice number.

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 197

def perform_cancel_action(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/invoicing/v2/invoices/{id}/cancelation',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesCancel200Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Requested action is not allowed.',
                             InvoicingV2InvoicesCancel400ResponseException)
                .local_error('404',
                             'Invoice does not exist.',
                             InvoicingV2InvoicesCancel404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesCancel502ResponseException))
    .execute
end

#perform_publish_action(id) ⇒ ApiResponse

You can publish an invoice in DRAFT status. After invoking this method, the invoice status is changed to CREATED.

Parameters:

  • id (String)

    Required parameter: The invoice number.

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 227

def perform_publish_action(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/invoicing/v2/invoices/{id}/publication',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesPublish200Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Requested action is not allowed.',
                             InvoicingV2InvoicesPublish400ResponseException)
                .local_error('404',
                             'Invoice does not exist.',
                             InvoicingV2InvoicesPublish404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesPublish502ResponseException))
    .execute
end

#perform_send_action(id) ⇒ ApiResponse

You can send an invoice in draft or created state or resend a sent or partially paid invoice. Fully paid or canceled invoices cannot be resent.

Parameters:

  • id (String)

    Required parameter: The invoice number.

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 167

def perform_send_action(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/invoicing/v2/invoices/{id}/delivery',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesSend200Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Requested action is not allowed.',
                             InvoicingV2InvoicesSend400ResponseException)
                .local_error('404',
                             'Invoice does not exist.',
                             InvoicingV2InvoicesSend404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesSend502ResponseException))
    .execute
end

#update_invoice(id, update_invoice_request) ⇒ ApiResponse

You can update all information except the invoice number till any payment is received for an invoice. Invoices that are partially or fully paid or cancelled cannot be updated. Updating the invoice does not resend the invoice automatically. You must resend the invoice separately.

Parameters:

  • id (String)

    Required parameter: The invoice number.

  • update_invoice_request (UpdateInvoiceRequest)

    Required parameter:

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cyber_source_merged_spec/controllers/invoices_controller.rb', line 133

def update_invoice(id,
                   update_invoice_request)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/invoicing/v2/invoices/{id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .body_param(new_parameter(update_invoice_request)
                            .is_required(true))
               .header_param(new_parameter('application/json;charset=utf-8', key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(InvoicingV2InvoicesPut200Response.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Field validation errors.',
                             InvoicingV2InvoicesPut400ResponseException)
                .local_error('404',
                             'Invoice does not exist.',
                             InvoicingV2InvoicesPut404ResponseException)
                .local_error('502',
                             'Unexpected error.',
                             InvoicingV2InvoicesPut502ResponseException))
    .execute
end