Skip to content

Commit

Permalink
feat: added support for titleImageUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
edavism committed Jun 11, 2024
1 parent f9d7791 commit aa419cc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const result: KhipuResult = await startOperation({
operationId: '<paymentId>',
options: {
title: '<Title to display in the payment process>', // Title for the top bar during the payment process.
titleImageUrl: '<Image to display centered in the topbar>', // Url of the image to display in the top bar.
locale: 'es_CL', // Regional settings for the interface language. The standard format combines an ISO 639-1 language code and an ISO 3166 country code. For example, "es_CL" for Spanish (Chile).
theme: 'light', // The theme of the interface, can be 'dark', 'light' or 'system'
skipExitPage: false, // If true, skips the exit page at the end of the payment process, whether successful or failed.
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.khipu:khipu-client-android:2.3.0'
implementation 'com.khipu:khipu-client-android:2.5.0'
}

1 change: 1 addition & 0 deletions android/src/main/java/com/khipu/KhipuModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class KhipuModule(reactContext: ReactApplicationContext) :
if (options !== null) {

options.getString("title")?.let { optionsBuilder.topBarTitle(it) }
options.getString("titleImageUrl")?.let { optionsBuilder.topBarImageUrl(it) }
options.getBoolean("skipExitPage").let { optionsBuilder.skipExitPage(it) }
options.getString("locale")?.let { optionsBuilder.locale(it) }
if (options.hasKey("theme")) {
Expand Down
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default function App() {
operationId: 'hxet5stmvvoj',
options: {
title: 'KhipuReactNative',
titleImageUrl:
'https://s3.amazonaws.com/static.khipu.com/buttons/2024/200x75-black.png',
locale: 'es_CL',
theme: 'light',
skipExitPage: true,
Expand Down
40 changes: 22 additions & 18 deletions ios/Khipu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ import KhipuClientIOS

@objc(Khipu)
class Khipu: NSObject {

@objc(startOperation:withResolver:withRejecter:)
func startOperation(startOperationOptions: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {

var optionsBuilder = KhipuOptions.Builder()

if(startOperationOptions["options"] != nil) {

let options = startOperationOptions["options"] as! NSDictionary

if (options["title"] != nil) {
optionsBuilder = optionsBuilder.topBarTitle(options["title"]! as! String)
}


if (options["titleImageUrl"] != nil) {
optionsBuilder = optionsBuilder.topBarImageUrl(options["titleImageUrl"]! as! String)
}

if (options["skipExitPage"] != nil) {
optionsBuilder = optionsBuilder.skipExitPage(options["skipExitPage"]! as! Bool)
}

if (options["locale"] != nil) {
optionsBuilder = optionsBuilder.locale(options["locale"]! as! String)
}

if (options["theme"] != nil) {
let theme = options["theme"]! as! String
if(theme == "light") {
Expand All @@ -34,12 +38,12 @@ class Khipu: NSObject {
optionsBuilder = optionsBuilder.theme(.system)
}
}

if (options["colors"] != nil) {
let colors = options["colors"] as! NSDictionary

var colorsBuilder = KhipuColors.Builder()

if (colors["lightBackground"] != nil) {
colorsBuilder = colorsBuilder.lightBackground(colors["lightBackground"]! as! String)
}
Expand Down Expand Up @@ -76,26 +80,26 @@ class Khipu: NSObject {
if (colors["darkOnTopBarContainer"] != nil) {
colorsBuilder = colorsBuilder.darkOnTopBarContainer(colors["darkOnTopBarContainer"]! as! String)
}


optionsBuilder = optionsBuilder.colors(colorsBuilder.build())
}
}




DispatchQueue.main.async {
guard let presenter = RCTPresentedViewController() else {
reject("NO_AVAILABLE_VIEW", "There is no presented UIViewController", NSError())
return
}

guard let operationId = startOperationOptions["operationId"] else {
reject("NO_OPERATION_ID", "OperationId is needed to start the operation", NSError())
return
}

KhipuLauncher.launch(presenter: presenter,
operationId: operationId as! String,
options: optionsBuilder.build()) { result in
Expand Down
2 changes: 1 addition & 1 deletion react-native-khipu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|

s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "KhipuClientIOS", "1.1.6"
s.dependency "KhipuClientIOS", "1.1.7"
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface StartOperationOptions {
export interface KhipuOptions {
locale: string | undefined;
title: string | undefined;
titleImageUrl: string | undefined;
skipExitPage: boolean | undefined;
theme: 'light' | 'dark' | 'system' | undefined;
colors: KhipuColors | undefined;
Expand Down

0 comments on commit aa419cc

Please sign in to comment.