class ProcessOut::Invoice
Attributes
Public Class Methods
Initializes the Invoice
object Params:
client
-
ProcessOut
client instance data
-
data that can be used to fill the object
# File lib/processout/invoice.rb, line 349 def initialize(client, data = {}) @client = client self.id = data.fetch(:id, nil) self.project = data.fetch(:project, nil) self.project_id = data.fetch(:project_id, nil) self.transaction = data.fetch(:transaction, nil) self.transaction_id = data.fetch(:transaction_id, nil) self.customer = data.fetch(:customer, nil) self.customer_id = data.fetch(:customer_id, nil) self.subscription = data.fetch(:subscription, nil) self.subscription_id = data.fetch(:subscription_id, nil) self.token = data.fetch(:token, nil) self.token_id = data.fetch(:token_id, nil) self.details = data.fetch(:details, nil) self.url = data.fetch(:url, nil) self.name = data.fetch(:name, nil) self.amount = data.fetch(:amount, nil) self.currency = data.fetch(:currency, nil) self.merchant_initiator_type = data.fetch(:merchant_initiator_type, nil) self.statement_descriptor = data.fetch(:statement_descriptor, nil) self.statement_descriptor_phone = data.fetch(:statement_descriptor_phone, nil) self.statement_descriptor_city = data.fetch(:statement_descriptor_city, nil) self.statement_descriptor_company = data.fetch(:statement_descriptor_company, nil) self.statement_descriptor_url = data.fetch(:statement_descriptor_url, nil) self.metadata = data.fetch(:metadata, nil) self.gateway_data = data.fetch(:gateway_data, nil) self.return_url = data.fetch(:return_url, nil) self.cancel_url = data.fetch(:cancel_url, nil) self.webhook_url = data.fetch(:webhook_url, nil) self.require_backend_capture = data.fetch(:require_backend_capture, nil) self.sandbox = data.fetch(:sandbox, nil) self.created_at = data.fetch(:created_at, nil) self.risk = data.fetch(:risk, nil) self.shipping = data.fetch(:shipping, nil) self.device = data.fetch(:device, nil) self.external_fraud_tools = data.fetch(:external_fraud_tools, nil) self.exemption_reason_3ds2 = data.fetch(:exemption_reason_3ds2, nil) self.sca_exemption_reason = data.fetch(:sca_exemption_reason, nil) self.challenge_indicator = data.fetch(:challenge_indicator, nil) self.incremental = data.fetch(:incremental, nil) self.tax = data.fetch(:tax, nil) end
Public Instance Methods
Get all the invoices. Params:
options
-
Hash
of options
# File lib/processout/invoice.rb, line 838 def all(options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new a = Array.new body = response.body for v in body['invoices'] tmp = Invoice.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end
# File lib/processout/invoice.rb, line 184 def amount=(val) @amount = val end
Assign a customer to the invoice. Params:
customer_id
-
ID of the customer to be linked to the invoice
options
-
Hash
of options
# File lib/processout/invoice.rb, line 740 def assign_customer(customer_id, options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(@id) + "/customers" data = { "customer_id" => customer_id } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["customer"] customer = Customer.new(@client) return_values.push(customer.fill_with_data(body)) return_values[0] end
# File lib/processout/invoice.rb, line 228 def cancel_url=(val) @cancel_url = val end
Capture the invoice using the given source (customer or token) Params:
source
-
Source used to authorization the payment. Can be a card, a token or a gateway request
options
-
Hash
of options
# File lib/processout/invoice.rb, line 683 def capture(source, options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(@id) + "/capture" data = { "device" => @device, "incremental" => @incremental, "authorize_only" => options.fetch(:authorize_only, nil), "synchronous" => options.fetch(:synchronous, nil), "retry_drop_liability_shift" => options.fetch(:retry_drop_liability_shift, nil), "capture_amount" => options.fetch(:capture_amount, nil), "auto_capture_at" => options.fetch(:auto_capture_at, nil), "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil), "source" => source } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["transaction"] transaction = Transaction.new(@client) return_values.push(transaction.fill_with_data(body)) return_values[0] end
# File lib/processout/invoice.rb, line 320 def challenge_indicator=(val) @challenge_indicator = val end
Create a new invoice. Params:
options
-
Hash
of options
# File lib/processout/invoice.rb, line 868 def create(options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices" data = { "customer_id" => @customer_id, "name" => @name, "amount" => @amount, "currency" => @currency, "metadata" => @metadata, "details" => @details, "exemption_reason_3ds2" => @exemption_reason_3ds2, "sca_exemption_reason" => @sca_exemption_reason, "challenge_indicator" => @challenge_indicator, "gateway_data" => @gateway_data, "merchant_initiator_type" => @merchant_initiator_type, "statement_descriptor" => @statement_descriptor, "statement_descriptor_phone" => @statement_descriptor_phone, "statement_descriptor_city" => @statement_descriptor_city, "statement_descriptor_company" => @statement_descriptor_company, "statement_descriptor_url" => @statement_descriptor_url, "return_url" => @return_url, "cancel_url" => @cancel_url, "webhook_url" => @webhook_url, "risk" => @risk, "shipping" => @shipping, "device" => @device, "require_backend_capture" => @require_backend_capture, "external_fraud_tools" => @external_fraud_tools, "tax" => @tax } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["invoice"] return_values.push(self.fill_with_data(body)) return_values[0] end
# File lib/processout/invoice.rb, line 244 def created_at=(val) @created_at = val end
# File lib/processout/invoice.rb, line 188 def currency=(val) @currency = val end
# File lib/processout/invoice.rb, line 96 def customer=(val) if val.nil? @customer = val return end if val.instance_of? Customer @customer = val else obj = Customer.new(@client) obj.fill_with_data(val) @customer = obj end end
# File lib/processout/invoice.rb, line 112 def customer_id=(val) @customer_id = val end
# File lib/processout/invoice.rb, line 156 def details=(val) if val.nil? @details = [] return end if val.length > 0 and val[0].instance_of? InvoiceDetail @details = val else l = Array.new for v in val obj = InvoiceDetail.new(@client) obj.fill_with_data(v) l.push(obj) end @details = l end end
# File lib/processout/invoice.rb, line 280 def device=(val) if val.nil? @device = val return end if val.instance_of? InvoiceDevice @device = val else obj = InvoiceDevice.new(@client) obj.fill_with_data(val) @device = obj end end
# File lib/processout/invoice.rb, line 312 def exemption_reason_3ds2=(val) @exemption_reason_3ds2 = val end
# File lib/processout/invoice.rb, line 296 def external_fraud_tools=(val) if val.nil? @external_fraud_tools = val return end if val.instance_of? InvoiceExternalFraudTools @external_fraud_tools = val else obj = InvoiceExternalFraudTools.new(@client) obj.fill_with_data(val) @external_fraud_tools = obj end end
Get the customer linked to the invoice. Params:
options
-
Hash
of options
# File lib/processout/invoice.rb, line 715 def fetch_customer(options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(@id) + "/customers" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new body = response.body body = body["customer"] customer = Customer.new(@client) return_values.push(customer.fill_with_data(body)) return_values[0] end
Get the transaction of the invoice. Params:
options
-
Hash
of options
# File lib/processout/invoice.rb, line 790 def fetch_transaction(options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(@id) + "/transactions" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new body = response.body body = body["transaction"] transaction = Transaction.new(@client) return_values.push(transaction.fill_with_data(body)) return_values[0] end
Fills the object with data coming from the API Params:
data
-
Hash
of data coming from the API
# File lib/processout/invoice.rb, line 447 def fill_with_data(data) if data.nil? return self end if data.include? "id" self.id = data["id"] end if data.include? "project" self.project = data["project"] end if data.include? "project_id" self.project_id = data["project_id"] end if data.include? "transaction" self.transaction = data["transaction"] end if data.include? "transaction_id" self.transaction_id = data["transaction_id"] end if data.include? "customer" self.customer = data["customer"] end if data.include? "customer_id" self.customer_id = data["customer_id"] end if data.include? "subscription" self.subscription = data["subscription"] end if data.include? "subscription_id" self.subscription_id = data["subscription_id"] end if data.include? "token" self.token = data["token"] end if data.include? "token_id" self.token_id = data["token_id"] end if data.include? "details" self.details = data["details"] end if data.include? "url" self.url = data["url"] end if data.include? "name" self.name = data["name"] end if data.include? "amount" self.amount = data["amount"] end if data.include? "currency" self.currency = data["currency"] end if data.include? "merchant_initiator_type" self.merchant_initiator_type = data["merchant_initiator_type"] end if data.include? "statement_descriptor" self.statement_descriptor = data["statement_descriptor"] end if data.include? "statement_descriptor_phone" self.statement_descriptor_phone = data["statement_descriptor_phone"] end if data.include? "statement_descriptor_city" self.statement_descriptor_city = data["statement_descriptor_city"] end if data.include? "statement_descriptor_company" self.statement_descriptor_company = data["statement_descriptor_company"] end if data.include? "statement_descriptor_url" self.statement_descriptor_url = data["statement_descriptor_url"] end if data.include? "metadata" self.metadata = data["metadata"] end if data.include? "gateway_data" self.gateway_data = data["gateway_data"] end if data.include? "return_url" self.return_url = data["return_url"] end if data.include? "cancel_url" self.cancel_url = data["cancel_url"] end if data.include? "webhook_url" self.webhook_url = data["webhook_url"] end if data.include? "require_backend_capture" self.require_backend_capture = data["require_backend_capture"] end if data.include? "sandbox" self.sandbox = data["sandbox"] end if data.include? "created_at" self.created_at = data["created_at"] end if data.include? "risk" self.risk = data["risk"] end if data.include? "shipping" self.shipping = data["shipping"] end if data.include? "device" self.device = data["device"] end if data.include? "external_fraud_tools" self.external_fraud_tools = data["external_fraud_tools"] end if data.include? "exemption_reason_3ds2" self.exemption_reason_3ds2 = data["exemption_reason_3ds2"] end if data.include? "sca_exemption_reason" self.sca_exemption_reason = data["sca_exemption_reason"] end if data.include? "challenge_indicator" self.challenge_indicator = data["challenge_indicator"] end if data.include? "incremental" self.incremental = data["incremental"] end if data.include? "tax" self.tax = data["tax"] end self end
Find an invoice by its ID. Params:
invoice_id
-
ID of the invoice
options
-
Hash
of options
# File lib/processout/invoice.rb, line 919 def find(invoice_id, options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(invoice_id) + "" data = { } response = Response.new(request.get(path, data, options)) return_values = Array.new body = response.body body = body["invoice"] obj = Invoice.new(@client) return_values.push(obj.fill_with_data(body)) return_values[0] end
# File lib/processout/invoice.rb, line 220 def gateway_data=(val) @gateway_data = val end
# File lib/processout/invoice.rb, line 52 def id=(val) @id = val end
# File lib/processout/invoice.rb, line 324 def incremental=(val) @incremental = val end
Initiate a 3-D Secure authentication Params:
source
-
Source used to initiate the 3-D Secure authentication. Can be a card, or a token representing a card
options
-
Hash
of options
# File lib/processout/invoice.rb, line 765 def initiate_three_d_s(source, options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(@id) + "/three-d-s" data = { "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil), "source" => source } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["customer_action"] customer_action = CustomerAction.new(@client) return_values.push(customer_action.fill_with_data(body)) return_values[0] end
# File lib/processout/invoice.rb, line 192 def merchant_initiator_type=(val) @merchant_initiator_type = val end
# File lib/processout/invoice.rb, line 216 def metadata=(val) @metadata = val end
# File lib/processout/invoice.rb, line 180 def name=(val) @name = val end
Create a new Invoice
using the current client
# File lib/processout/invoice.rb, line 395 def new(data = {}) Invoice.new(@client, data) end
Prefills the object with the data passed as parameters Params:
data
-
Hash
of data
# File lib/processout/invoice.rb, line 575 def prefill(data) if data.nil? return self end self.id = data.fetch(:id, self.id) self.project = data.fetch(:project, self.project) self.project_id = data.fetch(:project_id, self.project_id) self.transaction = data.fetch(:transaction, self.transaction) self.transaction_id = data.fetch(:transaction_id, self.transaction_id) self.customer = data.fetch(:customer, self.customer) self.customer_id = data.fetch(:customer_id, self.customer_id) self.subscription = data.fetch(:subscription, self.subscription) self.subscription_id = data.fetch(:subscription_id, self.subscription_id) self.token = data.fetch(:token, self.token) self.token_id = data.fetch(:token_id, self.token_id) self.details = data.fetch(:details, self.details) self.url = data.fetch(:url, self.url) self.name = data.fetch(:name, self.name) self.amount = data.fetch(:amount, self.amount) self.currency = data.fetch(:currency, self.currency) self.merchant_initiator_type = data.fetch(:merchant_initiator_type, self.merchant_initiator_type) self.statement_descriptor = data.fetch(:statement_descriptor, self.statement_descriptor) self.statement_descriptor_phone = data.fetch(:statement_descriptor_phone, self.statement_descriptor_phone) self.statement_descriptor_city = data.fetch(:statement_descriptor_city, self.statement_descriptor_city) self.statement_descriptor_company = data.fetch(:statement_descriptor_company, self.statement_descriptor_company) self.statement_descriptor_url = data.fetch(:statement_descriptor_url, self.statement_descriptor_url) self.metadata = data.fetch(:metadata, self.metadata) self.gateway_data = data.fetch(:gateway_data, self.gateway_data) self.return_url = data.fetch(:return_url, self.return_url) self.cancel_url = data.fetch(:cancel_url, self.cancel_url) self.webhook_url = data.fetch(:webhook_url, self.webhook_url) self.require_backend_capture = data.fetch(:require_backend_capture, self.require_backend_capture) self.sandbox = data.fetch(:sandbox, self.sandbox) self.created_at = data.fetch(:created_at, self.created_at) self.risk = data.fetch(:risk, self.risk) self.shipping = data.fetch(:shipping, self.shipping) self.device = data.fetch(:device, self.device) self.external_fraud_tools = data.fetch(:external_fraud_tools, self.external_fraud_tools) self.exemption_reason_3ds2 = data.fetch(:exemption_reason_3ds2, self.exemption_reason_3ds2) self.sca_exemption_reason = data.fetch(:sca_exemption_reason, self.sca_exemption_reason) self.challenge_indicator = data.fetch(:challenge_indicator, self.challenge_indicator) self.incremental = data.fetch(:incremental, self.incremental) self.tax = data.fetch(:tax, self.tax) self end
# File lib/processout/invoice.rb, line 56 def project=(val) if val.nil? @project = val return end if val.instance_of? Project @project = val else obj = Project.new(@client) obj.fill_with_data(val) @project = obj end end
# File lib/processout/invoice.rb, line 72 def project_id=(val) @project_id = val end
# File lib/processout/invoice.rb, line 236 def require_backend_capture=(val) @require_backend_capture = val end
# File lib/processout/invoice.rb, line 224 def return_url=(val) @return_url = val end
# File lib/processout/invoice.rb, line 248 def risk=(val) if val.nil? @risk = val return end if val.instance_of? InvoiceRisk @risk = val else obj = InvoiceRisk.new(@client) obj.fill_with_data(val) @risk = obj end end
# File lib/processout/invoice.rb, line 240 def sandbox=(val) @sandbox = val end
# File lib/processout/invoice.rb, line 316 def sca_exemption_reason=(val) @sca_exemption_reason = val end
# File lib/processout/invoice.rb, line 264 def shipping=(val) if val.nil? @shipping = val return end if val.instance_of? InvoiceShipping @shipping = val else obj = InvoiceShipping.new(@client) obj.fill_with_data(val) @shipping = obj end end
# File lib/processout/invoice.rb, line 196 def statement_descriptor=(val) @statement_descriptor = val end
# File lib/processout/invoice.rb, line 204 def statement_descriptor_city=(val) @statement_descriptor_city = val end
# File lib/processout/invoice.rb, line 208 def statement_descriptor_company=(val) @statement_descriptor_company = val end
# File lib/processout/invoice.rb, line 200 def statement_descriptor_phone=(val) @statement_descriptor_phone = val end
# File lib/processout/invoice.rb, line 212 def statement_descriptor_url=(val) @statement_descriptor_url = val end
# File lib/processout/invoice.rb, line 116 def subscription=(val) if val.nil? @subscription = val return end if val.instance_of? Subscription @subscription = val else obj = Subscription.new(@client) obj.fill_with_data(val) @subscription = obj end end
# File lib/processout/invoice.rb, line 132 def subscription_id=(val) @subscription_id = val end
# File lib/processout/invoice.rb, line 328 def tax=(val) if val.nil? @tax = val return end if val.instance_of? InvoiceTax @tax = val else obj = InvoiceTax.new(@client) obj.fill_with_data(val) @tax = obj end end
Overrides the JSON marshaller to only send the fields we want
# File lib/processout/invoice.rb, line 400 def to_json(options) { "id": self.id, "project": self.project, "project_id": self.project_id, "transaction": self.transaction, "transaction_id": self.transaction_id, "customer": self.customer, "customer_id": self.customer_id, "subscription": self.subscription, "subscription_id": self.subscription_id, "token": self.token, "token_id": self.token_id, "details": self.details, "url": self.url, "name": self.name, "amount": self.amount, "currency": self.currency, "merchant_initiator_type": self.merchant_initiator_type, "statement_descriptor": self.statement_descriptor, "statement_descriptor_phone": self.statement_descriptor_phone, "statement_descriptor_city": self.statement_descriptor_city, "statement_descriptor_company": self.statement_descriptor_company, "statement_descriptor_url": self.statement_descriptor_url, "metadata": self.metadata, "gateway_data": self.gateway_data, "return_url": self.return_url, "cancel_url": self.cancel_url, "webhook_url": self.webhook_url, "require_backend_capture": self.require_backend_capture, "sandbox": self.sandbox, "created_at": self.created_at, "risk": self.risk, "shipping": self.shipping, "device": self.device, "external_fraud_tools": self.external_fraud_tools, "exemption_reason_3ds2": self.exemption_reason_3ds2, "sca_exemption_reason": self.sca_exemption_reason, "challenge_indicator": self.challenge_indicator, "incremental": self.incremental, "tax": self.tax, }.to_json end
# File lib/processout/invoice.rb, line 136 def token=(val) if val.nil? @token = val return end if val.instance_of? Token @token = val else obj = Token.new(@client) obj.fill_with_data(val) @token = obj end end
# File lib/processout/invoice.rb, line 152 def token_id=(val) @token_id = val end
# File lib/processout/invoice.rb, line 76 def transaction=(val) if val.nil? @transaction = val return end if val.instance_of? Transaction @transaction = val else obj = Transaction.new(@client) obj.fill_with_data(val) @transaction = obj end end
# File lib/processout/invoice.rb, line 92 def transaction_id=(val) @transaction_id = val end
# File lib/processout/invoice.rb, line 176 def url=(val) @url = val end
Void the invoice Params:
options
-
Hash
of options
# File lib/processout/invoice.rb, line 814 def void(options = {}) self.prefill(options) request = Request.new(@client) path = "/invoices/" + CGI.escape(@id) + "/void" data = { } response = Response.new(request.post(path, data, options)) return_values = Array.new body = response.body body = body["transaction"] transaction = Transaction.new(@client) return_values.push(transaction.fill_with_data(body)) return_values[0] end
# File lib/processout/invoice.rb, line 232 def webhook_url=(val) @webhook_url = val end