Skip to content

Commit

Permalink
style: improve docs and dx for builders (#24)
Browse files Browse the repository at this point in the history
* feat: add docs for the main java code

* docs: add docs for account

* docs: add docs for charge

* docs: add docs for customer

* docs: add docs for payment

* docs: add docs for pix qr code

* docs: add docs for refund

* docs: add docs for subscription
  • Loading branch information
aripiprazole authored Jul 21, 2023
1 parent c2aa9fa commit 84f33d6
Show file tree
Hide file tree
Showing 10 changed files with 606 additions and 43 deletions.
32 changes: 29 additions & 3 deletions src/main/kotlin/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,66 @@ import kotlinx.serialization.Serializable

@Serializable
public data class Balance(
/** Total amount in cents */
public val total: Int,

/** Blocked amount in cents */
public val blocked: Int,

/** Available amount in cents */
public val available: Int,
)

@Serializable
public data class Account(
/** The id of the account */
public val accountId: String,

/** If the account is a default account */
public val isDefault: Boolean,

/** The balance of the account */
public val balance: Balance,
)

@Serializable
public data class WithdrawRequest(
/** Value in cents */
public val value: Int,
)

@Serializable
public data class WithdrawResponse(
public val withdraw: Withdraw,
)
public data class WithdrawResponse(public val withdraw: Withdraw)

/**
* The withdrawal response.
*
* @property account The account that the withdrawal was made
* @property transaction The transaction of the withdrawal
*/
@Serializable
public data class Withdraw(
public val account: Account,
public val transaction: WithdrawTransaction,
)

/**
* The transaction of the withdrawal.
*
* @property endToEndId The end to end id of the transaction
* @property value The value of the transaction in cents
*/
@Serializable
public data class WithdrawTransaction(
public val endToEndId: String,
public val value: Int,
)

/**
* The response of the account list.
*
* @property accounts The list of accounts
*/
@Serializable
public data class AccountListResponse(public val accounts: List<Account>) : List<Account> by accounts

Expand Down
98 changes: 98 additions & 0 deletions src/main/kotlin/Charge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,104 @@ public class ChargeBuilder internal constructor() {
public var fines: Fines? by Properties.nullable()
public var additionalInfo: List<AdditionalInfo> = emptyList()

/**
* The correlation ID is a unique identifier for each request. It is useful for tracking a request through the system.
*
* @param correlationID The correlation ID
*/
public fun correlationID(correlationID: String): ChargeBuilder = apply {
this.correlationID = correlationID
}

/**
* The value of the charge in cents.
*
* @param value The value of the charge in cents
*/
public fun value(value: Int) {
this.value = value
}

/**
* The comment of the charge.
*
* @param comment The comment of the charge
*/
public fun comment(comment: String) {
this.comment = comment
}

/**
* The customer information.
*
* @param customer The customer information
*/
public fun customer(customer: CustomerBuilder): ChargeBuilder = apply {
this.customer = customer.build()
}

/**
* The expiration date of the charge in days.
*
* @param expiresIn The expiration date of the charge in days
*/
public fun expiresIn(expiresIn: Int): ChargeBuilder = apply {
this.expiresIn = expiresIn
}

/**
* The days for overdue.
*
* @param daysForOverdue The days for overdue
*/
public fun daysForOverdue(daysForOverdue: Int): ChargeBuilder = apply {
this.daysForOverdue = daysForOverdue
}

/**
* The days after due date.
*
* @param daysAfterDueDate The days after due date
*/
public fun daysAfterDueDate(daysAfterDueDate: Int): ChargeBuilder = apply {
this.daysAfterDueDate = daysAfterDueDate
}

/**
* The interests value in cents.
*
* @param interests The interests value in cents
*/
public fun interests(interests: Int): ChargeBuilder = apply {
this.interests = Interests(interests)
}

/**
* The fines value in cents.
*
* @param fines The fines value in cents
*/
public fun fines(fines: Int): ChargeBuilder = apply {
this.fines = Fines(fines)
}

/**
* The interests value in cents.
*/
public fun additionalInfo(additionalInfo: List<AdditionalInfo>): ChargeBuilder = apply {
this.additionalInfo = additionalInfo
}

/**
* Adds an info.
*
* @param key The key of the additional info
* @param value The value of the additional info
*/
public fun additionalInfo(key: String, value: String): ChargeBuilder = apply {
additionalInfo = additionalInfo + AdditionalInfo(key, value)
}

@JvmSynthetic
internal fun build(): ChargeRequestBody {
return ChargeRequestBody(
Expand Down
54 changes: 54 additions & 0 deletions src/main/kotlin/Customer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,60 @@ public class CustomerBuilder internal constructor() {
public var correlationID: String? by Properties.nullable()
public var address: Address? by Properties.nullable()

/**
* The customer's name.
*
* @param name The customer's name.
*/
public fun name(name: String): CustomerBuilder = apply {
this.name = name
}

/**
* The customer's tax id.
*
* @param taxID The customer's tax id.
*/
public fun taxID(taxID: String): CustomerBuilder = apply {
this.taxID = taxID
}

/**
* The customer's email.
*
* @param email The customer's email.
*/
public fun email(email: String): CustomerBuilder = apply {
this.email = email
}

/**
* The customer's phone.
*
* @param phone The customer's phone.
*/
public fun phone(phone: String): CustomerBuilder = apply {
this.phone = phone
}

/**
* The customer's correlation id.
*
* @param correlationID The customer's correlation id.
*/
public fun correlationID(correlationID: String): CustomerBuilder = apply {
this.correlationID = correlationID
}

/**
* The customer's address.
*
* @param address The customer's address.
*/
public fun address(address: Address): CustomerBuilder = apply {
this.address = address
}

@JvmSynthetic
internal fun build(): CustomerRequest {
return CustomerRequest(name, taxID, email, phone, correlationID, address)
Expand Down
45 changes: 45 additions & 0 deletions src/main/kotlin/Payment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,51 @@ public class PaymentBuilder internal constructor() {
public var comment: String? by Properties.nullable()
public var sourceAccountId: String? by Properties.nullable()

/**
* The value of the payment in cents.
*
* @param value The value of the payment in cents.
*/
public fun value(value: Int): PaymentBuilder = apply {
this.value = value
}

/**
* The destination of the payment.
*
* @param destinationAlias The destination of the payment.
*/
public fun destinationAlias(destinationAlias: String): PaymentBuilder = apply {
this.destinationAlias = destinationAlias
}

/**
* The source account of the payment.
*
* @param sourceAccountId The source account of the payment.
*/
public fun sourceAccountId(sourceAccountId: String): PaymentBuilder = apply {
this.sourceAccountId = sourceAccountId
}

/**
* The correlation id of the payment.
*
* @param correlationID The correlation id of the payment.
*/
public fun correlationID(correlationID: String): PaymentBuilder = apply {
this.correlationID = correlationID
}

/**
* The comment of the payment.
*
* @param comment The comment of the payment.
*/
public fun comment(comment: String): PaymentBuilder = apply {
this.comment = comment
}

@JvmSynthetic
internal fun build(): PaymentRequest {
return PaymentRequest(value, destinationAlias, correlationID, comment, sourceAccountId)
Expand Down
45 changes: 45 additions & 0 deletions src/main/kotlin/PixQrCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,51 @@ public class PixQrCodeBuilder internal constructor() {
public var comment: String? by Properties.nullable()
public var identifier: String by Properties.required()

/**
* The name of the pix qr code.
*
* @param name The name of the pix qr code.
*/
public fun name(name: String): PixQrCodeBuilder = apply {
this.name = name
}

/**
* The correlation id of the pix qr code.
*
* @param correlationID The correlation id of the pix qr code.
*/
public fun correlationID(correlationID: String): PixQrCodeBuilder = apply {
this.correlationID = correlationID
}

/**
* The value of the pix qr code.
*
* @param value The value of the pix qr code.
*/
public fun value(value: Int): PixQrCodeBuilder = apply {
this.value = value
}

/**
* The comment of the pix qr code.
*
* @param comment The comment of the pix qr code.
*/
public fun comment(comment: String): PixQrCodeBuilder = apply {
this.comment = comment
}

/**
* The identifier of the pix qr code.
*
* @param identifier The identifier of the pix qr code.
*/
public fun identifier(identifier: String): PixQrCodeBuilder = apply {
this.identifier = identifier
}

@JvmSynthetic
internal fun build(): PixQrCodeRequestBody {
return PixQrCodeRequestBody(name, correlationID, value, comment, identifier)
Expand Down
36 changes: 36 additions & 0 deletions src/main/kotlin/Refund.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,42 @@ public class RefundBuilder internal constructor() {
public var transactionEndToEndId: String by Properties.required()
public var comment: String? by Properties.nullable()

/**
* The correlation id of the refund.
*
* @param correlationID The correlation id of the refund.
*/
public fun correlationID(correlationID: String): RefundBuilder = apply {
this.correlationID = correlationID
}

/**
* The value of the refund.
*
* @param value The value of the refund.
*/
public fun value(value: Int): RefundBuilder = apply {
this.value = value
}

/**
* The transaction end to end id of the refund.
*
* @param transactionEndToEndId The transaction end to end id of the refund.
*/
public fun transactionEndToEndId(transactionEndToEndId: String): RefundBuilder = apply {
this.transactionEndToEndId = transactionEndToEndId
}

/**
* The comment of the refund.
*
* @param comment The comment of the refund.
*/
public fun comment(comment: String): RefundBuilder = apply {
this.comment = comment
}

@JvmSynthetic
internal fun build(): RefundRequestBody {
return RefundRequestBody(correlationID, value, transactionEndToEndId, comment)
Expand Down
Loading

0 comments on commit 84f33d6

Please sign in to comment.