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

Api update #32

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
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
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions lib/pactas_itero/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
require 'pactas_itero/api/orders'
require 'pactas_itero/api/invoices'
require "pactas_itero/api/payment_transactions"
require "pactas_itero/api/plans"
require "pactas_itero/api/coupons"
require "pactas_itero/api/discounts"
require "pactas_itero/api/components"

module PactasItero
module Api
Expand All @@ -16,5 +20,9 @@ module Api
include PactasItero::Api::Orders
include PactasItero::Api::Invoices
include PactasItero::Api::PaymentTransactions
include PactasItero::Api::Plans
include PactasItero::Api::Coupons
include PactasItero::Api::Discounts
include PactasItero::Api::Components
end
end
26 changes: 26 additions & 0 deletions lib/pactas_itero/api/components.rb
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

Copy link
Contributor

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 ends. This should be applied to all files of this pull request.

end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

22 changes: 22 additions & 0 deletions lib/pactas_itero/api/contracts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Contributor

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 before ends.

end

end
end
end
31 changes: 31 additions & 0 deletions lib/pactas_itero/api/coupons.rb
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
5 changes: 5 additions & 0 deletions lib/pactas_itero/api/customers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def update_customer(customer_id, options = {})
options = options.camelize_keys
patch "api/v1/customers/#{customer_id}", options
end

def search_customer(search_string, options = {})
options = options.camelize_keys
get "api/v1/customers/?search=#{search_string}", options
end
end
end
end
26 changes: 26 additions & 0 deletions lib/pactas_itero/api/discounts.rb
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
50 changes: 50 additions & 0 deletions lib/pactas_itero/api/plans.rb
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
1 change: 1 addition & 0 deletions lib/pactas_itero/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def request(method, path, params = {})
def connection_options
@connection_options ||= {
:builder => middleware,
:ssl => {verify_mode: OpenSSL::SSL::VERIFY_NONE},
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand Down
9 changes: 7 additions & 2 deletions lib/pactas_itero/ext/hash/camelize_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Contributor

Choose a reason for hiding this comment

The 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