Skip to content

Commit

Permalink
Merge pull request #9 from ronjunevaldoz/develop
Browse files Browse the repository at this point in the history
v1.0.2-dev06
  • Loading branch information
ronjunevaldoz authored Oct 5, 2024
2 parents c3b4c82 + 2d909a1 commit f7c9377
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 44 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.0.2-dev06]

### Fixes
- Fix link webhook response

## [v1.0.2-dev05]

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ plugins {

allprojects {
group = "io.github.ronjunevaldoz"
version = "1.0.2-dev05"
version = "1.0.2-dev06"
}

mavenPublishing {
coordinates(
groupId = "io.github.ronjunevaldoz",
artifactId = "paymongo-kotlin",
version = "1.0.2-dev05"
version = "1.0.2-dev06"
)

pom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.github.ronjunevaldoz.paymongo.models.resource.CreateSourceInput
import io.github.ronjunevaldoz.paymongo.models.resource.CreateWebhookInput
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentIntentResponse
import io.github.ronjunevaldoz.paymongo.models.resource.Link
import io.github.ronjunevaldoz.paymongo.models.resource.LinkResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentMethodResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentResponse
import io.github.ronjunevaldoz.paymongo.models.resource.SourceResponse
Expand Down Expand Up @@ -82,9 +83,9 @@ interface IPayMongo {
* Create a Link
* https://developers.paymongo.com/reference/create-a-link
*/
suspend fun createLink(input: CreateLinkInput): Link
suspend fun getLink(id: String): Link
suspend fun getLinkByReference(referenceNumber: String): Link
suspend fun archiveLink(id: String): Link
suspend fun unarchiveLink(id: String): Link
suspend fun createLink(input: CreateLinkInput): LinkResponse
suspend fun getLink(id: String): LinkResponse
suspend fun getLinkByReference(referenceNumber: String): LinkResponse
suspend fun archiveLink(id: String): LinkResponse
suspend fun unarchiveLink(id: String): LinkResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.github.ronjunevaldoz.paymongo.models.resource.CreateSourceInput
import io.github.ronjunevaldoz.paymongo.models.resource.CreateWebhookInput
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentIntentResponse
import io.github.ronjunevaldoz.paymongo.models.resource.Link
import io.github.ronjunevaldoz.paymongo.models.resource.LinkResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentMethodResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentResponse
import io.github.ronjunevaldoz.paymongo.models.resource.SourceResponse
Expand Down Expand Up @@ -127,27 +128,27 @@ class PayMongo(
return client.post("/checkout_sessions/$checkoutSessionId/expire").body()
}

override suspend fun createLink(input: CreateLinkInput): Link {
override suspend fun createLink(input: CreateLinkInput): LinkResponse {
return client.post("/links") {
setBody(input)
}.body()
}

override suspend fun getLink(id: String): Link {
override suspend fun getLink(id: String): LinkResponse {
return client.get("/links/$id").body()
}

override suspend fun getLinkByReference(referenceNumber: String): Link {
override suspend fun getLinkByReference(referenceNumber: String): LinkResponse {
return client.get("/links") {
parameter("reference_number", referenceNumber)
}.body()
}

override suspend fun archiveLink(id: String): Link {
override suspend fun archiveLink(id: String): LinkResponse {
return client.post("/links/$id/archive").body()
}

override suspend fun unarchiveLink(id: String): Link {
override suspend fun unarchiveLink(id: String): LinkResponse {
return client.post("/links/$id/unarchive").body()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.ronjunevaldoz.paymongo.models.resource.CreatePaymentMethodInput
import io.github.ronjunevaldoz.paymongo.models.resource.CreateSourceInput
import io.github.ronjunevaldoz.paymongo.models.resource.CreateWebhookInput
import io.github.ronjunevaldoz.paymongo.models.resource.Link
import io.github.ronjunevaldoz.paymongo.models.resource.LinkResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentMethodResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentType
import io.github.ronjunevaldoz.paymongo.models.resource.SourceResponse
Expand Down Expand Up @@ -70,7 +71,7 @@ suspend fun IPayMongo.createLink(
amount: Int,
description: String,
remarks: String
): Link {
): LinkResponse {
return createLink(
CreateLinkInput(
data = CreateLinkInput.LinkInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,40 @@ data class CreateLinkInput(val data: LinkInput) {
)
}


@Serializable
data class LinkResponse(
val data: Link
)

@Serializable
@SerialName("link")
data class Link(
val data: Data
val id: String,
val attributes: Attributes
) : Resource() {
@Serializable
data class Data(
val id: String,
val type: String,
val attributes: Attributes
) {
@Serializable
data class Attributes(
val amount: Int,
val archived: Boolean,
val currency: String,
val description: String,
@SerialName("livemode")
val liveMode: Boolean,
val fee: Int,
val remarks: String,
val status: String,
@SerialName("tax_amount")
val taxAmount: Int?,
val taxes: List<Tax>,
@SerialName("checkout_url")
val checkoutUrl: String,
@SerialName("reference_number")
val referenceNumber: String,
@SerialName("created_at")
val createdAt: Long,
@SerialName("updated_at")
val updatedAt: Long,
val payments: List<Payment>
)
}
data class Attributes(
val amount: Int,
val archived: Boolean,
val currency: String,
val description: String,
@SerialName("livemode")
val liveMode: Boolean,
val fee: Int,
val remarks: String,
val status: String,
@SerialName("tax_amount")
val taxAmount: Int?,
val taxes: List<Tax>,
@SerialName("checkout_url")
val checkoutUrl: String,
@SerialName("reference_number")
val referenceNumber: String,
@SerialName("created_at")
val createdAt: Long,
@SerialName("updated_at")
val updatedAt: Long,
val payments: List<PaymentResponse>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ronjune.valdoz.kpaymongo
import io.github.ronjunevaldoz.paymongo.serialization.PayMongoJson
import io.github.ronjunevaldoz.paymongo.models.resource.CheckoutSessionResponse
import io.github.ronjunevaldoz.paymongo.models.resource.CreateCheckoutSessionInput
import io.github.ronjunevaldoz.paymongo.models.resource.Link
import io.github.ronjunevaldoz.paymongo.models.resource.ReceiveWebhookEvent
import kotlin.test.Test

Expand Down Expand Up @@ -515,4 +516,17 @@ class ReceivedWebhookEventTest {
assert(false)
}
}

@Test
fun `Link payment paid should not throw an exception`() {
val sourceEventJsonString =
"{\"data\":{\"id\":\"evt_AFDUsU4tTaXXLZRZedLDrjuS\",\"type\":\"event\",\"attributes\":{\"type\":\"link.payment.paid\",\"livemode\":false,\"data\":{\"id\":\"link_xkZBPitmewE1YABBuMN8b5jh\",\"type\":\"link\",\"attributes\":{\"amount\":135000,\"archived\":false,\"currency\":\"PHP\",\"description\":\"PREMIUM subscription for 3 month/s \",\"livemode\":false,\"fee\":3375,\"remarks\":\"670125a0e80fbe64c638b9b2\",\"status\":\"paid\",\"tax_amount\":null,\"taxes\":[],\"checkout_url\":\"https://pm.link/org-GapS1xaVTL395KW4ucNFgpkw/test/d677VxY\",\"reference_number\":\"d677VxY\",\"created_at\":1728128417,\"updated_at\":1728128417,\"payments\":[{\"data\":{\"id\":\"pay_KXVd5SLmqF99kNFKrSTbiL6o\",\"type\":\"payment\",\"attributes\":{\"access_url\":null,\"amount\":135000,\"balance_transaction_id\":\"bal_txn_GtjZGT7etSDVtsNtdpjwAJAN\",\"billing\":{\"address\":{\"city\":\"Taguig\",\"country\":\"PH\",\"line1\":\"12th floor The Trade and Financial Tower u1206\",\"line2\":\"32nd street and 7th Avenue\",\"postal_code\":\"1630\",\"state\":\"Bonifacio Global City\"},\"email\":\"[email protected]\",\"name\":\"awdawd\",\"phone\":\"w\"},\"currency\":\"PHP\",\"description\":\"PREMIUM subscription for 3 month/s \",\"disputed\":false,\"external_reference_number\":\"d677VxY\",\"fee\":3375,\"instant_settlement\":null,\"livemode\":false,\"net_amount\":131625,\"origin\":\"links\",\"payment_intent_id\":null,\"payout\":null,\"source\":{\"id\":\"src_JZH7WUoy7jVsfcUhfVDAer1o\",\"type\":\"gcash\"},\"statement_descriptor\":\"PAYMONGO\",\"status\":\"paid\",\"tax_amount\":null,\"metadata\":{\"pm_reference_number\":\"d677VxY\"},\"refunds\":[],\"taxes\":[],\"available_at\":1728464400,\"created_at\":1728128494,\"credited_at\":1729069200,\"paid_at\":1728128494,\"updated_at\":1728128494}}}]}},\"previous_data\":{},\"created_at\":1728128495,\"updated_at\":1728128495}}}"
try {
PayMongoJson.decodeFromString<ReceiveWebhookEvent>(sourceEventJsonString)
assert(true)
} catch (e: Exception) {
e.printStackTrace()
assert(false)
}
}
}

0 comments on commit f7c9377

Please sign in to comment.