Skip to content

Commit

Permalink
Push changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TpayDev committed Jul 3, 2024
1 parent 45a16e7 commit 2e18618
Show file tree
Hide file tree
Showing 23 changed files with 679 additions and 1,654 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ async function startScreenlessRatyPekaoPayment() {
}
```

## Screenless PayPo payment
```typescript
async function startScreenlessPayPoPayment() {
const payPoPayment = new PayPoPayment(paymentDetails, payer, callbacks);
const screenlessResult = await screenlessPayPoPayment(payPoPayment);
handleScreenlessResult(screenlessResult);
}
```

## Screenless credit card payment

Credit card payment can be created with credit card data or credit card token (for returning customers).
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.tpay:sdk:1.1.0'
implementation 'com.tpay:sdk:1.2.1'
}

4 changes: 4 additions & 0 deletions android/src/main/java/com/tpay/TpayModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class TpayModule(
@ReactMethod
fun screenlessRatyPekaoPayment(json: String, promise: Promise) = handleScreenlessPayment<RatyPekaoScreenlessPayment>(json, promise)

@ReactMethod
fun screenlessPayPoPayment(json: String, promise: Promise) = handleScreenlessPayment<PayPoScreenlessPayment>(json, promise)

@ReactMethod
fun screenlessCreditCardPayment(json: String, promise: Promise) = handleScreenlessPayment<CreditCardScreenlessPayment>(json, promise)

Expand Down Expand Up @@ -276,6 +279,7 @@ class TpayModule(
BLIKScreenlessPayment::class -> BLIKScreenlessPayment(json)
TransferScreenlessPayment::class -> TransferScreenlessPayment(json)
RatyPekaoScreenlessPayment::class -> RatyPekaoScreenlessPayment(json)
PayPoScreenlessPayment::class -> PayPoScreenlessPayment(json)
CreditCardScreenlessPayment::class -> CreditCardScreenlessPayment(json)
GooglePayScreenlessPayment::class -> GooglePayScreenlessPayment(json)
else -> throw IllegalArgumentException(NOT_IMPLEMENTED_SCREENLESS_PAYMENT_MESSAGE)
Expand Down
16 changes: 15 additions & 1 deletion android/src/main/java/com/tpay/TpayScreenlessPaymentHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.tpay.sdk.api.screenless.blik.*
import com.tpay.sdk.api.screenless.transfer.*
import com.tpay.sdk.api.screenless.card.*
import com.tpay.sdk.api.screenless.googlePay.*
import com.tpay.sdk.api.screenless.payPo.*
import com.tpay.sdk.api.screenless.PaymentDetails
import com.tpay.sdk.api.screenless.LongPollingConfig
import com.tpay.sdk.api.screenless.TransactionState
Expand Down Expand Up @@ -65,6 +66,19 @@ class TpayScreenlessPaymentHandler(
}
}

is PayPoScreenlessPayment -> {
PayPoPayment.Builder()
.apply {
setPayer(payer)
setPaymentDetails(paymentDetails)
setCallbacks(redirects, notifications)
}
.build()
.execute { createResult ->
onResult(TpayScreenlessResultHandler.handlePayPoCreateResult(createResult))
}
}

is CreditCardScreenlessPayment -> {
CreditCardPayment.Builder()
.apply {
Expand Down Expand Up @@ -99,4 +113,4 @@ class TpayScreenlessPaymentHandler(
}
}
}
}
}
20 changes: 19 additions & 1 deletion android/src/main/java/com/tpay/TpayScreenlessResultHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.tpay.sdk.api.screenless.blik.*
import com.tpay.sdk.api.screenless.transfer.*
import com.tpay.sdk.api.screenless.card.*
import com.tpay.sdk.api.screenless.googlePay.*
import com.tpay.sdk.api.screenless.payPo.*
import com.tpay.sdk.api.screenless.PaymentDetails
import com.tpay.sdk.api.screenless.LongPollingConfig
import com.tpay.sdk.api.screenless.TransactionState
Expand Down Expand Up @@ -66,6 +67,23 @@ object TpayScreenlessResultHandler {
}
}

fun handlePayPoCreateResult(
createResult: CreatePayPoTransactionResult
): TpayScreenlessResult {
return when (createResult) {
is CreatePayPoTransactionResult.Created -> {
TpayScreenlessResult.PaymentCreated(
createResult.transactionId,
createResult.paymentUrl
)
}

is CreatePayPoTransactionResult.Error -> {
TpayScreenlessResult.Error(createResult.devErrorMessage)
}
}
}

fun handleBLIKCreateResult(
createResult: CreateBLIKTransactionResult
): TpayScreenlessResult {
Expand Down Expand Up @@ -118,4 +136,4 @@ object TpayScreenlessResultHandler {
}
}
}
}
}
2 changes: 2 additions & 0 deletions android/src/main/java/com/tpay/model/PaymentMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PaymentMethods(val methods: List<PaymentMethod>) {
private const val APPLE_PAY = "applePay"
private const val GOOGLE_PAY = "googlePay"
private const val RATY_PEKAO = "ratyPekao"
private const val PAY_PO = "payPo"
private const val BLIK = "blik"
private const val CARD = "card"
private const val TRANSFER = "transfer"
Expand Down Expand Up @@ -50,6 +51,7 @@ class PaymentMethods(val methods: List<PaymentMethod>) {
.map { value ->
when (value) {
RATY_PEKAO -> InstallmentPayment.RATY_PEKAO
PAY_PO -> InstallmentPayment.PAY_PO
else -> throw ValidationException(UNKNOWN_INSTALLMENT_PAYMENT_MESSAGE)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.tpay.model.screenless

class PayPoScreenlessPayment(json: String) : ScreenlessPayment(json)
4 changes: 2 additions & 2 deletions android/src/main/java/com/tpay/util/TpayUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object TpayUtil {
.configure(merchant.environment)
.configure(paymentMethods.methods)
.configure(languages.preferredLanguage, languages.supportedLanguages)
.configure(Compatibility.Flutter)
.configure(Compatibility.REACT_NATIVE)
.configure(object : MerchantDetailsProvider {
override fun merchantDisplayName(language: Language): String {
return merchantDetails.displayNames
Expand Down Expand Up @@ -64,4 +64,4 @@ object TpayUtil {
)
}
}
}
}
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ PODS:
- React-jsinspector (0.72.6)
- React-logger (0.72.6):
- glog
- react-native-tpay (0.2.0):
- react-native-tpay (0.3.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- Tpay-SDK (= 1.0.0)
Expand Down Expand Up @@ -696,7 +696,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 3bf18ff7cb03cd8dfdce08fbbc0d15058c1d71ae
React-jsinspector: 194e32c6aab382d88713ad3dd0025c5f5c4ee072
React-logger: cebf22b6cf43434e471dc561e5911b40ac01d289
react-native-tpay: 80e31c7240cd1f0a142cb3de907c9cd52c6227c3
react-native-tpay: 38fc59425608b2dbb7cf004632d3145c6f1cb2d7
React-NativeModulesApple: 02e35e9a51e10c6422f04f5e4076a7c02243fff2
React-perflogger: e3596db7e753f51766bceadc061936ef1472edc3
React-RCTActionSheet: 17ab132c748b4471012abbcdcf5befe860660485
Expand Down
10 changes: 9 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
PaymentMethod,
PaymentMethods,
RatyPekaoPayment,
PayPoPayment,
Redirects,
Result,
screenlessAmbiguousBLIKPayment,
Expand All @@ -61,6 +62,7 @@ import {
ScreenlessConfiguredPaymentFailed,
screenlessCreditCardPayment,
screenlessGooglePayPayment,
screenlessPayPoPayment,
ScreenlessMethodCallError,
ScreenlessPaid,
ScreenlessPaymentCreated,
Expand Down Expand Up @@ -178,6 +180,12 @@ async function startScreenlessRatyPekaoPayment() {
handleScreenlessResult(screenlessResult);
}

async function startScreenlessPayPoPayment() {
const payPoPayment = new PayPoPayment(paymentDetails, payer, callbacks);
const screenlessResult = await screenlessPayPoPayment(payPoPayment);
handleScreenlessResult(screenlessResult);
}

async function startScreenlessCreditCardPayment() {
const creditCard = new CreditCard(
'card number',
Expand Down Expand Up @@ -377,7 +385,7 @@ async function configureTpay() {
const paymentMethods = new PaymentMethods(
[PaymentMethod.card, PaymentMethod.blik, PaymentMethod.transfer],
[DigitalWallet.googlePay, DigitalWallet.applePay],
[InstallmentPayment.ratyPekao]
[InstallmentPayment.ratyPekao, InstallmentPayment.payPo]
);

const configuration = new TpayConfiguration(
Expand Down
18 changes: 18 additions & 0 deletions ios/Source/Configuration/TransactionConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ final class TransactionConfiguration {
callbacks: callbacks)
}

static func payPoPayment(payPoPaymentConfiguration: String, paymentChannels: [Headless.Models.PaymentChannel]) -> PayPoPayment? {
guard let payPoData = payPoPaymentConfiguration.data(using: .utf8),
let payPoPayment = try? JSONDecoder().decode(T.PayPoPayment.self, from: payPoData),
let payer = makePayer(from: payPoPayment.payer),
let paymentChannel = paymentChannels.first(where: { $0.paymentKind == .payPo }) else {
return nil
}

let callbacks = makeCallbacksConfiguration(from: payPoPayment.callbacks)

return .init(amount: payPoPayment.paymentDetails.amount,
description: payPoPayment.paymentDetails.description,
payerContext: .init(payer: payer),
paymentChannel: paymentChannel,
callbacks: callbacks)
}


static func continuePayment(continuePaymentConfiguration: String) -> ContinuePayment? {
guard let continuePaymentData = continuePaymentConfiguration.data(using: .utf8),
let continuePayment = try? JSONDecoder().decode(T.ContinuePayment.self, from: continuePaymentData) else {
Expand Down
12 changes: 12 additions & 0 deletions ios/Source/Model/Domain/PayPoPayment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Tpay

struct PayPoPayment: Transaction {

// MARK: - Properties

let amount: Double
let description: String
let payerContext: PayerContext?
let paymentChannel: Headless.Models.PaymentChannel
let callbacks: CallbacksConfiguration
}
11 changes: 11 additions & 0 deletions ios/Source/Model/Transportation/Transportation+PayPoPayment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extension Transportation {

struct PayPoPayment: Decodable {

// MARK: - Properties

let paymentDetails: PaymentDetails
let payer: Payer
let callbacks: Callbacks
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension Transportation {
case transfer
case applePay
case ratyPekao
case payPo

// MARK: - Properties

Expand All @@ -26,6 +27,8 @@ extension Transportation {
return 3
case .applePay:
return 4
case .payPo:
return 5
}
}

Expand All @@ -41,6 +44,8 @@ extension Transportation {
return .pbl
case .applePay:
return .digitalWallet(.applePay)
case .payPo:
return .payPo
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions ios/Source/TpaySDK.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ @interface RCT_EXTERN_MODULE(TpayRNModule, NSObject)
RCT_EXTERN_METHOD(paymentWithApplePay: (NSString *)json
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(screenlessPayPoPayment: (NSString *)json
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(availablePaymentMethods: (NSString *)json
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
Expand Down
33 changes: 33 additions & 0 deletions ios/Source/TpaySDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ final class TpayRNModule: NSObject, RCTBridgeModule {
}
}

@objc func screenlessPayPoPayment(_ json: String, resolve: @escaping RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
Headless.getAvailablePaymentChannels { [weak self] result in
switch result {
case let .success(paymentChannels):
self?.invokePayPoPayment(json, resolve: resolve, paymentChannels: paymentChannels)
case let .failure(error):
resolve(ScreenlessResult.paymentFailure(error: error).toJson())
}
}
}

@objc func screenlessAmbiguousBLIKPayment(_ json: String, resolve: @escaping RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
guard let continuePayment = TransactionConfiguration.continuePayment(continuePaymentConfiguration: json),
let blikTranscation = blikPayments.first(where: { $0.ongoingTransaction.id == continuePayment.id }),
Expand Down Expand Up @@ -321,4 +332,26 @@ final class TpayRNModule: NSObject, RCTBridgeModule {
resolve(ScreenlessResult.paymentFailure(error: error).toJson())
}
}

private func invokePayPoPayment(_ json: String, resolve: @escaping RCTPromiseResolveBlock, paymentChannels: [Headless.Models.PaymentChannel]) {
guard let payPoPayment = TransactionConfiguration.payPoPayment(payPoPaymentConfiguration: json, paymentChannels: paymentChannels) else {
resolve(ScreenlessResult.methodCallError().toJson())
return
}

do {
try TpayModule.configure(callbacks: payPoPayment.callbacks)
try Headless.invokePayment(for: payPoPayment, using: payPoPayment.paymentChannel) { result in
switch result {
case let .success(transaction):
resolve(ScreenlessResult.paymentCreated(continueUrl: transaction.continueUrl, transactionId: transaction.ongoingTransaction.id).toJson())
case let .failure(error):
resolve(ScreenlessResult.paymentFailure(error: error).toJson())
}
}
} catch {
resolve(ScreenlessResult.paymentFailure(error: error).toJson())
}
}

}
25 changes: 2 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-tpay",
"version": "0.3.0",
"version": "0.4.0",
"description": "The Tpay SDK empowers your app to seamlessly integrate Tpay’s payment functionalities, providing a comprehensive and developer-friendly solution for managing payments.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
Loading

0 comments on commit 2e18618

Please sign in to comment.