Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment services #439

Merged
merged 3 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CloCkWeRX could you give me an example of proper formatting for named params please. Would this suffice?

def add_payment_service(id:, payment_service_id:)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure would :)

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
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved

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