Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add async charge functions #18

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/kotlin/Charge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ public suspend fun WooviSDK.charges(
.body<ChargeListResponse>()
}

public suspend fun WooviSDK.createCharge(builder: ChargeBuilder.() -> Unit): ChargeResponse {
public suspend fun WooviSDK.createCharge(
value: ChargeBuilder = ChargeBuilder(),
builder: ChargeBuilder.() -> Unit,
): ChargeResponse {
return client
.post("/api/v1/charge") { setBody(ChargeBuilder().apply(builder).build()) }
.post("/api/v1/charge") { setBody(value.apply(builder).build()) }
.body<ChargeResponse>()
}

Expand Down
27 changes: 26 additions & 1 deletion src/main/kotlin/WooviSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.ktor.client.plugins.logging.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import java.io.File
import java.util.concurrent.Executor
import java.util.concurrent.Executors
import java.util.concurrent.Future
Expand Down Expand Up @@ -72,13 +73,37 @@ public class WooviSDK(
createPixQrCode(builder) {}
}

public fun deleteChargeAsync(id: String): Future<ChargeDeleteResponse> = future {
deleteCharge(id)
}

public fun getChargeAsync(id: String): Future<ChargeResponse> = future {
getCharge(id)
}

public fun chargesAsync(
start: String? = null,
end: String? = null,
status: ChargeStatus? = null,
): Future<ChargeListResponse> = future {
charges(start, end, status)
}

public fun createChargeAsync(builder: ChargeBuilder): Future<ChargeResponse> = future {
createCharge(builder) {}
}

public fun chargeQrCodeImageAsync(id: String, size: Int = 768): Future<File> = future {
chargeQrCodeImage(id, size)
}

public fun getCustomerAsync(id: String): Future<Customer> = future {
getCustomer(id)
}

public fun allCustomersAsync(): Future<CustomerListResponse> = future {
allCustomers()
w }
}

public fun createCustomerAsync(value: CustomerBuilder): Future<CustomerResponse> = future {
createCustomer(value) {}
Expand Down
Loading