├── .gitattributes ├── android ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── nextar │ │ └── sumup │ │ ├── RNSumUpPackage.java │ │ └── RNSumUpModule.java ├── build.gradle ├── gradlew.bat └── gradlew ├── ios ├── RNSumUp.xcworkspace │ └── contents.xcworkspacedata ├── RNSumUp.h ├── RNSumUp.xcodeproj │ └── project.pbxproj └── RNSumUp.m ├── .gitignore ├── package.json ├── RNSumUp.podspec ├── README.md ├── index.d.ts └── index.js /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/540/react-native-sum-up/master/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ios/RNSumUp.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | 3 | 5 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Feb 28 16:18:37 BRT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /ios/RNSumUp.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNSumUp.h 3 | // RNSumUp.h 4 | // 5 | // Created by Ítalo Menezes on 26/02/2018. 6 | // Copyright © 2018 NEXTAR. All rights reserved. 7 | // 8 | // 9 | // Thanks to APSL/react-native-sumup. 10 | // 11 | 12 | #import 13 | #import 14 | #import 15 | 16 | @interface RNSumUp : NSObject 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Xcode 14 | # 15 | build/ 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | xcuserdata 25 | *.xccheckout 26 | *.moved-aside 27 | DerivedData 28 | *.hmap 29 | *.ipa 30 | *.xcuserstate 31 | project.xcworkspace 32 | 33 | 34 | # Android/IntelliJ 35 | # 36 | build/ 37 | .idea 38 | .gradle 39 | local.properties 40 | *.iml 41 | 42 | # BUCK 43 | buck-out/ 44 | \.buckd/ 45 | *.keystore 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@540deg/rn-sumup", 3 | "version": "1.1.5", 4 | "description": "SumUpSDK Wrapper for React Native.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react-native" 11 | ], 12 | "author": "540deg ", 13 | "license": "MIT", 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/ReactNativeBrasil/react-native-sum-up.git" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/ReactNativeBrasil/react-native-sum-up/issues" 20 | }, 21 | "homepage": "https://github.com/ReactNativeBrasil/react-native-sum-up#readme" 22 | } 23 | -------------------------------------------------------------------------------- /RNSumUp.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | Pod::Spec.new do |s| 4 | # NPM package specification 5 | package = JSON.parse(File.read(File.join(File.dirname(__FILE__), "package.json"))) 6 | 7 | s.name = "RNSumUp" 8 | s.version = package["version"] 9 | s.summary = package["description"] 10 | s.homepage = "https://github.com/ReactNativeBrasil/react-native-sum-up" 11 | s.license = "MIT" 12 | s.author = { package["author"]["name"] => package["author"]["email"] } 13 | s.platforms = { :ios => "9.0" } 14 | s.source = { :git => "https://github.com/ReactNativeBrasil/react-native-sum-up.git", :tag => "#{s.version}" } 15 | s.source_files = "ios/**/*.{h,m}" 16 | 17 | s.pod_target_xcconfig = { 18 | 'HEADER_SEARCH_PATHS' => [ 19 | '"$(SRCROOT)/../**"' 20 | ] 21 | } 22 | 23 | s.dependency "React" 24 | s.dependency "SumUpSDK" 25 | 26 | end 27 | -------------------------------------------------------------------------------- /android/src/main/java/com/nextar/sumup/RNSumUpPackage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.nextar.sumup; 3 | 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | 14 | public class RNSumUpPackage implements ReactPackage { 15 | @Override 16 | public List createNativeModules(ReactApplicationContext reactContext) { 17 | return Arrays.asList(new RNSumUpModule(reactContext)); 18 | } 19 | 20 | // Deprecated from RN 0.47 21 | public List> createJSModules() { 22 | return Collections.emptyList(); 23 | } 24 | 25 | @Override 26 | public List createViewManagers(ReactApplicationContext reactContext) { 27 | return Collections.emptyList(); 28 | } 29 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # react-native-sum-up 3 | 4 | ## Getting started 5 | 6 | `$ npm install rn-sumup --save` 7 | 8 | ### Mostly automatic installation 9 | 10 | `$ react-native link rn-sumup` 11 | 12 | ### Manual installation 13 | 14 | 15 | #### iOS 16 | 17 | 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 18 | 2. Go to `node_modules` ➜ `rn-sumup` and add `RNSumUp.xcodeproj` 19 | 3. In XCode, in the project navigator, select your project. Add `libRNSumUp.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` 20 | 4. Run your project (`Cmd+R`)< 21 | 22 | #### Android 23 | 24 | 1. Open up `android/app/src/main/java/[...]/MainApplication.java` 25 | - Add `import com.nextar.sumup.RNSumUpPackage;` to the imports at the top of the file 26 | - Add `new RNSumUpPackage()` to the list returned by the `getPackages()` method 27 | 2. Append the following lines to `android/settings.gradle`: 28 | ``` 29 | include ':rn-sumup' 30 | project(':rn-sumup').projectDir = new File(rootProject.projectDir, '../node_modules/rn-sumup/android') 31 | ``` 32 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: 33 | ``` 34 | compile project(':rn-sumup') 35 | ``` 36 | ## Usage 37 | ```javascript 38 | import RNSumUp from 'rn-sumup'; 39 | 40 | ``` 41 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@540deg/rn-sumup' { 2 | export function setup(apiKey: string): void 3 | 4 | export function authenticate(): Promise 5 | 6 | export function authenticateWithToken(accessToken: string): Promise 7 | 8 | export function preferences(): Promise 9 | 10 | export function isLoggedIn(): Promise 11 | 12 | export function logout(): Promise 13 | 14 | export function checkout(checkoutRequest: CheckoutRequest): Promise 15 | 16 | export interface AuthenticateResponse { 17 | success: boolean 18 | userAdditionalInfo: { 19 | currencyCode: string 20 | merchantCode: string 21 | } 22 | } 23 | 24 | export interface CheckoutRequest { 25 | currencyCode: 'SMPCurrencyCodeBGN' | 'SMPCurrencyCodeBRL' | 'SMPCurrencyCodeCHF' | 'SMPCurrencyCodeCLP' | 'SMPCurrencyCodeCZK' | 'SMPCurrencyCodeDKK' | 'SMPCurrencyCodeEUR' | 'SMPCurrencyCodeGBP' | 'SMPCurrencyCodeHUF' | 'SMPCurrencyCodeNOK' | 'SMPCurrencyCodePLN' | 'SMPCurrencyCodeRON' | 'SMPCurrencyCodeSEK' | 'SMPCurrencyCodeUSD' 26 | totalAmount: string 27 | title: string 28 | foreignTransactionId?: string 29 | receiptSMS?: string 30 | receiptEmail?: string 31 | } 32 | 33 | export interface CheckoutResponse { 34 | additionalInfo: { 35 | cardLast4Digits: string 36 | } 37 | cardType: string 38 | installments: number 39 | success: boolean 40 | transactionCode: string 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | maven { 6 | url 'https://maven.google.com/' 7 | name 'Google' 8 | } 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:2.3.3' 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | 19 | maven { 20 | url 'https://maven.google.com/' 21 | name 'Google' 22 | } 23 | 24 | maven { url 'https://maven.sumup.com/releases' } 25 | } 26 | } 27 | 28 | apply plugin: 'com.android.library' 29 | 30 | android { 31 | compileSdkVersion 27 32 | buildToolsVersion "26.0.2" 33 | 34 | defaultConfig { 35 | minSdkVersion 16 36 | targetSdkVersion 27 37 | versionCode 1 38 | versionName "1.0" 39 | ndk { 40 | abiFilters "armeabi-v7a", "x86" 41 | } 42 | } 43 | // Possible resolution strategy. Only necessary if not compiling against API 27 44 | configurations.all { 45 | resolutionStrategy { 46 | force 'com.android.support:support-v4:26.1.0' 47 | force 'com.android.support:appcompat-v7:26.1.0' 48 | force 'com.android.support:cardview-v7:26.1.0' 49 | force 'com.android.support:design:26.1.0' 50 | } 51 | } 52 | 53 | packagingOptions { 54 | exclude 'META-INF/services/javax.annotation.processing.Processor' 55 | exclude 'META-INF/LICENSE' 56 | exclude 'META-INF/NOTICE' 57 | } 58 | 59 | buildTypes { 60 | debug { 61 | // All ProGuard rules required by the SumUp SDK are packaged with the library 62 | minifyEnabled true 63 | proguardFiles getDefaultProguardFile('proguard-android.txt') 64 | } 65 | } 66 | } 67 | 68 | repositories { 69 | mavenCentral() 70 | jcenter() 71 | } 72 | 73 | dependencies { 74 | annotationProcessor 'com.neenbedankt.bundles:argument:1.0.4' 75 | compileOnly 'com.neenbedankt.bundles:argument:1.0.4' 76 | compile 'com.facebook.react:react-native:+' 77 | compile 'com.android.support:appcompat-v7:27.1.1' 78 | compile 'com.android.support:design:27.1.1' 79 | 80 | compile 'com.google.android.gms:play-services-location:17.0.0' 81 | compile 'com.sumup:merchant-sdk:3.3.0' 82 | } 83 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules, Platform } from 'react-native'; 2 | 3 | const RNSumUpWrapper = NativeModules.RNSumUp; 4 | 5 | const RNSumUp = { 6 | apiKey: '', 7 | 8 | paymentOptionAny: (Platform.OS === 'ios') ? RNSumUpWrapper.SMPPaymentOptionAny : null, 9 | paymentOptionCardReader: (Platform.OS === 'ios') ? RNSumUpWrapper.SMPPaymentOptionCardReader : null, 10 | paymentOptionMobilePayment: (Platform.OS === 'ios') ? RNSumUpWrapper.SMPPaymentOptionMobilePayment : null, 11 | 12 | SMPCurrencyCodeBGN: RNSumUpWrapper.SMPCurrencyCodeBGN, 13 | SMPCurrencyCodeBRL: RNSumUpWrapper.SMPCurrencyCodeBRL, 14 | SMPCurrencyCodeCHF: RNSumUpWrapper.SMPCurrencyCodeCHF, 15 | SMPCurrencyCodeCLP: (Platform.OS === 'android') ? RNSumUpWrapper.SMPCurrencyCodeCLP : null, // iOS SDK version currently doesn't supports this currency 16 | SMPCurrencyCodeCZK: RNSumUpWrapper.SMPCurrencyCodeCZK, 17 | SMPCurrencyCodeDKK: RNSumUpWrapper.SMPCurrencyCodeDKK, 18 | SMPCurrencyCodeEUR: RNSumUpWrapper.SMPCurrencyCodeEUR, 19 | SMPCurrencyCodeGBP: RNSumUpWrapper.SMPCurrencyCodeGBP, 20 | SMPCurrencyCodeHUF: RNSumUpWrapper.SMPCurrencyCodeHUF, 21 | SMPCurrencyCodeNOK: RNSumUpWrapper.SMPCurrencyCodeNOK, 22 | SMPCurrencyCodePLN: RNSumUpWrapper.SMPCurrencyCodePLN, 23 | SMPCurrencyCodeRON: RNSumUpWrapper.SMPCurrencyCodeRON, 24 | SMPCurrencyCodeSEK: RNSumUpWrapper.SMPCurrencyCodeSEK, 25 | SMPCurrencyCodeUSD: RNSumUpWrapper.SMPCurrencyCodeUSD, 26 | 27 | setup(key) { 28 | this.apiKey = key; 29 | if (Platform.OS === 'ios') { 30 | RNSumUpWrapper.setup(key); 31 | } 32 | }, 33 | 34 | authenticate() { 35 | return (Platform.OS === 'ios') ? RNSumUpWrapper.authenticate() : RNSumUpWrapper.authenticate(this.apiKey); 36 | }, 37 | 38 | authenticateWithToken(token) { 39 | return (Platform.OS === 'ios') ? RNSumUpWrapper.authenticateWithToken(token) : RNSumUpWrapper.authenticateWithToken(this.apiKey, token); 40 | }, 41 | 42 | logout() { 43 | return RNSumUpWrapper.logout(); 44 | }, 45 | 46 | prepareForCheckout() { 47 | return RNSumUpWrapper.prepareForCheckout(); 48 | }, 49 | 50 | checkout(request, token = null) { 51 | if (Platform.OS === 'android') { 52 | if (!token) { 53 | throw new Error('For Android checkouts you need to provide an OAuth2 token. Please, read: https://github.com/sumup/sumup-android-sdk#5-transparent-authentication'); 54 | } 55 | 56 | return this.isLoggedIn().then((isLoggedIn) => { 57 | if (!isLoggedIn) { 58 | const authWithToken = new Promise(async resolve => { 59 | await this.authenticateWithToken(token); 60 | resolve(); 61 | }); 62 | 63 | return authWithToken.then(() => RNSumUpWrapper.checkout(request)); 64 | } 65 | return RNSumUpWrapper.checkout(request); 66 | }); 67 | } 68 | return RNSumUpWrapper.checkout(request); 69 | }, 70 | 71 | preferences() { 72 | return RNSumUpWrapper.preferences(); 73 | }, 74 | 75 | isLoggedIn() { 76 | return RNSumUpWrapper.isLoggedIn(); 77 | } 78 | }; 79 | 80 | module.exports = RNSumUp; 81 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /ios/RNSumUp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B3E7B58A1CC2AC0600A0062D /* RNSumUp.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNSumUp.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 134814201AA4EA6300B7C361 /* libRNSumUp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNSumUp.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | B3E7B5881CC2AC0600A0062D /* RNSumUp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSumUp.h; sourceTree = ""; }; 28 | B3E7B5891CC2AC0600A0062D /* RNSumUp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSumUp.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 134814211AA4EA7D00B7C361 /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 134814201AA4EA6300B7C361 /* libRNSumUp.a */, 46 | ); 47 | name = Products; 48 | sourceTree = ""; 49 | }; 50 | 58B511D21A9E6C8500147676 = { 51 | isa = PBXGroup; 52 | children = ( 53 | B3E7B5881CC2AC0600A0062D /* RNSumUp.h */, 54 | B3E7B5891CC2AC0600A0062D /* RNSumUp.m */, 55 | 134814211AA4EA7D00B7C361 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXNativeTarget section */ 62 | 58B511DA1A9E6C8500147676 /* RNSumUp */ = { 63 | isa = PBXNativeTarget; 64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNSumUp" */; 65 | buildPhases = ( 66 | 58B511D71A9E6C8500147676 /* Sources */, 67 | 58B511D81A9E6C8500147676 /* Frameworks */, 68 | 58B511D91A9E6C8500147676 /* CopyFiles */, 69 | ); 70 | buildRules = ( 71 | ); 72 | dependencies = ( 73 | ); 74 | name = RNSumUp; 75 | productName = RCTDataManager; 76 | productReference = 134814201AA4EA6300B7C361 /* libRNSumUp.a */; 77 | productType = "com.apple.product-type.library.static"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | 58B511D31A9E6C8500147676 /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | LastUpgradeCheck = 0830; 86 | ORGANIZATIONNAME = Facebook; 87 | TargetAttributes = { 88 | 58B511DA1A9E6C8500147676 = { 89 | CreatedOnToolsVersion = 6.1.1; 90 | }; 91 | }; 92 | }; 93 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNSumUp" */; 94 | compatibilityVersion = "Xcode 3.2"; 95 | developmentRegion = English; 96 | hasScannedForEncodings = 0; 97 | knownRegions = ( 98 | English, 99 | en, 100 | ); 101 | mainGroup = 58B511D21A9E6C8500147676; 102 | productRefGroup = 58B511D21A9E6C8500147676; 103 | projectDirPath = ""; 104 | projectRoot = ""; 105 | targets = ( 106 | 58B511DA1A9E6C8500147676 /* RNSumUp */, 107 | ); 108 | }; 109 | /* End PBXProject section */ 110 | 111 | /* Begin PBXSourcesBuildPhase section */ 112 | 58B511D71A9E6C8500147676 /* Sources */ = { 113 | isa = PBXSourcesBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | B3E7B58A1CC2AC0600A0062D /* RNSumUp.m in Sources */, 117 | ); 118 | runOnlyForDeploymentPostprocessing = 0; 119 | }; 120 | /* End PBXSourcesBuildPhase section */ 121 | 122 | /* Begin XCBuildConfiguration section */ 123 | 58B511ED1A9E6C8500147676 /* Debug */ = { 124 | isa = XCBuildConfiguration; 125 | buildSettings = { 126 | ALWAYS_SEARCH_USER_PATHS = NO; 127 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 128 | CLANG_CXX_LIBRARY = "libc++"; 129 | CLANG_ENABLE_MODULES = YES; 130 | CLANG_ENABLE_OBJC_ARC = YES; 131 | CLANG_WARN_BOOL_CONVERSION = YES; 132 | CLANG_WARN_CONSTANT_CONVERSION = YES; 133 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 134 | CLANG_WARN_EMPTY_BODY = YES; 135 | CLANG_WARN_ENUM_CONVERSION = YES; 136 | CLANG_WARN_INFINITE_RECURSION = YES; 137 | CLANG_WARN_INT_CONVERSION = YES; 138 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 139 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 140 | CLANG_WARN_UNREACHABLE_CODE = YES; 141 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 142 | COPY_PHASE_STRIP = NO; 143 | ENABLE_STRICT_OBJC_MSGSEND = YES; 144 | ENABLE_TESTABILITY = YES; 145 | GCC_C_LANGUAGE_STANDARD = gnu99; 146 | GCC_DYNAMIC_NO_PIC = NO; 147 | GCC_NO_COMMON_BLOCKS = YES; 148 | GCC_OPTIMIZATION_LEVEL = 0; 149 | GCC_PREPROCESSOR_DEFINITIONS = ( 150 | "DEBUG=1", 151 | "$(inherited)", 152 | ); 153 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 154 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 155 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 156 | GCC_WARN_UNDECLARED_SELECTOR = YES; 157 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 158 | GCC_WARN_UNUSED_FUNCTION = YES; 159 | GCC_WARN_UNUSED_VARIABLE = YES; 160 | HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../ios/**"; 161 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 162 | MTL_ENABLE_DEBUG_INFO = YES; 163 | ONLY_ACTIVE_ARCH = YES; 164 | SDKROOT = iphoneos; 165 | }; 166 | name = Debug; 167 | }; 168 | 58B511EE1A9E6C8500147676 /* Release */ = { 169 | isa = XCBuildConfiguration; 170 | buildSettings = { 171 | ALWAYS_SEARCH_USER_PATHS = NO; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BOOL_CONVERSION = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_EMPTY_BODY = YES; 180 | CLANG_WARN_ENUM_CONVERSION = YES; 181 | CLANG_WARN_INFINITE_RECURSION = YES; 182 | CLANG_WARN_INT_CONVERSION = YES; 183 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 184 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 185 | CLANG_WARN_UNREACHABLE_CODE = YES; 186 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 187 | COPY_PHASE_STRIP = YES; 188 | ENABLE_NS_ASSERTIONS = NO; 189 | ENABLE_STRICT_OBJC_MSGSEND = YES; 190 | GCC_C_LANGUAGE_STANDARD = gnu99; 191 | GCC_NO_COMMON_BLOCKS = YES; 192 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 193 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 194 | GCC_WARN_UNDECLARED_SELECTOR = YES; 195 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 196 | GCC_WARN_UNUSED_FUNCTION = YES; 197 | GCC_WARN_UNUSED_VARIABLE = YES; 198 | HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../ios/**"; 199 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 200 | MTL_ENABLE_DEBUG_INFO = NO; 201 | SDKROOT = iphoneos; 202 | VALIDATE_PRODUCT = YES; 203 | }; 204 | name = Release; 205 | }; 206 | 58B511F01A9E6C8500147676 /* Debug */ = { 207 | isa = XCBuildConfiguration; 208 | buildSettings = { 209 | ENABLE_BITCODE = NO; 210 | FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../../../ios/Pods/**"; 211 | HEADER_SEARCH_PATHS = ( 212 | "$(inherited)", 213 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 214 | "$(SRCROOT)/../../../React/**", 215 | "$(SRCROOT)/../../react-native/React/**", 216 | "$(SRCROOT)/../../../ios/**", 217 | "$(SRCROOT)/../**", 218 | ); 219 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 220 | OTHER_LDFLAGS = ( 221 | "-ObjC", 222 | "$(inherited)", 223 | ); 224 | PRODUCT_NAME = RNSumUp; 225 | SKIP_INSTALL = YES; 226 | }; 227 | name = Debug; 228 | }; 229 | 58B511F11A9E6C8500147676 /* Release */ = { 230 | isa = XCBuildConfiguration; 231 | buildSettings = { 232 | ENABLE_BITCODE = NO; 233 | FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../../../ios/Pods/**"; 234 | HEADER_SEARCH_PATHS = ( 235 | "$(inherited)", 236 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 237 | "$(SRCROOT)/../../../React/**", 238 | "$(SRCROOT)/../../react-native/React/**", 239 | "$(SRCROOT)/../../../ios/**", 240 | "$(SRCROOT)/../**", 241 | ); 242 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 243 | OTHER_LDFLAGS = ( 244 | "-ObjC", 245 | "$(inherited)", 246 | ); 247 | PRODUCT_NAME = RNSumUp; 248 | SKIP_INSTALL = YES; 249 | }; 250 | name = Release; 251 | }; 252 | /* End XCBuildConfiguration section */ 253 | 254 | /* Begin XCConfigurationList section */ 255 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNSumUp" */ = { 256 | isa = XCConfigurationList; 257 | buildConfigurations = ( 258 | 58B511ED1A9E6C8500147676 /* Debug */, 259 | 58B511EE1A9E6C8500147676 /* Release */, 260 | ); 261 | defaultConfigurationIsVisible = 0; 262 | defaultConfigurationName = Release; 263 | }; 264 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNSumUp" */ = { 265 | isa = XCConfigurationList; 266 | buildConfigurations = ( 267 | 58B511F01A9E6C8500147676 /* Debug */, 268 | 58B511F11A9E6C8500147676 /* Release */, 269 | ); 270 | defaultConfigurationIsVisible = 0; 271 | defaultConfigurationName = Release; 272 | }; 273 | /* End XCConfigurationList section */ 274 | }; 275 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 276 | } 277 | -------------------------------------------------------------------------------- /ios/RNSumUp.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNSumUp.m 3 | // RNSumUp.m 4 | // 5 | // Created by Ítalo Menezes on 26/02/2018. 6 | // Copyright © 2018 NEXTAR. All rights reserved. 7 | // 8 | 9 | #import "RNSumUp.h" 10 | #import "AppDelegate.h" 11 | 12 | @implementation RCTConvert (SMPPaymentOptions) 13 | 14 | RCT_ENUM_CONVERTER(SMPPaymentOptions, ( 15 | @{@"SMPPaymentOptionAny" : @(SMPPaymentOptionAny), 16 | @"SMPPaymentOptionCardReader" : @(SMPPaymentOptionCardReader), 17 | @"SMPPaymentOptionMobilePayment" : @(SMPPaymentOptionMobilePayment) 18 | }), SMPPaymentOptionAny, integerValue); 19 | 20 | @end 21 | 22 | @implementation RCTConvert (SMPSkipScreenOptions) 23 | RCT_ENUM_CONVERTER(SMPSkipScreenOptions, (@{@"1" : @(SMPSkipScreenOptionSuccess)}), SMPSkipScreenOptionSuccess, integerValue); 24 | @end 25 | 26 | @implementation NSDictionary (WKDictionary) 27 | 28 | - (id)objectForKeyNotNull:(id)key { 29 | 30 | id object = [self objectForKey:key]; 31 | if (object == [NSNull null]) 32 | return nil; 33 | 34 | return object; 35 | } 36 | 37 | @end 38 | 39 | @implementation RNSumUp 40 | 41 | - (NSDictionary *)constantsToExport 42 | { 43 | return @{ @"SMPPaymentOptionAny": @(SMPPaymentOptionAny), 44 | @"SMPPaymentOptionCardReader": @(SMPPaymentOptionCardReader), 45 | @"SMPPaymentOptionMobilePayment": @(SMPPaymentOptionMobilePayment), 46 | @"SMPCurrencyCodeBGN" : (SMPCurrencyCodeBGN), 47 | @"SMPCurrencyCodeBRL" : (SMPCurrencyCodeBRL), 48 | @"SMPCurrencyCodeCHF" : (SMPCurrencyCodeCHF), 49 | @"SMPCurrencyCodeCLP" : (SMPCurrencyCodeCLP), 50 | @"SMPCurrencyCodeCZK" : (SMPCurrencyCodeCZK), 51 | @"SMPCurrencyCodeDKK" : (SMPCurrencyCodeDKK), 52 | @"SMPCurrencyCodeEUR" : (SMPCurrencyCodeEUR), 53 | @"SMPCurrencyCodeGBP" : (SMPCurrencyCodeGBP), 54 | @"SMPCurrencyCodeHUF" : (SMPCurrencyCodeHUF), 55 | @"SMPCurrencyCodeNOK" : (SMPCurrencyCodeNOK), 56 | @"SMPCurrencyCodePLN" : (SMPCurrencyCodePLN), 57 | @"SMPCurrencyCodeRON" : (SMPCurrencyCodeRON), 58 | @"SMPCurrencyCodeSEK" : (SMPCurrencyCodeSEK), 59 | @"SMPCurrencyCodeUSD" : (SMPCurrencyCodeUSD)}; 60 | } 61 | 62 | RCT_EXPORT_METHOD(setup:(NSString *)key resolver:(RCTPromiseResolveBlock)resolve 63 | rejecter:(RCTPromiseRejectBlock)reject) 64 | { 65 | BOOL setupResponse = [SMPSumUpSDK setupWithAPIKey:key]; 66 | if (setupResponse) { 67 | resolve(nil); 68 | } else { 69 | reject(@"000", @"It was not possible to complete setup with SumUp SDK. Please, check your implementation.", nil); 70 | } 71 | } 72 | 73 | RCT_EXPORT_METHOD(authenticate:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 74 | { 75 | dispatch_sync(dispatch_get_main_queue(), ^{ 76 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 77 | while (rootViewController.presentedViewController != nil) { 78 | rootViewController = rootViewController.presentedViewController; 79 | } 80 | [SMPSumUpSDK presentLoginFromViewController:rootViewController animated:YES completionBlock:^(BOOL success, NSError *error) { 81 | if (error) { 82 | [rootViewController dismissViewControllerAnimated:YES completion:nil]; 83 | reject(@"000", @"It was not possible to auth with SumUp. Please, check the username and password provided.", error); 84 | } else { 85 | SMPMerchant *merchantInfo = [SMPSumUpSDK currentMerchant]; 86 | NSString *merchantCode = [merchantInfo merchantCode]; 87 | NSString *currencyCode = [merchantInfo currencyCode]; 88 | if (merchantCode && currencyCode){ 89 | return resolve(@{@"success": @(success), @"userAdditionalInfo": @{ @"merchantCode": merchantCode, @"currencyCode": currencyCode }}); 90 | } 91 | return resolve(@{@"success": @(success) }); 92 | } 93 | }]; 94 | }); 95 | } 96 | 97 | RCT_EXPORT_METHOD(authenticateWithToken:(NSString *)token resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 98 | { 99 | BOOL isLoggedIn = [SMPSumUpSDK isLoggedIn]; 100 | if (isLoggedIn) { 101 | resolve(nil); 102 | } else { 103 | NSString *aToken = token; 104 | [SMPSumUpSDK loginWithToken:aToken completion:^(BOOL success, NSError * _Nullable error) { 105 | if (!success) { 106 | reject(@"004", @"It was not possible to login with SumUp using a token. Please, try again.", nil); 107 | } else { 108 | resolve(nil); 109 | } 110 | }]; 111 | } 112 | } 113 | 114 | RCT_EXPORT_METHOD(logout:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 115 | { 116 | [SMPSumUpSDK logoutWithCompletionBlock:^(BOOL success, NSError * _Nullable error) { 117 | if (!success) { 118 | reject(@"004", @"It was not possible to log out with SumUp. Please, try again.", nil); 119 | } else { 120 | resolve(nil); 121 | } 122 | }]; 123 | } 124 | 125 | RCT_EXPORT_METHOD(prepareForCheckout:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 126 | { 127 | BOOL isLoggedIn = [SMPSumUpSDK isLoggedIn]; 128 | if (isLoggedIn) { 129 | [SMPSumUpSDK prepareForCheckout]; 130 | resolve(nil); 131 | } else { 132 | reject(@"003", @"It was not possible to prepare for checkout. Please, log in first.", nil); 133 | } 134 | } 135 | 136 | RCT_EXPORT_METHOD(checkout:(NSDictionary *)request resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 137 | { 138 | NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString:[RCTConvert NSString:request[@"totalAmount"]]]; 139 | NSString *title = [RCTConvert NSString:request[@"title"]]; 140 | NSString *currencyCode = [RCTConvert NSString:request[@"currencyCode"]]; 141 | NSUInteger paymentOption = [RCTConvert SMPPaymentOptions:request[@"paymentOption"]]; 142 | NSUInteger skipScreen = [RCTConvert SMPSkipScreenOptions:@"1"]; 143 | NSString *foreignTransactionID = [RCTConvert NSString:[request objectForKeyNotNull:@"foreignTransactionId"]]; 144 | 145 | SMPCheckoutRequest *checkoutRequest = [SMPCheckoutRequest requestWithTotal:total 146 | title:title 147 | currencyCode:[[SMPSumUpSDK currentMerchant] currencyCode] 148 | paymentOptions:paymentOption]; 149 | checkoutRequest.skipScreenOptions = skipScreen; 150 | if (foreignTransactionID != nil) { 151 | [checkoutRequest setForeignTransactionID:foreignTransactionID]; 152 | } 153 | 154 | dispatch_sync(dispatch_get_main_queue(), ^{ 155 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 156 | while (rootViewController.presentedViewController != nil) { 157 | rootViewController = rootViewController.presentedViewController; 158 | } 159 | [SMPSumUpSDK checkoutWithRequest:checkoutRequest 160 | fromViewController:rootViewController 161 | completion:^(SMPCheckoutResult *result, NSError *error) { 162 | if (error) { 163 | reject(@"001", @"It was not possible to perform checkout with SumUp. Please, try again.", error); 164 | } else { 165 | NSDictionary *additionalInformation = [result additionalInfo]; 166 | if (additionalInformation == nil) { 167 | reject(@"001", @"It was not possible to perform checkout with SumUp. Please, try again.", error); 168 | } else { 169 | NSString *cardType = [additionalInformation valueForKeyPath:@"card.type"]; 170 | NSString *cardLast4Digits = [additionalInformation valueForKeyPath:@"card.last_4_digits"]; 171 | NSString *installments = [additionalInformation valueForKeyPath:@"installments"]; 172 | 173 | resolve(@{@"success": @([result success]), @"transactionCode": [result transactionCode], @"additionalInfo": @{ @"cardType": cardType, @"cardLast4Digits": cardLast4Digits, @"installments": installments }}); 174 | } 175 | } 176 | }]; 177 | }); 178 | } 179 | 180 | RCT_EXPORT_METHOD(preferences:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 181 | { 182 | dispatch_sync(dispatch_get_main_queue(), ^{ 183 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 184 | while (rootViewController.presentedViewController != nil) { 185 | rootViewController = rootViewController.presentedViewController; 186 | } 187 | [SMPSumUpSDK presentCheckoutPreferencesFromViewController:rootViewController 188 | animated:YES 189 | completion:^(BOOL success, NSError * _Nullable error) { 190 | if (success) { 191 | resolve(nil); 192 | } else { 193 | reject(@"002", @"It was not possible to open Preferences window. Please, try again.", nil); 194 | } 195 | }]; 196 | }); 197 | } 198 | 199 | RCT_EXPORT_METHOD(isLoggedIn:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 200 | { 201 | BOOL isLoggedIn = [SMPSumUpSDK isLoggedIn]; 202 | resolve(@{@"isLoggedIn": @(isLoggedIn)}); 203 | } 204 | 205 | 206 | RCT_EXPORT_MODULE(); 207 | 208 | @end 209 | 210 | -------------------------------------------------------------------------------- /android/src/main/java/com/nextar/sumup/RNSumUpModule.java: -------------------------------------------------------------------------------- 1 | package com.nextar.sumup; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.widget.Toast; 7 | 8 | import com.facebook.react.bridge.ActivityEventListener; 9 | import com.facebook.react.bridge.Arguments; 10 | import com.facebook.react.bridge.BaseActivityEventListener; 11 | import com.facebook.react.bridge.Promise; 12 | import com.facebook.react.bridge.ReactApplicationContext; 13 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 14 | import com.facebook.react.bridge.ReactMethod; 15 | import com.facebook.react.bridge.ReadableMap; 16 | import com.facebook.react.bridge.WritableMap; 17 | import com.sumup.merchant.reader.models.TransactionInfo; 18 | import com.sumup.merchant.reader.api.SumUpAPI; 19 | import com.sumup.merchant.reader.api.SumUpLogin; 20 | import com.sumup.merchant.reader.api.SumUpPayment; 21 | import com.sumup.merchant.reader.ReaderModuleCoreState; 22 | import com.sumup.merchant.reader.identitylib.models.IdentityModel; 23 | 24 | import java.math.BigDecimal; 25 | import java.math.RoundingMode; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | import java.util.UUID; 29 | 30 | /** 31 | * Created by Robert Suman on 22/02/2018. 32 | * Updated by Ítalo Menezes :) 33 | */ 34 | 35 | public class RNSumUpModule extends ReactContextBaseJavaModule { 36 | 37 | private static final int REQUEST_CODE_LOGIN = 1; 38 | private static final int REQUEST_CODE_PAYMENT = 2; 39 | private static final int REQUEST_CODE_PAYMENT_SETTINGS = 3; 40 | private static final int TRANSACTION_SUCCESSFUL = 1; 41 | 42 | private static final String SMPCurrencyCodeBGN = "SMPCurrencyCodeBGN"; 43 | private static final String SMPCurrencyCodeBRL = "SMPCurrencyCodeBRL"; 44 | private static final String SMPCurrencyCodeCHF = "SMPCurrencyCodeCHF"; 45 | private static final String SMPCurrencyCodeCLP = "SMPCurrencyCodeCLP"; 46 | private static final String SMPCurrencyCodeCZK = "SMPCurrencyCodeCZK"; 47 | private static final String SMPCurrencyCodeDKK = "SMPCurrencyCodeDKK"; 48 | private static final String SMPCurrencyCodeEUR = "SMPCurrencyCodeEUR"; 49 | private static final String SMPCurrencyCodeGBP = "SMPCurrencyCodeGBP"; 50 | private static final String SMPCurrencyCodeHUF = "SMPCurrencyCodeHUF"; 51 | private static final String SMPCurrencyCodeNOK = "SMPCurrencyCodeNOK"; 52 | private static final String SMPCurrencyCodePLN = "SMPCurrencyCodePLN"; 53 | private static final String SMPCurrencyCodeRON = "SMPCurrencyCodeRON"; 54 | private static final String SMPCurrencyCodeSEK = "SMPCurrencyCodeSEK"; 55 | private static final String SMPCurrencyCodeUSD = "SMPCurrencyCodeUSD"; 56 | 57 | private Promise mSumUpPromise; 58 | 59 | public RNSumUpModule(ReactApplicationContext reactContext) { 60 | super(reactContext); 61 | reactContext.addActivityEventListener(mActivityEventListener); 62 | } 63 | 64 | @Override 65 | public String getName() { 66 | return "RNSumUp"; 67 | } 68 | 69 | @Override 70 | public Map getConstants() { 71 | final Map constants = new HashMap<>(); 72 | constants.put("SMPCurrencyCodeBGN", SMPCurrencyCodeBGN); 73 | constants.put("SMPCurrencyCodeBRL", SMPCurrencyCodeBRL); 74 | constants.put("SMPCurrencyCodeCHF", SMPCurrencyCodeCHF); 75 | constants.put("SMPCurrencyCodeCLP", SMPCurrencyCodeCLP); 76 | constants.put("SMPCurrencyCodeCZK", SMPCurrencyCodeCZK); 77 | constants.put("SMPCurrencyCodeDKK", SMPCurrencyCodeDKK); 78 | constants.put("SMPCurrencyCodeEUR", SMPCurrencyCodeEUR); 79 | constants.put("SMPCurrencyCodeGBP", SMPCurrencyCodeGBP); 80 | constants.put("SMPCurrencyCodeHUF", SMPCurrencyCodeHUF); 81 | constants.put("SMPCurrencyCodeNOK", SMPCurrencyCodeNOK); 82 | constants.put("SMPCurrencyCodePLN", SMPCurrencyCodePLN); 83 | constants.put("SMPCurrencyCodeRON", SMPCurrencyCodeRON); 84 | constants.put("SMPCurrencyCodeSEK", SMPCurrencyCodeSEK); 85 | constants.put("SMPCurrencyCodeUSD", SMPCurrencyCodeUSD); 86 | return constants; 87 | } 88 | 89 | @ReactMethod 90 | public void authenticate(String affiliateKey, Promise promise) { 91 | mSumUpPromise = promise; 92 | SumUpLogin sumupLogin = SumUpLogin.builder(affiliateKey).build(); 93 | SumUpAPI.openLoginActivity(getCurrentActivity(), sumupLogin, REQUEST_CODE_LOGIN); 94 | } 95 | 96 | @ReactMethod 97 | public void authenticateWithToken(String affiliateKey, String token, Promise promise) { 98 | mSumUpPromise = promise; 99 | SumUpLogin sumupLogin = SumUpLogin.builder(affiliateKey).accessToken(token).build(); 100 | SumUpAPI.openLoginActivity(getCurrentActivity(), sumupLogin, REQUEST_CODE_LOGIN); 101 | } 102 | 103 | @ReactMethod 104 | public void prepareForCheckout(Promise promise) { 105 | mSumUpPromise = promise; 106 | SumUpAPI.prepareForCheckout(); 107 | } 108 | 109 | @ReactMethod 110 | public void logout(Promise promise) { 111 | mSumUpPromise = promise; 112 | SumUpAPI.logout(); 113 | mSumUpPromise.resolve(true); 114 | } 115 | 116 | private SumUpPayment.Currency getCurrency(String currency) { 117 | switch (currency) { 118 | case SMPCurrencyCodeBGN: return SumUpPayment.Currency.BGN; 119 | case SMPCurrencyCodeBRL: return SumUpPayment.Currency.BRL; 120 | case SMPCurrencyCodeCHF: return SumUpPayment.Currency.CHF; 121 | case SMPCurrencyCodeCLP: return SumUpPayment.Currency.CLP; 122 | case SMPCurrencyCodeCZK: return SumUpPayment.Currency.CZK; 123 | case SMPCurrencyCodeDKK: return SumUpPayment.Currency.DKK; 124 | case SMPCurrencyCodeEUR: return SumUpPayment.Currency.EUR; 125 | case SMPCurrencyCodeGBP: return SumUpPayment.Currency.GBP; 126 | case SMPCurrencyCodeHUF: return SumUpPayment.Currency.HUF; 127 | case SMPCurrencyCodeNOK: return SumUpPayment.Currency.NOK; 128 | case SMPCurrencyCodePLN: return SumUpPayment.Currency.PLN; 129 | case SMPCurrencyCodeRON: return SumUpPayment.Currency.RON; 130 | case SMPCurrencyCodeSEK: return SumUpPayment.Currency.SEK; 131 | default: case SMPCurrencyCodeUSD: return SumUpPayment.Currency.USD; 132 | } 133 | } 134 | 135 | @ReactMethod 136 | public void checkout(ReadableMap request, Promise promise) { 137 | // TODO: replace foreignTransactionId for transaction UUID sent by user. 138 | mSumUpPromise = promise; 139 | try { 140 | String foreignTransactionId = UUID.randomUUID().toString(); 141 | if (request.hasKey("foreignTransactionId")) { 142 | foreignTransactionId = request.getString("foreignTransactionId"); 143 | } 144 | 145 | SumUpPayment.Currency currencyCode = this.getCurrency(request.getString("currencyCode")); 146 | SumUpPayment.Builder payment = SumUpPayment.builder() 147 | .total(new BigDecimal(request.getString("totalAmount")).setScale(2, RoundingMode.HALF_EVEN)) 148 | .currency(currencyCode) 149 | .title(request.getString("title")) 150 | .foreignTransactionId(foreignTransactionId); 151 | if (!request.hasKey("receiptSMS") && !request.hasKey("receiptEmail")) { 152 | payment = payment.skipSuccessScreen(); 153 | } 154 | if (request.hasKey("receiptEmail")) { 155 | payment = payment.receiptEmail(request.getString("receiptEmail")); 156 | } 157 | if (request.hasKey("receiptSMS")) { 158 | payment = payment.receiptSMS(request.getString("receiptSMS")); 159 | } 160 | 161 | SumUpAPI.checkout(getCurrentActivity(), payment.build(), REQUEST_CODE_PAYMENT); 162 | } catch (Exception ex) { 163 | mSumUpPromise.reject(ex); 164 | mSumUpPromise = null; 165 | } 166 | } 167 | 168 | @ReactMethod 169 | public void preferences(Promise promise) { 170 | mSumUpPromise = promise; 171 | SumUpAPI.openPaymentSettingsActivity(getCurrentActivity(), REQUEST_CODE_PAYMENT_SETTINGS); 172 | } 173 | 174 | @ReactMethod 175 | public void isLoggedIn(Promise promise) { 176 | promise.resolve(SumUpAPI.isLoggedIn()); 177 | } 178 | 179 | private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { 180 | 181 | @Override 182 | public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { 183 | switch (requestCode) { 184 | case REQUEST_CODE_LOGIN: 185 | if (data != null) { 186 | Bundle extra = data.getExtras(); 187 | if (extra.getInt(SumUpAPI.Response.RESULT_CODE) == REQUEST_CODE_LOGIN) { 188 | WritableMap map = Arguments.createMap(); 189 | map.putBoolean("success", true); 190 | 191 | IdentityModel userInfo = ReaderModuleCoreState.Instance().get(IdentityModel.class); 192 | WritableMap userAdditionalInfo = Arguments.createMap(); 193 | userAdditionalInfo.putString("merchantCode", userInfo.getBusiness().getMerchantCode()); 194 | userAdditionalInfo.putString("currencyCode", userInfo.getBusiness().getCountry().getCurrency().getCode()); 195 | map.putMap("userAdditionalInfo", userAdditionalInfo); 196 | 197 | mSumUpPromise.resolve(map); 198 | } else { 199 | mSumUpPromise.reject(extra.getString(SumUpAPI.Response.RESULT_CODE), extra.getString(SumUpAPI.Response.MESSAGE)); 200 | } 201 | } else { 202 | mSumUpPromise.reject(""); 203 | } 204 | break; 205 | 206 | case REQUEST_CODE_PAYMENT: 207 | if (data != null) { 208 | Bundle extra = data.getExtras(); 209 | if (mSumUpPromise != null) { 210 | if (extra.getInt(SumUpAPI.Response.RESULT_CODE) == TRANSACTION_SUCCESSFUL) { 211 | WritableMap map = Arguments.createMap(); 212 | map.putBoolean("success", true); 213 | map.putString("transactionCode", extra.getString(SumUpAPI.Response.TX_CODE)); 214 | 215 | TransactionInfo transactionInfo = extra.getParcelable(SumUpAPI.Response.TX_INFO); 216 | WritableMap additionalInfo = Arguments.createMap(); 217 | additionalInfo.putString("cardType", transactionInfo.getCard().getType()); 218 | additionalInfo.putString("cardLast4Digits", transactionInfo.getCard().getLast4Digits()); 219 | additionalInfo.putInt("installments", transactionInfo.getInstallments()); 220 | map.putMap("additionalInfo", additionalInfo); 221 | 222 | mSumUpPromise.resolve(map); 223 | }else 224 | mSumUpPromise.reject(extra.getString(SumUpAPI.Response.RESULT_CODE), extra.getString(SumUpAPI.Response.MESSAGE)); 225 | } 226 | } 227 | break; 228 | case REQUEST_CODE_PAYMENT_SETTINGS: 229 | WritableMap map = Arguments.createMap(); 230 | map.putBoolean("success", true); 231 | mSumUpPromise.resolve(map); 232 | break; 233 | default: 234 | break; 235 | } 236 | } 237 | 238 | }; 239 | } 240 | --------------------------------------------------------------------------------