Skip to content

Commit

Permalink
BREAKING CHANGE: breaking: change response types for invoices-authori…
Browse files Browse the repository at this point in the history
…ze, invoices-capture, invoices-native-payment; breaking: create/update card; add invoice expiry; add invoice qr_code; add invoice delete; add project public metadata; add hosted payment page support (#11)

Co-authored-by: ProcessOut Fountain <[email protected]>
  • Loading branch information
mateusz-walesiak-cko and processout-machine authored Jul 10, 2024
1 parent 2117e09 commit adb6308
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 145 deletions.
6 changes: 0 additions & 6 deletions lib/processout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
require "processout/native_apm_transaction_details_gateway"
require "processout/native_apm_transaction_details_invoice"
require "processout/native_apm_transaction_details"
require "processout/invoices_process_native_payment_response"

module ProcessOut
class Client
Expand Down Expand Up @@ -391,11 +390,6 @@ def native_apm_transaction_details(data = {})
obj = NativeAPMTransactionDetails.new(self, data)
end

# Create a new InvoicesProcessNativePaymentResponse instance
def invoices_process_native_payment_response(data = {})
obj = InvoicesProcessNativePaymentResponse.new(self, data)
end


end
end
33 changes: 33 additions & 0 deletions lib/processout/card_shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class CardShipping
attr_reader :country_code
attr_reader :zip
attr_reader :phone
attr_reader :first_name
attr_reader :last_name
attr_reader :email


def address1=(val)
Expand Down Expand Up @@ -57,6 +60,18 @@ def phone=(val)

end

def first_name=(val)
@first_name = val
end

def last_name=(val)
@last_name = val
end

def email=(val)
@email = val
end


# Initializes the CardShipping object
# Params:
Expand All @@ -72,6 +87,9 @@ def initialize(client, data = {})
self.country_code = data.fetch(:country_code, nil)
self.zip = data.fetch(:zip, nil)
self.phone = data.fetch(:phone, nil)
self.first_name = data.fetch(:first_name, nil)
self.last_name = data.fetch(:last_name, nil)
self.email = data.fetch(:email, nil)

end

Expand All @@ -90,6 +108,9 @@ def to_json(options)
"country_code": self.country_code,
"zip": self.zip,
"phone": self.phone,
"first_name": self.first_name,
"last_name": self.last_name,
"email": self.email,
}.to_json
end

Expand Down Expand Up @@ -121,6 +142,15 @@ def fill_with_data(data)
if data.include? "phone"
self.phone = data["phone"]
end
if data.include? "first_name"
self.first_name = data["first_name"]
end
if data.include? "last_name"
self.last_name = data["last_name"]
end
if data.include? "email"
self.email = data["email"]
end

self
end
Expand All @@ -139,6 +169,9 @@ def prefill(data)
self.country_code = data.fetch(:country_code, self.country_code)
self.zip = data.fetch(:zip, self.zip)
self.phone = data.fetch(:phone, self.phone)
self.first_name = data.fetch(:first_name, self.first_name)
self.last_name = data.fetch(:last_name, self.last_name)
self.email = data.fetch(:email, self.email)

self
end
Expand Down
24 changes: 0 additions & 24 deletions lib/processout/card_update_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,9 @@
module ProcessOut
class CardUpdateRequest

attr_reader :update_type
attr_reader :update_reason
attr_reader :preferred_scheme


def update_type=(val)
@update_type = val
end

def update_reason=(val)
@update_reason = val
end

def preferred_scheme=(val)
@preferred_scheme = val
end
Expand All @@ -33,8 +23,6 @@ def preferred_scheme=(val)
def initialize(client, data = {})
@client = client

self.update_type = data.fetch(:update_type, nil)
self.update_reason = data.fetch(:update_reason, nil)
self.preferred_scheme = data.fetch(:preferred_scheme, nil)

end
Expand All @@ -47,8 +35,6 @@ def new(data = {})
# Overrides the JSON marshaller to only send the fields we want
def to_json(options)
{
"update_type": self.update_type,
"update_reason": self.update_reason,
"preferred_scheme": self.preferred_scheme,
}.to_json
end
Expand All @@ -60,12 +46,6 @@ def fill_with_data(data)
if data.nil?
return self
end
if data.include? "update_type"
self.update_type = data["update_type"]
end
if data.include? "update_reason"
self.update_reason = data["update_reason"]
end
if data.include? "preferred_scheme"
self.preferred_scheme = data["preferred_scheme"]
end
Expand All @@ -80,8 +60,6 @@ def prefill(data)
if data.nil?
return self
end
self.update_type = data.fetch(:update_type, self.update_type)
self.update_reason = data.fetch(:update_reason, self.update_reason)
self.preferred_scheme = data.fetch(:preferred_scheme, self.preferred_scheme)

self
Expand All @@ -97,8 +75,6 @@ def update(card_id, options = {})
request = Request.new(@client)
path = "/cards/" + CGI.escape(card_id) + ""
data = {
"update_type" => @update_type,
"update_reason" => @update_reason,
"preferred_scheme" => @preferred_scheme
}

Expand Down
70 changes: 64 additions & 6 deletions lib/processout/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Invoice
attr_reader :token_id
attr_reader :details
attr_reader :url
attr_reader :url_qrcode
attr_reader :name
attr_reader :order_id
attr_reader :amount
Expand All @@ -39,6 +40,7 @@ class Invoice
attr_reader :require_backend_capture
attr_reader :sandbox
attr_reader :created_at
attr_reader :expires_at
attr_reader :risk
attr_reader :shipping
attr_reader :device
Expand Down Expand Up @@ -186,6 +188,10 @@ def url=(val)
@url = val
end

def url_qrcode=(val)
@url_qrcode = val
end

def name=(val)
@name = val
end
Expand Down Expand Up @@ -258,6 +264,10 @@ def created_at=(val)
@created_at = val
end

def expires_at=(val)
@expires_at = val
end

def risk=(val)
if val.nil?
@risk = val
Expand Down Expand Up @@ -443,6 +453,7 @@ def initialize(client, data = {})
self.token_id = data.fetch(:token_id, nil)
self.details = data.fetch(:details, nil)
self.url = data.fetch(:url, nil)
self.url_qrcode = data.fetch(:url_qrcode, nil)
self.name = data.fetch(:name, nil)
self.order_id = data.fetch(:order_id, nil)
self.amount = data.fetch(:amount, nil)
Expand All @@ -461,6 +472,7 @@ def initialize(client, data = {})
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.expires_at = data.fetch(:expires_at, nil)
self.risk = data.fetch(:risk, nil)
self.shipping = data.fetch(:shipping, nil)
self.device = data.fetch(:device, nil)
Expand Down Expand Up @@ -502,6 +514,7 @@ def to_json(options)
"token_id": self.token_id,
"details": self.details,
"url": self.url,
"url_qrcode": self.url_qrcode,
"name": self.name,
"order_id": self.order_id,
"amount": self.amount,
Expand All @@ -520,6 +533,7 @@ def to_json(options)
"require_backend_capture": self.require_backend_capture,
"sandbox": self.sandbox,
"created_at": self.created_at,
"expires_at": self.expires_at,
"risk": self.risk,
"shipping": self.shipping,
"device": self.device,
Expand Down Expand Up @@ -586,6 +600,9 @@ def fill_with_data(data)
if data.include? "url"
self.url = data["url"]
end
if data.include? "url_qrcode"
self.url_qrcode = data["url_qrcode"]
end
if data.include? "name"
self.name = data["name"]
end
Expand Down Expand Up @@ -640,6 +657,9 @@ def fill_with_data(data)
if data.include? "created_at"
self.created_at = data["created_at"]
end
if data.include? "expires_at"
self.expires_at = data["expires_at"]
end
if data.include? "risk"
self.risk = data["risk"]
end
Expand Down Expand Up @@ -715,6 +735,7 @@ def prefill(data)
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.url_qrcode = data.fetch(:url_qrcode, self.url_qrcode)
self.name = data.fetch(:name, self.name)
self.order_id = data.fetch(:order_id, self.order_id)
self.amount = data.fetch(:amount, self.amount)
Expand All @@ -733,6 +754,7 @@ def prefill(data)
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.expires_at = data.fetch(:expires_at, self.expires_at)
self.risk = data.fetch(:risk, self.risk)
self.shipping = data.fetch(:shipping, self.shipping)
self.device = data.fetch(:device, self.device)
Expand Down Expand Up @@ -810,9 +832,13 @@ def authorize(source, options = {})
body = body["transaction"]
transaction = Transaction.new(@client)
return_values.push(transaction.fill_with_data(body))
body = response.body
body = body["customer_action"]
customer_action = CustomerAction.new(@client)
return_values.push(customer_action.fill_with_data(body))


return_values[0]
return_values
end

# Capture the invoice using the given source (customer or token)
Expand Down Expand Up @@ -846,9 +872,13 @@ def capture(source, options = {})
body = body["transaction"]
transaction = Transaction.new(@client)
return_values.push(transaction.fill_with_data(body))
body = response.body
body = body["customer_action"]
customer_action = CustomerAction.new(@client)
return_values.push(customer_action.fill_with_data(body))


return_values[0]
return_values
end

# Get the customer linked to the invoice.
Expand Down Expand Up @@ -972,11 +1002,16 @@ def process_native_payment(invoice_id, options = {})
return_values = Array.new

body = response.body
invoices_process_native_payment_response = InvoicesProcessNativePaymentResponse.new(@client)
return_values.push(invoices_process_native_payment_response.fill_with_data(body))
body = body["transaction"]
transaction = Transaction.new(@client)
return_values.push(transaction.fill_with_data(body))
body = response.body
body = body["native_apm"]
native_apm_response = NativeAPMResponse.new(@client)
return_values.push(native_apm_response.fill_with_data(body))


return_values[0]
return_values
end

# Initiate a 3-D Secure authentication
Expand Down Expand Up @@ -1125,7 +1160,8 @@ def create(options = {})
"billing" => @billing,
"unsupported_feature_bypass" => @unsupported_feature_bypass,
"verification" => @verification,
"auto_capture_at" => @auto_capture_at
"auto_capture_at" => @auto_capture_at,
"expires_at" => @expires_at
}

response = Response.new(request.post(path, data, options))
Expand Down Expand Up @@ -1167,6 +1203,28 @@ def find(invoice_id, options = {})



return_values[0]
end

# Delete an invoice by its ID. Only invoices that have not been used yet can be deleted.
# Params:
# +invoice_id+:: ID of the invoice
# +options+:: +Hash+ of options
def delete(invoice_id, options = {})
self.prefill(options)

request = Request.new(@client)
path = "/invoices/" + CGI.escape(invoice_id) + ""
data = {

}

response = Response.new(request.delete(path, data, options))
return_values = Array.new

return_values.push(response.success)


return_values[0]
end

Expand Down
3 changes: 3 additions & 0 deletions lib/processout/invoice_external_fraud_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ class InvoiceExternalFraudTools

def forter=(val)
@forter = val

end

def ravelin=(val)
@ravelin = val

end

def signifyd=(val)
@signifyd = val

end


Expand Down
Loading

0 comments on commit adb6308

Please sign in to comment.