Skip to content

Commit

Permalink
Merge pull request #28 from AdGoji/feature/26-embeds
Browse files Browse the repository at this point in the history
Implement payment refunds and chargebacks functions
  • Loading branch information
roman-rudakov authored Feb 28, 2024
2 parents 469871f + 725d2c1 commit ac83798
Show file tree
Hide file tree
Showing 20 changed files with 693 additions and 50 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@ name: CI
on:
push:
branches:
- '**'
- 'main'
pull_request:
types:
- 'ready_for_review'
- 'synchronize'
- 'opened'
- 'reopened'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test-clj:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
env:
MOLLIE_API_KEY: ${{ secrets.MOLLIE_API_KEY }}
MOLLIE_PARTNER_ID: ${{ secrets.MOLLIE_PARTNER_ID }}
MOLLIE_PROFILE_ID: ${{ secrets.MOLLIE_PROFILE_ID }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Prepare java
uses: actions/setup-java@v3
uses: actions/setup-java@v4.1.0
with:
distribution: 'temurin'
java-version: '20'
Expand All @@ -28,7 +39,7 @@ jobs:
bb: 'latest'

- name: Cache clojure dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.m2/repository
Expand All @@ -48,14 +59,14 @@ jobs:
clj-kondo: 'latest'
bb: 'latest'

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- run: bb lint

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: DeLaGuardo/setup-clojure@master
with:
Expand Down
11 changes: 10 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] ##

## [0.4.0] - 2024-02-28 ##

### Added ###

- New option for getting payment by ID: `embed` ([#26](https://github.com/AdGoji/mollie/issues/26)).
- New API: payment refunds ([#20](https://github.com/AdGoji/mollie/issues/20)).
- New API: payment chargebacks ([#27](https://github.com/AdGoji/mollie/issues/27)).

## [0.3.6] - 2023-11-16 ##

### Fixed ###
Expand Down Expand Up @@ -86,7 +94,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Mandates management ([#1](https://github.com/AdGoji/mollie/issues/1)).
- Subscriptions management ([#1](https://github.com/AdGoji/mollie/issues/1)).

[unreleased]: https://github.com/AdGoji/mollie/compare/0.3.6..HEAD
[unreleased]: https://github.com/AdGoji/mollie/compare/0.4.0..HEAD
[0.4.0]: https://github.com/AdGoji/mollie/compare/0.3.6..0.4.0
[0.3.6]: https://github.com/AdGoji/mollie/compare/0.3.5..0.3.6
[0.3.5]: https://github.com/AdGoji/mollie/compare/0.3.4..0.3.5
[0.3.4]: https://github.com/AdGoji/mollie/compare/0.3.3..0.3.4
Expand Down
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[deps-deploy.deps-deploy :as dd]))

(def lib 'com.adgoji/mollie)
(def version "0.3.6")
(def version "0.4.0")
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{:paths ["src" "spec"]

:deps {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/data.json {:mvn/version "2.4.0"}
org.clojure/spec.alpha {:mvn/version "0.3.218"}
org.clojure/data.json {:mvn/version "2.5.0"}
org.clojure/spec.alpha {:mvn/version "0.4.233"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
hato/hato {:mvn/version "0.9.0"}
com.cognitect/anomalies {:mvn/version "0.1.12"}}
Expand Down
4 changes: 3 additions & 1 deletion spec/com/adgoji/common.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns com.adgoji.common
(:require
[clojure.spec.alpha :as s]))
[clojure.spec.alpha :as s]
[com.adgoji.mollie.amount :as amount]))

;;; Constants

Expand Down Expand Up @@ -42,3 +43,4 @@
:sofort})
(s/def ::metadata (s/nilable map?))
(s/def ::profile-id string?) ;TODO: Use real profile ID when implemented
(s/def ::amount (s/keys :req [::amount/value ::amount/currency]))
78 changes: 77 additions & 1 deletion spec/com/adgoji/mollie.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
[com.adgoji.mollie.creditcard :as creditcard]
[com.adgoji.mollie.paypal :as paypal]
[com.adgoji.common :as common]
[com.adgoji.mollie.ideal :as ideal]))
[com.adgoji.mollie.ideal :as ideal]
[com.adgoji.mollie.refund :as refund]
[com.adgoji.mollie.chargeback :as chargeback]))

;;; Customer

Expand Down Expand Up @@ -41,6 +43,69 @@
::pagination/previous
::pagination/self]))

;;; Refunds

(s/def ::refund
(common/only-keys :req [::refund/resource
::refund/id
::refund/amount
::refund/description
::refund/status
::refund/payment-id
::refund/created-at
::link/self
::link/payment]
:opt [::refund/settlement-id
::refund/settlement-amount
::refund/lines
::refund/order-id
::refund/metadata
::link/documentation
::link/settlement
::link/order]))

(s/def ::refunds
(s/coll-of ::refund :distinct true :into []))

(s/def ::refunds-list
(common/only-keys :req [::refunds
::pagination/count]
:opt [::pagination/next
::pagination/previous
::pagination/self]))

;;; Chargebacks

(s/def ::chargeback
(common/only-keys :req [::chargeback/resource
::chargeback/id
::chargeback/amount
::chargeback/settlement-amount
::chargeback/created-at
::chargeback/payment-id
::link/self
::link/payment]
:opt [::chargeback/reason
::chargeback/reversed-at
::link/settlement
::link/documentation]))

(s/def ::chargebacks
(s/coll-of ::chargeback :distinct true :into []))

(s/def ::chargebacks-list
(common/only-keys :req [::chargebacks
::pagination/count]
:opt [::pagination/next
::pagination/previous
::pagination/self]))

;;; Embedded

(s/def ::embedded
(common/only-keys :opt [::refunds
::chargebacks]))

;;; Payment

(defmulti payment-spec ::payment/method)
Expand Down Expand Up @@ -90,6 +155,7 @@
::payment/customer-id
::payment/mandate-id
::payment/subscription-id
::embedded
::directdebit/signature-date
::directdebit/bank-reason-code
::directdebit/bank-reason
Expand Down Expand Up @@ -148,6 +214,7 @@
::payment/customer-id
::payment/mandate-id
::payment/subscription-id
::embedded
::creditcard/card-holder
::creditcard/card-number
::creditcard/card-fingerprint
Expand Down Expand Up @@ -211,6 +278,7 @@
::payment/customer-id
::payment/mandate-id
::payment/subscription-id
::embedded
::ideal/consumer-name
::ideal/consumer-account
::ideal/consumer-bic
Expand Down Expand Up @@ -265,6 +333,7 @@
::payment/customer-id
::payment/mandate-id
::payment/subscription-id
::embedded
::link/checkout
::link/mobile-app-checkout
::link/refunds
Expand All @@ -289,6 +358,13 @@
::pagination/previous
::pagination/self]))

(s/def ::embed-val #{:captures
:refunds
:chargebacks})

(s/def ::embed
(s/coll-of ::embed-val :into [] :distinct true))

;;; Mandate

(defmulti mandate-spec ::mandate/method)
Expand Down
17 changes: 17 additions & 0 deletions spec/com/adgoji/mollie/address.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns com.adgoji.mollie.address
(:require
[clojure.spec.alpha :as s]
[com.adgoji.common :as common]))

(s/def ::organization-name string?)
(s/def ::title string?)
(s/def ::given-name string?)
(s/def ::family-name string?)
(s/def ::email ::common/email)
(s/def ::phone string?)
(s/def ::street-and-number string?)
(s/def ::street-additional string?)
(s/def ::postal-code string?)
(s/def ::city string?)
(s/def ::region string?)
(s/def ::country string?)
17 changes: 17 additions & 0 deletions spec/com/adgoji/mollie/chargeback.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns com.adgoji.mollie.chargeback
(:require
[clojure.spec.alpha :as s]
[com.adgoji.common :as common]
[com.adgoji.mollie.reason :as reason]
[com.adgoji.mollie.payment :as payment]))

(s/def ::resource #{"chargeback"})
(s/def ::id string?)
(s/def ::amount ::common/amount)
(s/def ::settlement-amount ::common/amount)
(s/def ::created-at inst?)
(s/def ::reason
(common/only-keys :req [::reason/code
::reason/description]))
(s/def ::reversed-at inst?)
(s/def ::payment-id ::payment/id)
3 changes: 3 additions & 0 deletions spec/com/adgoji/mollie/link.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
(s/def ::mandates ::link)
(s/def ::subscription ::link)
(s/def ::subscriptions ::link)
(s/def ::payment ::link)
(s/def ::payments ::link)
(s/def ::customer ::link)
(s/def ::change-payment-state ::link)
(s/def ::profile ::link)
(s/def ::product-url ::link)
(s/def ::image-url ::link)
98 changes: 98 additions & 0 deletions spec/com/adgoji/mollie/order.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
(ns com.adgoji.mollie.order
(:require
[clojure.spec.alpha :as s]
[com.adgoji.common :as common]
[com.adgoji.mollie.address :as address]
[com.adgoji.mollie.amount :as amount]
[com.adgoji.mollie.order-line :as order-line]
[com.adgoji.mollie.link :as link])
(:import
(java.time LocalDate)))

(s/def ::resource #{"order"})
(s/def ::id string?)
(s/def ::profile-id ::common/profile-id)
(s/def ::method ::common/payment-method)
(s/def ::mode ::common/mode)
(s/def ::amount (s/keys :req [::amount/currency ::amount/value]))
(s/def ::amount-captured (s/keys :req [::amount/currency ::amount/value]))
(s/def ::amount-refunded (s/keys :req [::amount/currency ::amount/value]))
(s/def ::status
#{:created
:paid
:authorized
:canceled
:shipping
:completed
:expired})
(s/def ::is-cancelable boolean?)
(s/def ::billing-address
(s/keys :req [::address/organization-name
::address/title
::address/given-name
::address/family-name
::address/street-and-number
::address/city
::address/country
::address/email
::address/phone]
:opt [::address/street-additional
::address/postal-code
::address/region]))
(s/def ::shopper-country-must-match-billing-country boolean?)
(s/def ::consumer-date-of-birth (partial instance? LocalDate))
(s/def ::order-number string?)
(s/def ::shipping-address
(s/keys :req [::address/organization-name
::address/title
::address/given-name
::address/family-name
::address/street-and-number
::address/city
::address/country
::address/email
::address/phone]
:opt [::address/street-additional
::address/postal-code
::address/region]))
(s/def ::locale ::common/locale)
(s/def ::metadata map?)
(s/def ::redirect-url string?)
(s/def ::cancel-url string?)
(s/def ::webhook-url string?)
(s/def ::created-at inst?)
(s/def ::expires-at inst?)
(s/def ::expired-at inst?)
(s/def ::paid-at inst?)
(s/def ::authorized-at inst?)
(s/def ::canceled-at inst?)
(s/def ::completed-at inst?)
(s/def ::line
(s/keys :req [::order-line/resource
::order-line/id
::order-line/order-id
::order-line/type
::order-line/name
::order-line/status
::order-line/is-cancelable
::order-line/quantity
::order-line/quantity-shipped
::order-line/amount-shipped
::order-line/quantity-refunded
::order-line/amount-refunded
::order-line/quantity-canceled
::order-line/amount-canceled
::order-line/shippable-quantity
::order-line/refundable-quantity
::order-line/cancelable-quantity
::order-line/unit-price
::order-line/total-amount
::order-line/vat-rate
::order-line/vat-amount
::order-line/sku
::order-line/created-at
::link/product-url
::link/image-url]
:opt [::order-line/discount-amount]))
(s/def ::lines
(s/coll-of ::line :into [] :distinct true))
Loading

0 comments on commit ac83798

Please sign in to comment.