pactas_itero 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +39 -0
- data/.hound.yml +14 -0
- data/.rubocop.yml +2 -0
- data/.ruby-style.yml +268 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +46 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +16 -0
- data/lib/pactas_itero/api/contracts.rb +30 -0
- data/lib/pactas_itero/api/customers.rb +20 -0
- data/lib/pactas_itero/api/invoices.rb +25 -0
- data/lib/pactas_itero/api/oauth.rb +12 -0
- data/lib/pactas_itero/api/orders.rb +19 -0
- data/lib/pactas_itero/api/rated_items.rb +16 -0
- data/lib/pactas_itero/api.rb +18 -0
- data/lib/pactas_itero/client.rb +108 -0
- data/lib/pactas_itero/configurable.rb +59 -0
- data/lib/pactas_itero/default.rb +77 -0
- data/lib/pactas_itero/error.rb +217 -0
- data/lib/pactas_itero/ext/hash/camelize_keys.rb +32 -0
- data/lib/pactas_itero/response/raise_error.rb +21 -0
- data/lib/pactas_itero/version.rb +3 -0
- data/lib/pactas_itero.rb +31 -0
- data/pactas_itero.gemspec +32 -0
- data/spec/fixtures/bearer_token.json +5 -0
- data/spec/fixtures/commit_order_response.json +50 -0
- data/spec/fixtures/contract.json +46 -0
- data/spec/fixtures/contract_cancellation_preview_response.json +73 -0
- data/spec/fixtures/contracts.json +48 -0
- data/spec/fixtures/create_order_response.json +17 -0
- data/spec/fixtures/create_rated_item.json +8 -0
- data/spec/fixtures/customer.json +23 -0
- data/spec/fixtures/customers.json +40 -0
- data/spec/fixtures/invoice.json +22 -0
- data/spec/fixtures/invoices.json +46 -0
- data/spec/fixtures/order.json +15 -0
- data/spec/pactas_itero/api/contracts_spec.rb +118 -0
- data/spec/pactas_itero/api/customers_spec.rb +188 -0
- data/spec/pactas_itero/api/invoices_spec.rb +87 -0
- data/spec/pactas_itero/api/oauth_spec.rb +40 -0
- data/spec/pactas_itero/api/orders_spec.rb +102 -0
- data/spec/pactas_itero/api/rated_items_spec.rb +74 -0
- data/spec/pactas_itero/client_spec.rb +316 -0
- data/spec/pactas_itero_spec.rb +32 -0
- data/spec/spec_helper.rb +100 -0
- metadata +218 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
{
|
2
|
+
"ContractAfter": {
|
3
|
+
"Balance": 0,
|
4
|
+
"Currency": "EUR",
|
5
|
+
"CurrentPhase": {
|
6
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
7
|
+
"StartDate": "2015-10-15T09:02:21.2750000Z",
|
8
|
+
"Type": "Trial"
|
9
|
+
},
|
10
|
+
"CustomFields": {},
|
11
|
+
"CustomerId": "561f6b9d1d8dd21334f22cb0",
|
12
|
+
"CustomerName": "Example Corp.",
|
13
|
+
"EndDate": "2015-12-15T10:02:21.2750000Z",
|
14
|
+
"EscalationSuspended": false,
|
15
|
+
"Id": "561f6b9d1d8dd21334f22cb2",
|
16
|
+
"LifecycleStatus": "InTrial",
|
17
|
+
"NextBillingDate": "2015-11-15T10:02:21.2750000Z",
|
18
|
+
"PaymentBearer": {
|
19
|
+
"CardType": "visa",
|
20
|
+
"Country": "DE",
|
21
|
+
"ExpiryMonth": 12,
|
22
|
+
"ExpiryYear": 2017,
|
23
|
+
"Holder": "Marcellus Wallace",
|
24
|
+
"Last4": "1111",
|
25
|
+
"Type": "CreditCard"
|
26
|
+
},
|
27
|
+
"PaymentProvider": "Paymill",
|
28
|
+
"PaymentProviderSupportRefunds": true,
|
29
|
+
"Phases": [
|
30
|
+
{
|
31
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
32
|
+
"StartDate": "2015-10-15T09:02:21.2750000Z",
|
33
|
+
"Type": "Trial"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
37
|
+
"PlanVariantId": "53567b431d8dd00df056564f",
|
38
|
+
"StartDate": "2015-11-15T10:02:21.2750000Z",
|
39
|
+
"Type": "Normal"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"StartDate": "2015-12-15T10:02:21.2750000Z",
|
43
|
+
"Type": "Inactive"
|
44
|
+
}
|
45
|
+
],
|
46
|
+
"PlanGroupId": "53567a731d8dd00df056564a",
|
47
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
48
|
+
"RecurringPaymentsPaused": false,
|
49
|
+
"ReferenceCode": "RFDT-ZHXM",
|
50
|
+
"StartDate": "2015-10-15T09:02:21.2750000Z"
|
51
|
+
},
|
52
|
+
"EndDate": "2015-12-15T10:02:21.2750000Z",
|
53
|
+
"Invoice": {
|
54
|
+
"ContractId": "561f6b9d1d8dd21334f22cb2",
|
55
|
+
"CustomerId": "561f6b9d1d8dd21334f22cb0",
|
56
|
+
"ItemList": [],
|
57
|
+
"RecipientAddress": {
|
58
|
+
"City": "Example City",
|
59
|
+
"Country": "DE",
|
60
|
+
"HouseNumber": "42",
|
61
|
+
"PostalCode": "12345",
|
62
|
+
"Street": "Example Street"
|
63
|
+
},
|
64
|
+
"RecipientName": "Example Corp.",
|
65
|
+
"RecipientSubName": "Max Mustermann",
|
66
|
+
"ReverseCharge": false,
|
67
|
+
"TotalGross": 0,
|
68
|
+
"TotalNet": 0,
|
69
|
+
"TotalVat": 0,
|
70
|
+
"VatDescriptors": []
|
71
|
+
},
|
72
|
+
"NextPossibleCancellationDate": "2015-11-15T10:02:21.2750000Z"
|
73
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"Balance": 0,
|
4
|
+
"BilledUntil": "2014-05-23T13:12:47.0760000Z",
|
5
|
+
"Currency": "EUR",
|
6
|
+
"CurrentPhase": {
|
7
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
8
|
+
"PlanVariantId": "53567b431d8dd00df056564f",
|
9
|
+
"StartDate": "2014-04-23T13:12:47.0760000Z",
|
10
|
+
"Type": "Normal"
|
11
|
+
},
|
12
|
+
"CustomerId": "5357bc4f1d8dd00fa0db6c31",
|
13
|
+
"CustomerName": "Max Mustermann",
|
14
|
+
"EndDate": "2014-05-23T13:12:47.0760000Z",
|
15
|
+
"EscalationSuspended": false,
|
16
|
+
"Id": "5357bc4f1d8dd00fa0db6c32",
|
17
|
+
"LastBillingDate": "2014-04-23T13:12:47.0760000Z",
|
18
|
+
"LifecycleStatus": "Active",
|
19
|
+
"NextBillingDate": "2014-05-23T13:12:47.0760000Z",
|
20
|
+
"PaymentBearer": {
|
21
|
+
"CardType": "visa",
|
22
|
+
"Country": "DE",
|
23
|
+
"ExpiryMonth": 12,
|
24
|
+
"ExpiryYear": 2017,
|
25
|
+
"Holder": "Marcellus Wallace",
|
26
|
+
"Last4": "1111",
|
27
|
+
"Type": "CreditCard"
|
28
|
+
},
|
29
|
+
"PaymentProvider": "Paymill",
|
30
|
+
"Phases": [
|
31
|
+
{
|
32
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
33
|
+
"PlanVariantId": "53567b431d8dd00df056564f",
|
34
|
+
"StartDate": "2014-04-23T13:12:47.0760000Z",
|
35
|
+
"Type": "Normal"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"StartDate": "2014-05-23T13:12:47.0760000Z",
|
39
|
+
"Type": "Inactive"
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"PlanGroupId": "53567a731d8dd00df056564a",
|
43
|
+
"PlanId": "53567a9e1d8dd00df056564d",
|
44
|
+
"PlanVariantId": "53567b431d8dd00df056564f",
|
45
|
+
"RecurringPaymentsPaused": false,
|
46
|
+
"StartDate": "2014-04-23T13:12:47.0760000Z"
|
47
|
+
}
|
48
|
+
]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"Id": "537dfcab9e400760b4cd6347",
|
3
|
+
"AllowWithoutPaymentData": false,
|
4
|
+
"ComponentSubscriptions": [{
|
5
|
+
"PreventModification": false,
|
6
|
+
"VatPercentage": 0,
|
7
|
+
"TotalNet": 0,
|
8
|
+
"TotalVat": 0,
|
9
|
+
"ComponentId": "534bbdcc9e400722602f5a21",
|
10
|
+
"Quantity": 1
|
11
|
+
}],
|
12
|
+
"Total": -0.99,
|
13
|
+
"TotalVat": -0.19,
|
14
|
+
"IsTrial": false,
|
15
|
+
"CustomerId": "5370e5ab9e40071fd01e01df",
|
16
|
+
"ContractId": "5370e5ab9e40071fd01e01e0"
|
17
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"Address": {
|
3
|
+
"City": "Example City",
|
4
|
+
"Country": "DE",
|
5
|
+
"HouseNumber": "42",
|
6
|
+
"PostalCode": "12345",
|
7
|
+
"Street": "Example Street"
|
8
|
+
},
|
9
|
+
"CompanyName": "Example Company",
|
10
|
+
"CreatedAt": "2014-05-12T14:22:24.0000000Z",
|
11
|
+
"CustomerName": "Example Company",
|
12
|
+
"CustomerType": "Consumer",
|
13
|
+
"DefaultBearerMedium": "Email",
|
14
|
+
"EmailAddress": "jane.doe@example.com",
|
15
|
+
"ExternalCustomerId": "",
|
16
|
+
"FirstName": "Jane",
|
17
|
+
"Id": "5370d9201d8dd006288221b0",
|
18
|
+
"Language": "de-DE",
|
19
|
+
"LastName": "Doe",
|
20
|
+
"Locale": "de-DE",
|
21
|
+
"VatId": "DE123456710",
|
22
|
+
"ExternalCustomerId": "1234"
|
23
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"Address": {
|
4
|
+
"City": "Example City",
|
5
|
+
"Country": "DE",
|
6
|
+
"HouseNumber": "42",
|
7
|
+
"PostalCode": "12345",
|
8
|
+
"Street": "Example Street"
|
9
|
+
},
|
10
|
+
"CompanyName": "Example Company",
|
11
|
+
"CreatedAt": "2014-05-12T14:22:24.0000000Z",
|
12
|
+
"CustomerName": "Example Company",
|
13
|
+
"CustomerType": "Consumer",
|
14
|
+
"DefaultBearerMedium": "Email",
|
15
|
+
"EmailAddress": "jane.doe@example.com",
|
16
|
+
"ExternalCustomerId": "",
|
17
|
+
"FirstName": "Jane",
|
18
|
+
"Id": "5370d9201d8dd006288221b0",
|
19
|
+
"Language": "de-DE",
|
20
|
+
"LastName": "Doe",
|
21
|
+
"Locale": "de-DE",
|
22
|
+
"VatId": "DE123456710"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"Address": {},
|
26
|
+
"CompanyName": "Test Inc.",
|
27
|
+
"CreatedAt": "2014-05-14T14:21:20.0000000Z",
|
28
|
+
"CustomerName": "Test Inc.",
|
29
|
+
"CustomerType": "Consumer",
|
30
|
+
"DefaultBearerMedium": "Email",
|
31
|
+
"EmailAddress": "john.test@example.com",
|
32
|
+
"ExternalCustomerId": "",
|
33
|
+
"FirstName": "John",
|
34
|
+
"Id": "5370d8e01d8dd00628822197",
|
35
|
+
"Language": "de-DE",
|
36
|
+
"LastName": "Test",
|
37
|
+
"Locale": "de-DE",
|
38
|
+
"VatId": "DE123456789"
|
39
|
+
}
|
40
|
+
]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"Id": "54b67d9e995ec90bc8f37718",
|
3
|
+
"InvoiceNumber": "SAN//2012//07--2435",
|
4
|
+
"CustomerId": "54b67d9e675ec90bc8f3770c",
|
5
|
+
"SentAt": "2012-07-03T23:02:22Z",
|
6
|
+
"DueDate": "2012-08-02",
|
7
|
+
"RecipientName": "OldTek GmbH",
|
8
|
+
"RecipientSubName": "Hermann Anton Müller",
|
9
|
+
"RecipientAddress": {
|
10
|
+
"AddressLine1": "c/o Andreas Meister",
|
11
|
+
"Street": "Sternstraße",
|
12
|
+
"HouseNumber": "43",
|
13
|
+
"PostalCode": "80538",
|
14
|
+
"City": "München",
|
15
|
+
"Country": "DE"
|
16
|
+
},
|
17
|
+
"Currency": "EUR",
|
18
|
+
"TotalNet": "211.60",
|
19
|
+
"TotalVat": "40.20",
|
20
|
+
"TotalGross": "251.80",
|
21
|
+
"IsInvoice": "False"
|
22
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"Id": "54b67d9e675ec90bc8f37718",
|
4
|
+
"InvoiceNumber": "SAN//2012//07--2434",
|
5
|
+
"CustomerId": "54b67d9e675ec90bc8f3770c",
|
6
|
+
"SentAt": "2012-07-03T23:02:22Z",
|
7
|
+
"DueDate": "2012-08-02",
|
8
|
+
"RecipientName": "OldTek GmbH",
|
9
|
+
"RecipientSubName": "Hermann Anton Müller",
|
10
|
+
"RecipientAddress": {
|
11
|
+
"AddressLine1": "c/o Andreas Meister",
|
12
|
+
"Street": "Sternstraße",
|
13
|
+
"HouseNumber": "43",
|
14
|
+
"PostalCode": "80538",
|
15
|
+
"City": "München",
|
16
|
+
"Country": "DE"
|
17
|
+
},
|
18
|
+
"Currency": "EUR",
|
19
|
+
"TotalNet": "211.60",
|
20
|
+
"TotalVat": "40.20",
|
21
|
+
"TotalGross": "251.80",
|
22
|
+
"IsInvoice": "False"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"Id": "54b67d9e995ec90bc8f37718",
|
26
|
+
"InvoiceNumber": "SAN//2012//07--2435",
|
27
|
+
"CustomerId": "54b67d9e675ec90bc8f3770c",
|
28
|
+
"SentAt": "2012-07-03T23:02:22Z",
|
29
|
+
"DueDate": "2012-08-02",
|
30
|
+
"RecipientName": "OldTek GmbH",
|
31
|
+
"RecipientSubName": "Hermann Anton Müller",
|
32
|
+
"RecipientAddress": {
|
33
|
+
"AddressLine1": "c/o Andreas Meister",
|
34
|
+
"Street": "Sternstraße",
|
35
|
+
"HouseNumber": "43",
|
36
|
+
"PostalCode": "80538",
|
37
|
+
"City": "München",
|
38
|
+
"Country": "DE"
|
39
|
+
},
|
40
|
+
"Currency": "EUR",
|
41
|
+
"TotalNet": "211.60",
|
42
|
+
"TotalVat": "40.20",
|
43
|
+
"TotalGross": "251.80",
|
44
|
+
"IsInvoice": "False"
|
45
|
+
}
|
46
|
+
]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"Id": "56af22c51d8dd207684db9b5",
|
3
|
+
"PlanVariantId": "5357b8f11d8dd00fa0db6c1b",
|
4
|
+
"AllowWithoutPaymentData": false,
|
5
|
+
"ComponentSubscriptions": [],
|
6
|
+
"DiscountSubscriptions": [],
|
7
|
+
"Currency": "EUR",
|
8
|
+
"Total": 24.9,
|
9
|
+
"TotalVat": 4.73,
|
10
|
+
"TotalGross": 29.63,
|
11
|
+
"IsTrial": false,
|
12
|
+
"Status": "InProgress",
|
13
|
+
"CustomerId": "56af224c1d8dd207684db935",
|
14
|
+
"ContractId": "56af22c51d8dd207684db9b4"
|
15
|
+
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PactasItero::Api::Customers do
|
4
|
+
describe '.customer_contracts' do
|
5
|
+
it 'requests the correct resource' do
|
6
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
7
|
+
request = stub_get('/api/v1/customers/535783241d8dd00fa0db6b2a/contracts').
|
8
|
+
to_return(
|
9
|
+
body: fixture('contracts.json'),
|
10
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
11
|
+
)
|
12
|
+
|
13
|
+
client.customer_contracts('535783241d8dd00fa0db6b2a')
|
14
|
+
|
15
|
+
expect(request).to have_been_made
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns an array of contracts' do
|
19
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
20
|
+
request = stub_get('/api/v1/customers/535783241d8dd00fa0db6b2a/contracts').
|
21
|
+
to_return(
|
22
|
+
body: fixture('contracts.json'),
|
23
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
24
|
+
)
|
25
|
+
|
26
|
+
contracts = client.customer_contracts('535783241d8dd00fa0db6b2a')
|
27
|
+
|
28
|
+
expect(contracts).to be_a Array
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.contracts' do
|
33
|
+
it 'requests the correct resource' do
|
34
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
35
|
+
request = stub_get('/api/v1/contracts').
|
36
|
+
to_return(
|
37
|
+
body: fixture('contracts.json'),
|
38
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
39
|
+
)
|
40
|
+
|
41
|
+
client.contracts
|
42
|
+
|
43
|
+
expect(request).to have_been_made
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns an array of contracts' do
|
47
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
48
|
+
request = stub_get('/api/v1/contracts').
|
49
|
+
to_return(
|
50
|
+
body: fixture('contracts.json'),
|
51
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
52
|
+
)
|
53
|
+
|
54
|
+
contracts = client.contracts
|
55
|
+
|
56
|
+
expect(contracts).to be_a Array
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".contract_cancellation_preview" do
|
61
|
+
it "requests the correct resource" do
|
62
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
63
|
+
request = stub_get("/api/v1/contracts/some_contract_id/cancellationPreview").to_return(
|
64
|
+
body: fixture("contract_cancellation_preview_response.json"),
|
65
|
+
headers: { content_type: "application/json; charset=utf-8" }
|
66
|
+
)
|
67
|
+
|
68
|
+
client.contract_cancellation_preview("some_contract_id")
|
69
|
+
|
70
|
+
expect(request).to have_been_made
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns the next possible cancellation date' do
|
74
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
75
|
+
request = stub_get("/api/v1/contracts/some_contract_id/cancellationPreview").to_return(
|
76
|
+
body: fixture("contract_cancellation_preview_response.json"),
|
77
|
+
headers: { content_type: "application/json; charset=utf-8" }
|
78
|
+
)
|
79
|
+
|
80
|
+
contract_cancellation_preview = client.contract_cancellation_preview("some_contract_id")
|
81
|
+
|
82
|
+
expect(
|
83
|
+
contract_cancellation_preview.next_possible_cancellation_date
|
84
|
+
).to eq "2015-11-15T10:02:21.2750000Z"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.update_contract' do
|
89
|
+
it 'requests the correct resource' do
|
90
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
91
|
+
request = stub_patch('/api/v1/contracts/contract-id').
|
92
|
+
with(body: { EndDate: '2014-05-23T13:12:47.0760000Z' }.to_json).
|
93
|
+
to_return(
|
94
|
+
body: fixture('contract.json'),
|
95
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
96
|
+
)
|
97
|
+
|
98
|
+
client.update_contract('contract-id', { end_date: '2014-05-23T13:12:47.0760000Z' })
|
99
|
+
|
100
|
+
expect(request).to have_been_made
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.contract' do
|
105
|
+
it 'requests the correct resource' do
|
106
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
107
|
+
request = stub_get('/api/v1/contracts/5357bc4f1d8dd00fa0db6c31').
|
108
|
+
to_return(
|
109
|
+
body: fixture('contract.json'),
|
110
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
111
|
+
)
|
112
|
+
|
113
|
+
client.contract('5357bc4f1d8dd00fa0db6c31')
|
114
|
+
|
115
|
+
expect(request).to have_been_made
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PactasItero::Api::Customers do
|
4
|
+
describe ".create_customer" do
|
5
|
+
it "requests the correct resource" do
|
6
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
7
|
+
post_data = {
|
8
|
+
"Address" => {
|
9
|
+
"City" => "Example City",
|
10
|
+
"Country" => "DE",
|
11
|
+
"HouseNumber" => "42",
|
12
|
+
"PostalCode" => "12345",
|
13
|
+
"Street" => "Example Street"
|
14
|
+
},
|
15
|
+
"CompanyName" => "Example Company",
|
16
|
+
"DefaultBearerMedium" => "Email",
|
17
|
+
"EmailAddress" => "jane.doe@example.com",
|
18
|
+
"ExternalCustomerId" => "1234",
|
19
|
+
"FirstName" => "Jane",
|
20
|
+
"Language" => "de-DE",
|
21
|
+
"LastName" => "Doe",
|
22
|
+
"Locale" => "de-DE",
|
23
|
+
"VatId" => "DE123456710"
|
24
|
+
}.to_json
|
25
|
+
request = stub_post('/api/v1/customers').with(body: post_data).to_return(
|
26
|
+
body: fixture('customer.json'),
|
27
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
28
|
+
)
|
29
|
+
|
30
|
+
client.create_customer(
|
31
|
+
address: {
|
32
|
+
city: "Example City",
|
33
|
+
country: "DE",
|
34
|
+
house_number: "42",
|
35
|
+
postal_code: "12345",
|
36
|
+
street: "Example Street"
|
37
|
+
},
|
38
|
+
company_name: "Example Company",
|
39
|
+
default_bearer_medium: "Email",
|
40
|
+
email_address: "jane.doe@example.com",
|
41
|
+
external_customer_id: "1234",
|
42
|
+
first_name: "Jane",
|
43
|
+
language: "de-DE",
|
44
|
+
last_name: "Doe",
|
45
|
+
locale: "de-DE",
|
46
|
+
vat_id: "DE123456710"
|
47
|
+
)
|
48
|
+
|
49
|
+
expect(request).to have_been_made
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns the created customer' do
|
53
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
54
|
+
post_data = {
|
55
|
+
"Address" => {
|
56
|
+
"City" => "Example City",
|
57
|
+
"Country" => "DE",
|
58
|
+
"HouseNumber" => "42",
|
59
|
+
"PostalCode" => "12345",
|
60
|
+
"Street" => "Example Street"
|
61
|
+
},
|
62
|
+
"CompanyName" => "Example Company",
|
63
|
+
"DefaultBearerMedium" => "Email",
|
64
|
+
"EmailAddress" => "jane.doe@example.com",
|
65
|
+
"ExternalCustomerId" => "1234",
|
66
|
+
"FirstName" => "Jane",
|
67
|
+
"Language" => "de-DE",
|
68
|
+
"LastName" => "Doe",
|
69
|
+
"Locale" => "de-DE",
|
70
|
+
"VatId" => "DE123456710"
|
71
|
+
}.to_json
|
72
|
+
request = stub_post('/api/v1/customers').with(body: post_data).to_return(
|
73
|
+
body: fixture('customer.json'),
|
74
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
75
|
+
)
|
76
|
+
|
77
|
+
customer = client.create_customer(
|
78
|
+
address: {
|
79
|
+
city: "Example City",
|
80
|
+
country: "DE",
|
81
|
+
house_number: "42",
|
82
|
+
postal_code: "12345",
|
83
|
+
street: "Example Street"
|
84
|
+
},
|
85
|
+
company_name: "Example Company",
|
86
|
+
default_bearer_medium: "Email",
|
87
|
+
email_address: "jane.doe@example.com",
|
88
|
+
external_customer_id: "1234",
|
89
|
+
first_name: "Jane",
|
90
|
+
language: "de-DE",
|
91
|
+
last_name: "Doe",
|
92
|
+
locale: "de-DE",
|
93
|
+
vat_id: "DE123456710"
|
94
|
+
)
|
95
|
+
|
96
|
+
address = customer.address
|
97
|
+
expect(address.city).to eq "Example City"
|
98
|
+
expect(address.country).to eq "DE"
|
99
|
+
expect(address.house_number).to eq "42"
|
100
|
+
expect(address.postal_code).to eq "12345"
|
101
|
+
expect(address.street).to eq "Example Street"
|
102
|
+
|
103
|
+
expect(customer.company_name).to eq "Example Company"
|
104
|
+
expect(customer.default_bearer_medium).to eq"Email"
|
105
|
+
expect(customer.email_address).to eq "jane.doe@example.com"
|
106
|
+
expect(customer.external_customer_id).to eq "1234"
|
107
|
+
expect(customer.first_name).to eq "Jane"
|
108
|
+
expect(customer.language).to eq "de-DE"
|
109
|
+
expect(customer.last_name).to eq "Doe"
|
110
|
+
expect(customer.locale).to eq "de-DE"
|
111
|
+
expect(customer.vat_id).to eq "DE123456710"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe ".customers" do
|
116
|
+
it "requests the correct resource" do
|
117
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
118
|
+
request = stub_get('/api/v1/customers').
|
119
|
+
to_return(
|
120
|
+
body: fixture('customers.json'),
|
121
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
122
|
+
)
|
123
|
+
|
124
|
+
client.customers
|
125
|
+
|
126
|
+
expect(request).to have_been_made
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'returns an array of customers' do
|
130
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
131
|
+
request = stub_get('/api/v1/customers').
|
132
|
+
to_return(
|
133
|
+
body: fixture('customers.json'),
|
134
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
135
|
+
)
|
136
|
+
|
137
|
+
customers = client.customers
|
138
|
+
|
139
|
+
expect(customers).to be_a Array
|
140
|
+
customer = customers.first
|
141
|
+
|
142
|
+
expect(customer.company_name).to eq 'Example Company'
|
143
|
+
expect(customer.created_at).to eq '2014-05-12T14:22:24.0000000Z'
|
144
|
+
expect(customer.customer_name).to eq 'Example Company'
|
145
|
+
expect(customer.customer_type).to eq 'Consumer'
|
146
|
+
expect(customer.default_bearer_medium).to eq 'Email'
|
147
|
+
expect(customer.email_address).to eq 'jane.doe@example.com'
|
148
|
+
expect(customer.external_customer_id).to eq ''
|
149
|
+
expect(customer.first_name).to eq 'Jane'
|
150
|
+
expect(customer.id).to eq '5370d9201d8dd006288221b0'
|
151
|
+
expect(customer.language).to eq 'de-DE'
|
152
|
+
expect(customer.last_name ).to eq 'Doe'
|
153
|
+
expect(customer.locale).to eq 'de-DE'
|
154
|
+
expect(customer.vat_id).to eq 'DE123456710'
|
155
|
+
expect(customer.address.city).to eq 'Example City'
|
156
|
+
expect(customer.address.country).to eq 'DE'
|
157
|
+
expect(customer.address.house_number).to eq '42'
|
158
|
+
expect(customer.address.postal_code).to eq '12345'
|
159
|
+
expect(customer.address.street).to eq 'Example Street'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '.update_customer' do
|
164
|
+
it 'requests the correct resource' do
|
165
|
+
client = PactasItero::Client.new(bearer_token: 'bt')
|
166
|
+
request = stub_patch('/api/v1/customers/customer-id').
|
167
|
+
with(
|
168
|
+
body: {
|
169
|
+
CompanyName: 'example & sons',
|
170
|
+
VatId: 'DE555',
|
171
|
+
Address: { Street: 'abc street' }
|
172
|
+
}.to_json
|
173
|
+
).
|
174
|
+
to_return(
|
175
|
+
body: fixture('customer.json'),
|
176
|
+
headers: { content_type: 'application/json; charset=utf-8'}
|
177
|
+
)
|
178
|
+
|
179
|
+
client.update_customer('customer-id', {
|
180
|
+
company_name: 'example & sons',
|
181
|
+
vat_id: 'DE555',
|
182
|
+
address: { street: 'abc street' }
|
183
|
+
})
|
184
|
+
|
185
|
+
expect(request).to have_been_made
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|