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

Add PayPal support #38

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] ##

## [0.5.0] - 2024-12-16 ##

### Added ###

- PayPal support ([#37](https://github.com/AdGoji/mollie/issues/37)).
- Bank transfers support ([#39](https://github.com/AdGoji/mollie/issues/39)).

## [0.4.4] - 2024-11-14 ##

### Fixed ###
Expand Down Expand Up @@ -118,7 +125,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.4.4..HEAD
[unreleased]: https://github.com/AdGoji/mollie/compare/0.5.0..HEAD
[0.5.0]: https://github.com/AdGoji/mollie/compare/0.4.4..0.5.0
[0.4.4]: https://github.com/AdGoji/mollie/compare/0.4.3..0.4.4
[0.4.3]: https://github.com/AdGoji/mollie/compare/0.4.2..0.4.3
[0.4.2]: https://github.com/AdGoji/mollie/compare/0.4.1..0.4.2
Expand Down
6 changes: 3 additions & 3 deletions 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.4.4")
(def version "0.5.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 All @@ -22,8 +22,8 @@
:basis basis
:src-dirs ["src" "spec"]
:scm {:tag version
:connection (str "scm:git:git://github.com/adgoji/mollie")
:developerConnection (str "scm:git:ssh://[email protected]:adgoji/mollie.git")
:connection "scm:git:git://github.com/adgoji/mollie"
:developerConnection "scm:git:ssh://[email protected]:adgoji/mollie.git"
:url "https://github.com/adgoji/mollie"}
:pom-data [[:licenses
[:license
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:paths ["src" "spec"]

:deps {org.clojure/clojure {:mvn/version "1.12.0"}
org.clojure/data.json {:mvn/version "2.5.0"}
org.clojure/data.json {:mvn/version "2.5.1"}
org.clojure/spec.alpha {:mvn/version "0.5.238"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
hato/hato {:mvn/version "1.0.0"}
Expand All @@ -23,6 +23,6 @@
"--codecov"]}

:build
{:deps {io.github.clojure/tools.build {:mvn/version "0.10.5"}
{:deps {io.github.clojure/tools.build {:mvn/version "0.10.6"}
slipset/deps-deploy {:mvn/version "0.2.2"}}
:ns-default build}}}
115 changes: 114 additions & 1 deletion spec/com/adgoji/mollie.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[com.adgoji.common :as common]
[com.adgoji.mollie.ideal :as ideal]
[com.adgoji.mollie.refund :as refund]
[com.adgoji.mollie.chargeback :as chargeback]))
[com.adgoji.mollie.chargeback :as chargeback]
[com.adgoji.mollie.banktransfer :as banktransfer]))

;;; Customer

Expand Down Expand Up @@ -294,6 +295,118 @@
::link/subscription
::link/customer]))

(defmethod payment-spec :paypal
[_]
(common/only-keys :req [::payment/resource
::payment/id
::payment/mode
::payment/created-at
::payment/status
::payment/amount
::payment/description
::payment/redirect-url
::payment/method
::payment/profile-id
::link/self
::link/dashboard
::link/documentation]
:opt [::payment/is-cancelable
::payment/authorized-at
::payment/paid-at
::payment/canceled-at
::payment/expires-at
::payment/expired-at
::payment/failed-at
::payment/amount-refunded
::payment/amount-remaining
::payment/amount-captured
::payment/amount-charged-back
::payment/settlement-amount
::payment/cancel-url
::payment/webhook-url
::payment/locale
::payment/country-code
::payment/restrict-payment-methods-to-country
::payment/metadata
::payment/settlement-id
::payment/order-id
::payment/sequence-type
::payment/customer-id
::payment/mandate-id
::payment/subscription-id
::embedded
::paypal/paypal-reference
::paypal/paypal-payer-id
::paypal/seller-protection
::paypal/paypal-fee
::link/checkout
::link/mobile-app-checkout
::link/refunds
::link/chargebacks
::link/captures
::link/settlement
::link/order
::link/change-payment-state
::link/mandate
::link/subscription
::link/customer]))

(defmethod payment-spec :banktransfer
[_]
(common/only-keys :req [::payment/resource
::payment/id
::payment/mode
::payment/created-at
::payment/status
::payment/amount
::payment/description
::payment/redirect-url
::payment/method
::payment/profile-id
::link/self
::link/dashboard
::link/documentation]
:opt [::payment/is-cancelable
::payment/authorized-at
::payment/paid-at
::payment/canceled-at
::payment/expires-at
::payment/expired-at
::payment/failed-at
::payment/amount-refunded
::payment/amount-remaining
::payment/amount-captured
::payment/amount-charged-back
::payment/settlement-amount
::payment/cancel-url
::payment/webhook-url
::payment/locale
::payment/country-code
::payment/restrict-payment-methods-to-country
::payment/metadata
::payment/settlement-id
::payment/order-id
::payment/sequence-type
::payment/customer-id
::payment/mandate-id
::payment/subscription-id
::embedded
::banktransfer/bank-account
::banktransfer/bank-bic
::banktransfer/bank-name
::banktransfer/transfer-reference
::link/checkout
::link/mobile-app-checkout
::link/refunds
::link/chargebacks
::link/captures
::link/settlement
::link/order
::link/change-payment-state
::link/mandate
::link/subscription
::link/customer]))

(defmethod payment-spec nil
[_]
(common/only-keys :req [::payment/resource
Expand Down
8 changes: 8 additions & 0 deletions spec/com/adgoji/mollie/banktransfer.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns com.adgoji.mollie.banktransfer
(:require
[clojure.spec.alpha :as s]))

(s/def ::bank-name string?)
(s/def ::bank-account string?)
(s/def ::bank-bic string?)
(s/def ::transfer-reference string?)
15 changes: 11 additions & 4 deletions spec/com/adgoji/mollie/payment/request.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[com.adgoji.common :as common]
[com.adgoji.mollie.amount :as amount]
[com.adgoji.mollie.customer :as customer]
[com.adgoji.mollie.mandate :as mandate])
[com.adgoji.mollie.mandate :as mandate]
[com.adgoji.mollie.paypal :as paypal])
(:import
(java.time LocalDate)))

Expand Down Expand Up @@ -53,7 +54,9 @@
::issuer
::billing-email
::due-date
::profile-id]))
::profile-id
::paypal/session-id
::paypal/digital-goods]))

(defmulti create-spec :sequence-type)

Expand Down Expand Up @@ -81,7 +84,9 @@
::issuer
::billing-email
::due-date
::profile-id]))
::profile-id
::paypal/session-id
::paypal/digital-goods]))

(defmethod create-spec :recurring
[_]
Expand All @@ -100,7 +105,9 @@
::issuer
::billing-email
::due-date
::profile-id]))
::profile-id
::paypal/session-id
::paypal/digital-goods]))

(s/def ::create (s/multi-spec create-spec :sequence-type))

Expand Down
9 changes: 8 additions & 1 deletion spec/com/adgoji/mollie/paypal.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
(ns com.adgoji.mollie.paypal
(:require
[clojure.spec.alpha :as s]))
[clojure.spec.alpha :as s]
[com.adgoji.mollie.amount :as amount]))

(s/def ::consumer-name string?)
(s/def ::consumer-account string?)
(s/def ::session-id string?)
(s/def ::digital-goods boolean?)
(s/def ::paypal-reference string?)
(s/def ::paypal-payer-id string?)
(s/def ::seller-protection string?)
(s/def ::paypal-fee (s/keys :req [::amount/currency ::amount/value]))
26 changes: 25 additions & 1 deletion src/com/adgoji/mollie/api/payments.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
[com.adgoji.mollie.refund :as refund]
[clojure.string :as str]
[com.adgoji.mollie.chargeback :as chargeback]
[camel-snake-kebab.core :as csk])
[camel-snake-kebab.core :as csk]
[com.adgoji.mollie.paypal :as paypal]
[com.adgoji.mollie.banktransfer :as banktransfer])
(:import
(java.time Instant LocalDate)))

Expand Down Expand Up @@ -86,6 +88,28 @@
consumer-account (assoc ::ideal/consumer-account consumer-account)
consumer-bic (assoc ::ideal/consumer-bic consumer-bic)))

(defmethod get-details :paypal
[{{:keys [paypal-reference
paypal-payer-id
seller-protection
paypal-fee]} :details}]
(cond-> {}
paypal-reference (assoc ::paypal/paypal-reference paypal-reference)
paypal-payer-id (assoc ::paypal/paypal-payer-id paypal-payer-id)
seller-protection (assoc ::paypal/seller-protection seller-protection)
paypal-fee (assoc ::paypal/paypal-fee (spec/qualify-amount paypal-fee))))

(defmethod get-details :banktransfer
[{{:keys [bank-account
bank-bic
bank-name
transfer-reference]} :details}]
(cond-> {}
bank-account (assoc ::banktransfer/bank-account bank-account)
bank-bic (assoc ::banktransfer/bank-bic bank-bic)
bank-name (assoc ::banktransfer/bank-name bank-name)
transfer-reference (assoc ::banktransfer/transfer-reference transfer-reference)))

(defmethod get-details ::default
[{:keys [method]}]
(throw (ex-info "Payment method is not supported"
Expand Down
Loading