Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
mani1232 committed Jun 29, 2024
1 parent 9cf1e40 commit 36442c9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ application {
mainClass.set("cc.worldmandia.PPApiExampleKt")
}

tasks {
shadowJar {
exclude("$group.examples")
}
}

val dokkaOutputDir = "${layout.buildDirectory}/dokka"

tasks.getByName<DokkaTask>("dokkaHtml") {
Expand Down
66 changes: 66 additions & 0 deletions src/jvmMain/kotlin/cc/worldmandia/examples/PPApiExample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cc.worldmandia.examples

import cc.worldmandia.buildOrderRequest
import cc.worldmandia.buildPayPalClient
import cc.worldmandia.paypalApi.PayPalApi
import cc.worldmandia.paypalApi.orderApi.paymentSource.sources.paypal.LandingPage
import cc.worldmandia.paypalApi.orderApi.paymentSource.sources.paypal.PaymentMethodPreference
import cc.worldmandia.paypalApi.orderApi.paymentSource.sources.paypal.ShippingPreference
import cc.worldmandia.paypalApi.orderApi.paymentSource.sources.paypal.UserAction
import io.klogging.logger
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import java.util.*
import kotlin.time.Duration.Companion.seconds

suspend fun main() = coroutineScope {
buildPayPalClient {
credentials {
clientId = "AQXggWNithZosKd7xpkG9nViS1Sseb1T8LoJN-SMLUqN2OYSc2_Tqtgt39-JDQqqUwiHB8fANFLzWgNp"
clientSecret = "EIYAbJKj8sCAU08l2eajHwrxYyyEZbkr9Cd8m-GSzU98cJoy60pmPlKsB-U4pg6z0D5u3u45PvWcT73Z"
}
}

val log = logger("PayPalApi")

log.info {
PayPalApi.paypalClient.createOrder(buildOrderRequest {
purchaseUnit {
amount {
currencyCode = "USD"
value = "50.00"
}
description = "My awesome product"
}
purchaseUnit {
amount {
currencyCode = "USD"
value = "100.00"
}
description = "My awesome product 2"
}

paymentSource {
payPalSource {
experienceContext {
brandName = "My Store"
returnUrl = "https://example.com/return"
cancelUrl = "https://example.com/cancel"
locale = Locale.ENGLISH
landingPage = LandingPage.GUEST_CHECKOUT
shippingPreference = ShippingPreference.NO_SHIPPING
userAction = UserAction.PAY_NOW
paymentMethodPreference = PaymentMethodPreference.UNRESTRICTED
}
}
}

applicationContext {
// TODO
}
}).response
}

// Wait response
delay(3.seconds)
}

0 comments on commit 36442c9

Please sign in to comment.