Skip to content

Commit 33f417e

Browse files
committed
Kotlin pay invoices
1 parent 86c87cd commit 33f417e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

android/src/main/java/com/reactnativeldk/LdkModule.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,23 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
351351

352352
@ReactMethod
353353
fun pay(paymentRequest: String, promise: Promise) {
354-
//TODO
355-
handleResolve(promise, LdkCallbackResponses.invoice_payment_success)
354+
invoicePayer ?: return handleReject(promise, LdkErrors.init_invoice_payer)
355+
356+
val invoice = Invoice.from_str(paymentRequest)
357+
if (!invoice.is_ok) {
358+
return handleReject(promise, LdkErrors.decode_invoice_fail)
359+
}
360+
361+
val res = invoicePayer!!.pay_invoice((invoice as Result_InvoiceParseOrSemanticErrorZ_OK).res)
362+
363+
if (res.is_ok) {
364+
handleResolve(promise, LdkCallbackResponses.invoice_payment_success)
365+
}
366+
367+
val error = res as Result_PaymentIdPaymentErrorZ.Result_PaymentIdPaymentErrorZ_Err // ?: return return handleReject(promise, LdkErrors.invoice_payment_fail)
368+
369+
//TODO check payment fail options like in swift
370+
handleReject(promise, LdkErrors.invoice_payment_fail, Error(error.err.toString()))
356371
}
357372

358373
@ReactMethod

ios/Ldk.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,6 @@ class Ldk: NSObject {
373373
return handleReject(reject, .decode_invoice_fail, nil, error?.to_str())
374374
}
375375

376-
377-
// invoice.into_signed_raw().raw_invoice().description()
378376
resolve(invoice.asJson) //Invoice class extended in Helpers file
379377
}
380378

0 commit comments

Comments
 (0)