darujme_cz 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/darujme_cz/address.rb +5 -0
- data/lib/darujme_cz/donor.rb +1 -1
- data/lib/darujme_cz/pledge.rb +2 -0
- data/lib/darujme_cz/transaction.rb +19 -3
- data/lib/darujme_cz/version.rb +1 -1
- data/spec/fixtures/files/transactions.json +36 -0
- data/spec/models/donor_spec.rb +4 -0
- data/spec/models/pledge_spec.rb +8 -0
- data/spec/models/transaction_spec.rb +28 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f8ec4b523429634b11709ae103a9eb3e31ee7f60f7d3ca960f354c6f9cc7c88
|
4
|
+
data.tar.gz: c491df332c6065165837be87c44fa64acc13a4c70d31f834def26735ef7840a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65183b12b97591eb3da72459f9d86ea9dd0d9b7ddecf81a77609e8eeb73d087592bed8b33dc4f552c0939cf3a9fa6fa7721afcdd30f253bd7ac022ceacf287d6
|
7
|
+
data.tar.gz: a474254a286f346c83adfd51812d40d202df9efda4208cc5def3c2ab88e831edad18f492197689cac9ccad5b48f46f77f69e27a7579a8a87aa4d305eee8a2adf
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
|
-
|
9
|
+
## [0.1.2] - 2019-05-13
|
10
|
+
### Added
|
11
|
+
- delegators in transaction and pledge
|
12
|
+
- statuses methods in transaction
|
13
|
+
- alias postal=post code in address
|
14
|
+
### Fixed
|
15
|
+
- transaction without amount
|
10
16
|
## [0.1.0] - 2019-05-05
|
11
17
|
### Added
|
12
18
|
- Created darujme_cz prototype
|
data/lib/darujme_cz/address.rb
CHANGED
@@ -10,6 +10,11 @@ module DarujmeCz
|
|
10
10
|
"#{@source["street"]}\n#{@source["postCode"]} #{@source["city"]}\n#{@source["country"]}"
|
11
11
|
end
|
12
12
|
|
13
|
+
# alias
|
14
|
+
def postal_code
|
15
|
+
post_code
|
16
|
+
end
|
17
|
+
|
13
18
|
%w[street postCode city country].each do |m|
|
14
19
|
define_method m.underscore do
|
15
20
|
@source[m]
|
data/lib/darujme_cz/donor.rb
CHANGED
data/lib/darujme_cz/pledge.rb
CHANGED
@@ -2,6 +2,8 @@ module DarujmeCz
|
|
2
2
|
# @see https://www.darujme.cz/doc/api/v1/index.html#endpoint-get-organization-organizationid-pledges-by-filter
|
3
3
|
class Pledge < Base
|
4
4
|
|
5
|
+
delegate :name, :address, :city, :street, :post_code, :postal_code, :country, to: :donor
|
6
|
+
|
5
7
|
def self.endpoint
|
6
8
|
"pledges"
|
7
9
|
end
|
@@ -6,6 +6,8 @@ module DarujmeCz
|
|
6
6
|
"transactions"
|
7
7
|
end
|
8
8
|
|
9
|
+
delegate :name, :address, :city, :street, :postal_code, :country, to: :donor
|
10
|
+
|
9
11
|
# @param [Hash] attributes
|
10
12
|
def initialize(attributes)
|
11
13
|
@id = attributes["transactionId"]
|
@@ -13,21 +15,35 @@ module DarujmeCz
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def sent_amount
|
16
|
-
@sent_amount ||= ::Money.new(*@source["sentAmount"].values)
|
18
|
+
@sent_amount ||= ::Money.new(*@source["sentAmount"].values) if @source["sentAmount"]
|
17
19
|
end
|
18
20
|
|
19
21
|
def outgoing_amount
|
20
|
-
@outgoing_amount ||= ::Money.new(*@source["outgoingAmount"].values)
|
22
|
+
@outgoing_amount ||= ::Money.new(*@source["outgoingAmount"].values) if @source["outgoingAmount"]
|
21
23
|
end
|
22
24
|
|
23
25
|
def received_at
|
24
|
-
@source["receivedAt"]
|
26
|
+
@source["receivedAt"]&.to_time
|
25
27
|
end
|
26
28
|
|
27
29
|
def pledge
|
28
30
|
@pledge ||= Pledge.new(@source["pledge"])
|
29
31
|
end
|
30
32
|
|
33
|
+
def donor
|
34
|
+
@donor ||= pledge.donor
|
35
|
+
end
|
36
|
+
|
37
|
+
def status
|
38
|
+
@source["state"]
|
39
|
+
end
|
40
|
+
|
41
|
+
%w[pending pending_confirmation pending_update success success_money_on_account sent_to_organization failure error refund timeout canceled].each do |state|
|
42
|
+
define_method "#{state}?" do
|
43
|
+
status == state
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
31
47
|
%w[outgoingVs outgoingBankAccount].each do |m|
|
32
48
|
define_method m.underscore do
|
33
49
|
@source[m]
|
data/lib/darujme_cz/version.rb
CHANGED
@@ -41,6 +41,42 @@
|
|
41
41
|
"wantDonationCertificate": true,
|
42
42
|
"customFields": {}
|
43
43
|
}
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"transactionId": 5,
|
47
|
+
"state": "success",
|
48
|
+
"sentAmount": null,
|
49
|
+
"receivedAt": null,
|
50
|
+
"outgoingAmount": null,
|
51
|
+
"outgoingVs": null,
|
52
|
+
"outgoingBankAccount": null,
|
53
|
+
"pledge": {
|
54
|
+
"pledgeId": 1342845,
|
55
|
+
"organizationId": 2,
|
56
|
+
"projectId": 1201275,
|
57
|
+
"promotionId": null,
|
58
|
+
"paymentMethod": "gp_webpay_charge",
|
59
|
+
"isRecurrent": true,
|
60
|
+
"pledgedAmount": {
|
61
|
+
"cents": 25000,
|
62
|
+
"currency": "CZK"
|
63
|
+
},
|
64
|
+
"pledgedAt": "2018-11-13T09:48:45+01:00",
|
65
|
+
"donor": {
|
66
|
+
"firstName": "Jan",
|
67
|
+
"lastName": "Novák",
|
68
|
+
"email": "jan.novak@seznam.cz",
|
69
|
+
"address": {
|
70
|
+
"street": "Otakarova 34",
|
71
|
+
"city": "Praha",
|
72
|
+
"postCode": "120 00",
|
73
|
+
"country": "ČR"
|
74
|
+
},
|
75
|
+
"phone": "+420 123 456 789"
|
76
|
+
},
|
77
|
+
"wantDonationCertificate": true,
|
78
|
+
"customFields": {}
|
79
|
+
}
|
44
80
|
}
|
45
81
|
]
|
46
82
|
}
|
data/spec/models/donor_spec.rb
CHANGED
data/spec/models/pledge_spec.rb
CHANGED
@@ -17,16 +17,38 @@ RSpec.describe DarujmeCz::Transaction do
|
|
17
17
|
expect(subject.pledge).to be_a DarujmeCz::Pledge
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
describe "#sent_amount" do
|
21
|
+
context "with amount" do
|
22
|
+
it { expect(subject.sent_amount).to be_a Money }
|
23
|
+
end
|
24
|
+
context "without amount" do
|
25
|
+
subject { described_class.new json["transactions"][1] }
|
26
|
+
it { expect(subject.sent_amount).to be_nil }
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
|
30
|
+
describe "#outgoing_amount" do
|
31
|
+
context "with amount" do
|
32
|
+
it { expect(subject.outgoing_amount).to be_a Money }
|
33
|
+
end
|
34
|
+
context "without amount" do
|
35
|
+
subject { described_class.new json["transactions"][1] }
|
36
|
+
it { expect(subject.outgoing_amount).to be_nil }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#received_at" do
|
41
|
+
it { expect(subject.received_at).to be_a Time }
|
42
|
+
context "null" do
|
43
|
+
subject { described_class.new json["transactions"][1] }
|
44
|
+
it { expect(subject.received_at).to be_nil }
|
45
|
+
end
|
26
46
|
end
|
27
47
|
|
28
|
-
|
29
|
-
expect(subject.
|
48
|
+
describe "#status" do
|
49
|
+
it { expect(subject.status).to eq "refund" }
|
50
|
+
it { expect(subject.refund?).to eq true }
|
51
|
+
it { expect(subject.pending?).to eq false }
|
30
52
|
end
|
31
53
|
|
32
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darujme_cz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|