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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5f2fa8b2f474d09e5de8d2e3d6acda29a9ff19ef16005e83371dc25fc63d180
4
- data.tar.gz: ce46a5adb61b68031b2e892fdef2e1afc07a0ea150625bd74262911addf8343b
3
+ metadata.gz: 6f8ec4b523429634b11709ae103a9eb3e31ee7f60f7d3ca960f354c6f9cc7c88
4
+ data.tar.gz: c491df332c6065165837be87c44fa64acc13a4c70d31f834def26735ef7840a5
5
5
  SHA512:
6
- metadata.gz: e834776d865002c75cc8bb6bfeb92c5cba665d63f3d3b46a1f8e883e2cd7d5f105cbee2c1abe69dfdf74d446f3be15dd1731e1c06550a38da57ad18167f23639
7
- data.tar.gz: f15de592cd636575ba9d32f1f16058bd517ef5363b4dc2e427a32317142e1301687ff6b5e016f3bfef70c9a78b1c2a4d94cff08a78c2630e16fb25a74ca496d4
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
@@ -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]
@@ -1,7 +1,7 @@
1
1
  module DarujmeCz
2
2
  class Donor
3
3
 
4
- delegate :city, :street, :postal_code, :country, to: :address
4
+ delegate :city, :street, :post_code, :postal_code, :country, to: :address
5
5
  # @param [Hash] attributes
6
6
  def initialize(attributes)
7
7
  @source = attributes
@@ -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"].to_time
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]
@@ -1,3 +1,3 @@
1
1
  module DarujmeCz
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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
  }
@@ -26,4 +26,8 @@ RSpec.describe DarujmeCz::Donor do
26
26
  expect(subject.street).to eq "Otakarova 34"
27
27
  end
28
28
 
29
+ it "#postal_code" do
30
+ expect(subject.postal_code).to eq "120 00"
31
+ end
32
+
29
33
  end
@@ -82,4 +82,12 @@ RSpec.describe DarujmeCz::Pledge do
82
82
  end
83
83
  end
84
84
 
85
+ it "#name" do
86
+ expect(subject.name).to eq "Jan Novák"
87
+ end
88
+
89
+ it "#city" do
90
+ expect(subject.city).to eq "Praha"
91
+ end
92
+
85
93
  end
@@ -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
- it "#sent_amount" do
21
- expect(subject.sent_amount).to be_a Money
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
- it "#outgoing_amount" do
25
- expect(subject.outgoing_amount).to be_a Money
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
- it "#received_at" do
29
- expect(subject.received_at).to be_a Time
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.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-05-12 00:00:00.000000000 Z
11
+ date: 2019-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport