-
Notifications
You must be signed in to change notification settings - Fork 6
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
Api update #32
base: main
Are you sure you want to change the base?
Api update #32
Changes from 13 commits
28fcb95
b06dd3f
fe68572
62799d5
2585f83
a8993ba
ef8a4b8
b775e24
18a359f
9c716df
6154d97
88eaf74
f265205
19eee4a
1c879b5
4089f41
28abbcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,79 @@ Or install it yourself as: | |
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
### INIT: | ||
``` | ||
PactasItero.client_id = "my_billwerk_client_id" | ||
PactasItero.client_secret = "my_billwerk_client_secret" | ||
@billwerkClient = PactasItero.client | ||
@billwerkClient.bearer_token = @billwerkClient.try(:token).try(:access_token) | ||
``` | ||
|
||
### Examples: | ||
|
||
#### 1) Create-Plan Example | ||
|
||
``` | ||
plangroup_id = "16dc8c7gba5c2202143de8b5" | ||
plan_options={} | ||
plan_options[:Name] = {"_c" => "Package XXL" } | ||
plan_options[:PlanDescription] = {"_c"=>"This is the Plan-Description for XXL"} | ||
plan_options[:PlanGroupId] = plangroup_id | ||
plan_options[:SetupDescription] = {"_c"=>"one-time setup-fee"} | ||
plan_options[:TrialEndNotificationPeriod] = {'Unit' => "Day", 'Quantity' => 3} | ||
plan_options[:TrialEndPolicy] = "RequestPayment" | ||
plan_options[:TrialPeriod] = {:Unit => "Day", :Quantity => 7} | ||
plan_options[:IsQuantityBased] = false | ||
plan_options[:Hidden] = false | ||
plan_options[:IsDeletable] = false | ||
@[email protected]_plan(plangroup_id,plan_options) | ||
``` | ||
|
||
#### 2) Create-Order Example | ||
|
||
##### Submitted via Order-Form (Example Data) | ||
|
||
``` | ||
Parameters: {"Cart"=>{"PlanVariantId"=>"19dc8c7gba5c2202143de1s9"}, | ||
"Customer"=>{"CompanyName"=>"Mustermann Ltd.", "EmailAddress"=>"[email protected]", "FirstName"=>"Klaus", "LastName"=>"Mustermann", "VatId"=>"DE63244715", | ||
"Address"=>{"Street"=>"Karl-Str.", "HouseNumber"=>"55", "PostalCode"=>"10421", "City"=>"Berlin", "Country"=>"DE"}}, | ||
"Bearer"=>{"holder"=>"Mustermann Ltd", "iban"=>"DE883299699663", "bic"=>"HAC556AXXX"}} | ||
``` | ||
|
||
##### Usage in Order-Controller | ||
|
||
``` | ||
orderOptions = {} | ||
orderOptions[:ContractCustomFields] = {} | ||
orderOptions[:AdditionalData] = {} | ||
orderOptions[:AdditionalData][:Contract] = {} | ||
orderOptions[:AdditionalData][:Contract][:CustomFields] = {} | ||
orderOptions[:Cart] = params[:Cart].to_h | ||
orderOptions[:Cart][:Quantity] = 1 | ||
orderOptions[:Cart][:EnableTrial] = true | ||
orderOptions[:Cart][:ComponentSubscriptions] = [] | ||
orderOptions[:Cart][:MeteredUsages] = [] | ||
orderOptions[:Cart][:DiscountSubscriptions] = [] | ||
orderOptions[:Cart][:RatedItems] = [] | ||
orderOptions[:Customer] = params[:Customer].to_h | ||
orderOptions[:Customer][:ExternalCustomerId] = "#{current_customer.id}" | ||
orderOptions[:Customer][:Language] = 'de-DE'; | ||
orderOptions[:Customer][:Locale] = 'de-DE'; | ||
orderOptions[:Customer][:DebitorAccount] = "#{current_customer.debit_id}" | ||
orderOptions[:Customer][:Hidden] = false | ||
orderOptions[:StartDate] = Time.now.to_formatted_s(:iso8601) | ||
@[email protected]_order(orderOptions) | ||
``` | ||
|
||
##### On Success Commit-Order via Order-Controller | ||
|
||
``` | ||
commitOptions = {} | ||
commitOptions[:PaymentMethod] = "Debit:FakeProvider" | ||
commitOptions[:Bearer] = params[:Bearer].to_h | ||
commitOptions[:Bearer][:mandatereference] = "Z-#{current_customer.debit_id}-#{current_customer.id}" | ||
@commit = @billwerkClient.commit_order(@order.id, commitOptions) | ||
``` | ||
|
||
## Contributing | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module PactasItero | ||
module Api | ||
module Components | ||
def components(options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/components", options | ||
end | ||
|
||
def component(component_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/components/#{component_id}", options | ||
end | ||
|
||
def create_component(plangroup_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/planGroups/#{plangroup_id}/components", options | ||
end | ||
|
||
def update_component(component_id, options = {}) | ||
options = options.camelize_keys | ||
patch "api/v1/components/#{component_id}", options | ||
end | ||
|
||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a newline at the end of the file, your editor should have an option to do this automatically for you. This should be applied to all files of this pull request. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,28 @@ def terminate_contract(contract_id, options = {}) | |
options = options.camelize_keys | ||
post "api/v1/contracts/#{contract_id}/end", options | ||
end | ||
|
||
def annulate_contract(contract_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/contracts/#{contract_id}/annulate", options | ||
end | ||
|
||
def ledger_entries_for_contract(contract_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/contracts/#{contract_id}/ledgerEntries", options | ||
end | ||
|
||
def change_payment_method_for_contract(contract_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/contracts/#{contract_id}/changepaymentmethod", options | ||
end | ||
|
||
def subscribe_component_for_contract(contract_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/contracts/#{contract_id}/componentsubscriptions", options | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not add empty lines before |
||
end | ||
|
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module PactasItero | ||
module Api | ||
module Coupons | ||
def coupons(options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/coupons", options | ||
end | ||
|
||
def coupon(coupon_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/coupons/#{coupon_id}", options | ||
end | ||
|
||
def create_coupon(plangroup_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/planGroups/#{plangroup_id}/coupons", options | ||
end | ||
|
||
def update_coupon(coupon_id, options = {}) | ||
options = options.camelize_keys | ||
patch "api/v1/coupons/#{coupon_id}", options | ||
end | ||
|
||
def coupon_by_code(coupon_code, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/coupons/?couponCode=#{coupon_code}", options | ||
end | ||
|
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module PactasItero | ||
module Api | ||
module Discounts | ||
def discounts(options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/Discounts", options | ||
end | ||
|
||
def discount(discount_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/Discounts/#{discount_id}", options | ||
end | ||
|
||
def create_discount(plangroup_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/planGroups/#{plangroup_id}/discounts", options | ||
end | ||
|
||
def update_discount(discount_id, options = {}) | ||
options = options.camelize_keys | ||
patch "api/v1/discount/#{discount_id}", options | ||
end | ||
|
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module PactasItero | ||
module Api | ||
module Plans | ||
def plans(options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/Plans", options | ||
end | ||
|
||
def plan(plan_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/plans/#{plan_id}", options | ||
end | ||
|
||
def create_plan(plangroup_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/planGroups/#{plangroup_id}/plans", options | ||
end | ||
|
||
def update_plan(plan_id, options = {}) | ||
options = options.camelize_keys | ||
patch "api/v1/plans/#{plan_id}", options | ||
end | ||
|
||
def plan_variants(options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/planvariants", options | ||
end | ||
|
||
def plan_variant(planvariant_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/planvariants/#{planvariant_id}", options | ||
end | ||
|
||
def create_plan_variant(plan_id, options = {}) | ||
options = options.camelize_keys | ||
post "api/v1/plans/#{plan_id}/planvariants", options | ||
end | ||
|
||
def update_plan_variant(planvariant_id, options = {}) | ||
options = options.camelize_keys | ||
patch "api/v1/planvariants/#{planvariant_id}", options | ||
end | ||
|
||
def plan_variants_for_plan(plan_id, options = {}) | ||
options = options.camelize_keys | ||
get "api/v1/plans/#{plan_id}/planvariants", options | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ def request(method, path, params = {}) | |
def connection_options | ||
@connection_options ||= { | ||
:builder => middleware, | ||
:ssl => {verify_mode: OpenSSL::SSL::VERIFY_NONE}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You stated that you had issues with SSL. I think it would be better to fix your issues or solve them otherwise. Changing the SSL options in the gem is somewhat risky and untransparent to the user of the gem. |
||
:headers => { | ||
:accept => default_media_type, | ||
:user_agent => user_agent, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,14 @@ def camelize_key(key) | |
end | ||
|
||
# copied from ActiveSupport | ||
# do not camelize exact "_c" | ||
def camelize(term) | ||
string = term.to_s | ||
string = string.sub(/^[a-z\d]*/) { $&.capitalize } | ||
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') | ||
if (string.downcase == '_c') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to me like some really special behaviour. Could you please elaborate why this is necessary and give some examples? |
||
string | ||
else | ||
string = string.sub(/^[a-z\d]*/) { $&.capitalize } | ||
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not add empty-lines between
end
s. This should be applied to all files of this pull request.