Created
February 16, 2023 15:25
-
-
Save gabfssilva/d69a2b7bdcec7b3e0d4d8dfb67516f9f to your computer and use it in GitHub Desktop.
Payment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST /api/v1/payments | |
{ | |
amount: { | |
currency: BRL, | |
value: 1000 // R$ 10,00 | |
}, | |
//more payment data depending on the payment type | |
} | |
//the version is the last event version, so we can ensure we won't append events to an old payment state | |
//whoever is calling must deal with that, usually those issues happen in a concurrent scenario or simply message duplication | |
POST /api/v1/payments/{id}/events?version=3 | |
[ { | |
type: payment_sent | |
},{ | |
type: credit_card_authorization_sent, | |
acquirerCode: "abc_dbc#123" //each event has its own fields | |
}] | |
case class Amount(value: Long, currency: Currency) | |
case class Payment( | |
id: Long, | |
createdAt: ZonedDateTime, | |
amount: Amount, | |
events: List[Event] | |
) | |
sealed class Event( | |
id: Long, | |
paymentVersion: Int, | |
createdAt: ZonedDateTime | |
) | |
//the generic ones | |
case class PaymentCreated( | |
id: Long, | |
paymentVersion: Int | |
) extends Event(ZonedDateTime.now) | |
case class PaymentSent( | |
id: Long, | |
paymentVersion: Int | |
) extends Event(ZonedDateTime.now) | |
case class PaymentPaid( | |
id: Long, | |
paymentVersion: Int | |
) extends Event(ZonedDateTime.now) | |
case class PaymentNotPaid( | |
id: Long, | |
paymentVersion: Int | |
) extends Event(ZonedDateTime.now) | |
// the specific ones | |
case class CreditCardAuthorizationSent( | |
id: Long, | |
paymentVersion: Int, | |
acquirerCode: String | |
) extends Event(ZonedDateTime.now) | |
case class CreditCardAuthorized( | |
id: Long, | |
paymentVersion: Int, | |
acquirerConfirmationCode: String | |
) extends Event(ZonedDateTime.now) | |
case class CreditCardCaptureSent( | |
id: Long, | |
paymentVersion: Int, | |
) extends Event(ZonedDateTime.now) | |
case class CreditCardCaptured( | |
id: Long, | |
paymentVersion: Int, | |
captureId: String | |
) extends Event(ZonedDateTime.now) | |
case class BoletoGenerated( | |
id: Long, | |
paymentVersion: Int, | |
url: String | |
) extends Event(ZonedDateTime.now) | |
case class BoletoPaid( | |
id: Long, | |
paymentVersion: Int, | |
amount: Amount | |
) extends Event(ZonedDateTime.now) | |
case class BoletoExpired( | |
id: Long, | |
paymentVersion: Int, | |
expiredAt: ZonedDateTime | |
) extends Event(ZonedDateTime.now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment