Skip to content

Commit

Permalink
add: Payment services
Browse files Browse the repository at this point in the history
  • Loading branch information
jono-booth committed Jun 19, 2018
1 parent 95e4e9b commit 210b93b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pkg/
.DS_Store
.idea/
Gemfile.lock
tmp/
tmp/
1 change: 1 addition & 0 deletions lib/xeroizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
require 'xeroizer/models/option'
require 'xeroizer/models/organisation'
require 'xeroizer/models/payment'
require 'xeroizer/models/payment_service'
require 'xeroizer/models/prepayment'
require 'xeroizer/models/overpayment'
require 'xeroizer/models/phone'
Expand Down
3 changes: 2 additions & 1 deletion lib/xeroizer/generic_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GenericApplication
record :ManualJournal
record :Organisation
record :Payment
record :PaymentService
record :Prepayment
record :Overpayment
record :PurchaseOrder
Expand Down Expand Up @@ -80,6 +81,6 @@ def payroll(options = {})
xero_client.xero_url = options[:xero_url] || "https://api.xero.com/payroll.xro/1.0"
@payroll ||= PayrollApplication.new(xero_client)
end

end
end
58 changes: 49 additions & 9 deletions lib/xeroizer/models/branding_theme.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
require "xeroizer/models/payment_service"

module Xeroizer
module Record

class BrandingThemeModel < BaseModel

set_permissions :read


set_permissions :read, :write

public

def payment_services(id)
@payment_services ||= @application.http_get(@application.client, payment_services_endpoint(id))
end

def add_payment_service(id:,payment_service_id:)
xml = {
PaymentService: {
PaymentServiceID: payment_service_id
}
}.to_xml

@application.http_post(@application.client, payment_services_endpoint(id), xml)
end

private

def payment_services_endpoint(id)
"#{url}/#{id}/PaymentServices"
end

end

class BrandingTheme < Base

set_primary_key :branding_theme_id

guid :branding_theme_id
string :name
integer :sort_order
datetime_utc :created_date_utc, :api_name => 'CreatedDateUTC'

# Unfortunately, this part of the API does not work the same as the rest.
# You cannot POST child records to Branding Themes.
#
# The endpoints are:
# GET /BrandingThemes/{BrandingThemeID}/PaymentServices
# POST /BrandingThemes/{BrandingThemeID}/PaymentServices
#
# has_one :payment_service, :model_name => 'PaymentService', :list_complete => true

def payment_services
parent.payment_services(id)
end

def add_payment_service(payment_service_id)
parent.add_payment_service(id: id, payment_service_id: payment_service_id)
end
end

end
end
end
22 changes: 22 additions & 0 deletions lib/xeroizer/models/payment_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Xeroizer
module Record

class PaymentServiceModel < BaseModel

set_permissions :read, :write, :update

end

class PaymentService < Base

set_primary_key :payment_service_id

guid :payment_service_id
string :payment_service_name
string :payment_service_url
string :payment_service_type
string :pay_now_text

end
end
end
15 changes: 15 additions & 0 deletions test/stub_responses/payment_service.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Id>42d8b00c-2fdd-4a8a-9b84-82cfe78ff34a</Id>
<Status>OK</Status>
<ProviderName>Test Provider Name</ProviderName>
<DateTimeUTC>2018-06-18T04:13:44.7828584Z</DateTimeUTC>
<PaymentServices>
<PaymentService>
<PaymentServiceID>4d7f4335-6f16-437a-86e3-a856ebc576b8</PaymentServiceID>
<PaymentServiceName>Custom Service</PaymentServiceName>
<PaymentServiceType>Custom</PaymentServiceType>
<PaymentServiceUrl>http://example.com</PaymentServiceUrl>
<PayNowText>Pay Me</PayNowText>
</PaymentService>
</PaymentServices>
</Response>
29 changes: 29 additions & 0 deletions test/unit/models/payment_service_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'test_helper'

class PaymentServiceTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
end

context "response parsing" do
it "parses default attributes" do
@instance = Xeroizer::Record::PaymentServiceModel.new(nil, "PaymentService")

some_xml = get_record_xml("payment_service")

result = @instance.parse_response(some_xml)
payment_service = result.response_items.first

keys = [:payment_service_id,
:payment_service_name,
:payment_service_type,
:payment_service_url,
:pay_now_text
]

assert_equal(payment_service.attributes.keys, keys)
end
end
end

0 comments on commit 210b93b

Please sign in to comment.