Skip to content

Commit

Permalink
Merge pull request #5 from ronjunevaldoz/develop
Browse files Browse the repository at this point in the history
v1.0.2-dev02
  • Loading branch information
ronjunevaldoz authored Oct 1, 2024
2 parents a3617d2 + 31bea20 commit 8a5d087
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ 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-dev02]

### Changed
- Support link in Resource serializers

## [v1.0.2-dev01]

### Added
Expand Down Expand Up @@ -42,7 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Upgrade to multiplatform with WASMJS

[v1.0.1]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.1...HEAD
[v1.0.2-dev02]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.2-dev01...HEAD
[v1.0.2-dev01]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.2-dev01...v1.0.2-dev02
[v1.0.1]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.1...v1.0.2-dev01
[v1.0.0-dev02]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.0-dev02...v1.0.1
[v1.0.0-dev01]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.0-dev01...v1.0.0-dev02
[v1.0.0]: https://github.com/ronjunevaldoz/KotlinPaymongo/compare/v1.0.0...v1.0.0-dev01
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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.PaymentIntentResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentLink
import io.github.ronjunevaldoz.paymongo.models.resource.Link
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 +82,9 @@ interface IPayMongo {
* Create a Link
* https://developers.paymongo.com/reference/create-a-link
*/
suspend fun createLink(input: CreateLinkInput): PaymentLink
suspend fun getLink(id: String): PaymentLink
suspend fun getLinkByReference(referenceNumber: String): PaymentLink
suspend fun archiveLink(id: String): PaymentLink
suspend fun unarchiveLink(id: String): PaymentLink
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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.PaymentIntentResponse
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentLink
import io.github.ronjunevaldoz.paymongo.models.resource.Link
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 +127,27 @@ class PayMongo(
return client.post("/checkout_sessions/$checkoutSessionId/expire").body()
}

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.ronjunevaldoz.paymongo.models

import kotlinx.serialization.Serializable

@Serializable
data class Tax(
val amount: Int,
val currency: String,
val inclusive: Boolean,
val name: String,
val type: String,
val value: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.ronjunevaldoz.paymongo.models.resource

import io.github.ronjunevaldoz.paymongo.models.Tax
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -13,33 +14,9 @@ data class CreateLinkInput(val data: Attributes) {
)
}

/**
* {
* "data": {
* "id": "link_WrnsXCjNtdv8wfRDwcs6APjy",
* "type": "link",
* "attributes": {
* "amount": 10000,
* "archived": false,
* "currency": "PHP",
* "description": "test payment for subscription",
* "livemode": false,
* "fee": 0,
* "remarks": "internal use descirption",
* "status": "unpaid",
* "tax_amount": null,
* "taxes": [],
* "checkout_url": "https://pm.link/org-GapS1xaVTL395KW4ucNFgpkw/test/NJUgWgz",
* "reference_number": "NJUgWgz",
* "created_at": 1727713221,
* "updated_at": 1727713221,
* "payments": []
* }
* }
* }
*/
@Serializable
data class PaymentLink(
@SerialName("link")
data class Link(
val data: Data
) : Resource() {
@Serializable
Expand All @@ -61,7 +38,7 @@ data class PaymentLink(
val status: String,
@SerialName("tax_amount")
val taxAmount: Int?,
val taxes: List<String>,
val taxes: List<Tax>,
@SerialName("checkout_url")
val checkoutUrl: String,
@SerialName("reference_number")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.ronjunevaldoz.paymongo.models.resource

import io.github.ronjunevaldoz.paymongo.models.Billing
import io.github.ronjunevaldoz.paymongo.models.Tax
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -75,7 +76,7 @@ data class Payment(
val taxAmount: Int? = null,
val metadata: Map<String, String>? = null,
val refunds : List<String> = emptyList(),
val taxes : List<String> = emptyList(),
val taxes : List<Tax> = emptyList(),
val availableAt : Long = 0,
@SerialName("created_at")
val createdAt : Long = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object ResourceSerializer : JsonContentPolymorphicSerializer<Resource>(Resource:
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<Resource> {
val property = element.jsonObject
return when {
"link" in property -> Link.serializer()
"source" in property -> Source.serializer()
"payment" in property -> Payment.serializer()
"webhook" in property -> Webhook.serializer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.ronjunevaldoz.paymongo.serialization

import io.github.ronjunevaldoz.paymongo.models.resource.Payment
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentIntent
import io.github.ronjunevaldoz.paymongo.models.resource.Link
import io.github.ronjunevaldoz.paymongo.models.resource.Resource
import io.github.ronjunevaldoz.paymongo.models.resource.Source
import io.github.ronjunevaldoz.paymongo.models.resource.Webhook
Expand All @@ -10,6 +11,7 @@ import kotlinx.serialization.modules.polymorphic

val ResourceModule = SerializersModule {
polymorphic(Resource::class) {
subclass(Link::class, Link.serializer())
subclass(Source::class, Source.serializer())
subclass(Payment::class, Payment.serializer())
subclass(PaymentIntent::class, PaymentIntent.serializer())
Expand Down
12 changes: 6 additions & 6 deletions samples/demo/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.github.ronjunevaldoz.paymongo.PayMongo
import io.github.ronjunevaldoz.paymongo.models.resource.PaymentLink
import io.github.ronjunevaldoz.paymongo.models.resource.Link
import kotlinx.coroutines.launch


Expand All @@ -29,7 +29,7 @@ fun App() {
MaterialTheme {
val scope = rememberCoroutineScope()
var webhooks by remember { mutableStateOf<List<String>>(listOf()) }
var paymentLink by remember { mutableStateOf<PaymentLink?>(null) }
var link by remember { mutableStateOf<Link?>(null) }
var secretKey by remember { mutableStateOf("sk_test_mqRYWTNuCR3pnKQvD48iJfng") }
val client by remember(secretKey) {
mutableStateOf(
Expand Down Expand Up @@ -73,7 +73,7 @@ fun App() {
client.getLink("link_WrnsXCjNtdv8wfRDwcs6APjy")
}.fold(
onSuccess = {
paymentLink = it
link = it
},
onFailure = {
it.printStackTrace()
Expand All @@ -89,7 +89,7 @@ fun App() {
client.getLink("NJUgWgz")
}.fold(
onSuccess = {
paymentLink = it
link = it
},
onFailure = {
it.printStackTrace()
Expand All @@ -99,8 +99,8 @@ fun App() {
}) {
Text("Get link by reference")
}
if (paymentLink != null) {
Text("Payment Link: $paymentLink")
if (link != null) {
Text("Payment Link: $link")
}
if (webhooks.isNotEmpty()) {
Text("Webhooks")
Expand Down

0 comments on commit 8a5d087

Please sign in to comment.