From fa223f2c3142b73241f4ed21c4801f67c90f71b1 Mon Sep 17 00:00:00 2001 From: Zac Demi Date: Tue, 15 Feb 2022 18:46:07 -0800 Subject: [PATCH 1/6] update build.gradle for > Gradle 3.0.0 and later --- android/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 84a0ab9..8490e8c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -12,12 +12,12 @@ buildscript { apply plugin: 'com.android.library' android { - compileSdkVersion 28 + compileSdkVersion 30 buildToolsVersion "28.0.3" defaultConfig { - minSdkVersion 16 - targetSdkVersion 22 + minSdkVersion 24 + targetSdkVersion 30 versionCode 1 versionName "1.0" } @@ -31,7 +31,7 @@ repositories { } dependencies { - compile 'com.facebook.react:react-native:+' - compile 'com.squareup.sdk:point-of-sale-sdk:2.+' + implementation 'com.facebook.react:react-native:+' + implementation 'com.squareup.sdk:point-of-sale-sdk:2.+' } \ No newline at end of file From 4a1f1adfc994dabc2e313fc31d24d2e527d8cbc4 Mon Sep 17 00:00:00 2001 From: Zac Demi Date: Tue, 15 Feb 2022 18:46:46 -0800 Subject: [PATCH 2/6] update for Android 11 or newer --- android/src/main/AndroidManifest.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index f6cfe39..bb22ded 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ - + package="io.matix"> + + + \ No newline at end of file From 799731057462f7aebd1ab458a81d98594e1ebb93 Mon Sep 17 00:00:00 2001 From: Zac Demi Date: Tue, 15 Feb 2022 18:53:38 -0800 Subject: [PATCH 3/6] minsdk to 16 --- android/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 8490e8c..8436987 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -16,7 +16,7 @@ android { buildToolsVersion "28.0.3" defaultConfig { - minSdkVersion 24 + minSdkVersion 16 targetSdkVersion 30 versionCode 1 versionName "1.0" @@ -34,4 +34,4 @@ dependencies { implementation 'com.facebook.react:react-native:+' implementation 'com.squareup.sdk:point-of-sale-sdk:2.+' } - \ No newline at end of file + From c0067872cbec36d7a2ba6667a806225f0e9c0828 Mon Sep 17 00:00:00 2001 From: Zac Demi Date: Wed, 16 Feb 2022 08:53:26 -0800 Subject: [PATCH 4/6] update to latest ios sdk --- RNSquarePos.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RNSquarePos.podspec b/RNSquarePos.podspec index 17c5938..56e7aa4 100644 --- a/RNSquarePos.podspec +++ b/RNSquarePos.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "RNSquarePos" - s.version = "1.0.13" + s.version = "1.1.0" s.summary = "RNSquarePos" s.description = <<-DESC RNSquarePos @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.license = "MIT" # s.license = { :type => "MIT", :file => "FILE_LICENSE" } s.author = { "author" => "connor@matix.io" } - s.platform = :ios, "7.0" + s.platform = :ios, "12.0" s.source = { :git => "https://github.com/matix-io/react-native-square-pos.git", :tag => "master" } s.source_files = "ios/**/*.{h,m}" s.requires_arc = true From 2961ea50daa8ce57482ae3a04a94062ddd054208 Mon Sep 17 00:00:00 2001 From: Zac Demi Date: Mon, 21 Feb 2022 07:26:10 -0800 Subject: [PATCH 5/6] gift card support ios --- ios/RNSquarePos.m | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ios/RNSquarePos.m b/ios/RNSquarePos.m index 6496c08..dc0ad99 100644 --- a/ios/RNSquarePos.m +++ b/ios/RNSquarePos.m @@ -46,6 +46,8 @@ @implementation RNSquarePos currType = SCCAPIRequestTenderTypeCash; } else if ([tenderType isEqualToString:@"CARD"]) { currType = SCCAPIRequestTenderTypeCard; + } else if ([tenderType isEqualToString:@"GIFT_CARD"]) { + currType = SCCAPIRequestTenderTypeSquareGiftCard; } else if ([tenderType isEqualToString:@"CARD_ON_FILE"]) { currType = SCCAPIRequestTenderTypeCardOnFile; } else if ([tenderType isEqualToString:@"OTHER"]) { diff --git a/package.json b/package.json index feb5b72..1427897 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-square-pos", - "version": "1.1.2", + "version": "1.1.3", "description": "React Native wrapper around Square's Android / iOS POS SDKs", "main": "index.js", "scripts": { From fb52ed6476a06947aba51543ad424652c410a258 Mon Sep 17 00:00:00 2001 From: Zac Demi Date: Wed, 1 Nov 2023 15:30:31 -0400 Subject: [PATCH 6/6] Update for React 72 -Replace depreciated DeviceEventEmitter with NativeEventEmitter (Android) -Replace depreciated removeEventListener with remove (iOS) --- index.js | 248 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 134 insertions(+), 114 deletions(-) diff --git a/index.js b/index.js index 1f2854d..8d31869 100644 --- a/index.js +++ b/index.js @@ -1,130 +1,150 @@ -import { NativeModules, DeviceEventEmitter, Platform, Linking } from 'react-native' -const SquarePOS = NativeModules.RNSquarePos +import { + NativeEventEmitter, + NativeModules, + Platform, + Linking, +} from "react-native"; +const SquarePOS = NativeModules.RNSquarePos; -let callbackUrl +let callbackUrl; const errors = { - CANNOT_OPEN_SQUARE: 'CANNOT_OPEN_SQUARE', - UNKNOWN_IOS_ERROR: 'UNKNOWN_IOS_ERROR', - UNKNOWN_ANDROID_ERROR: 'UNKNOWN_ANDROID_ERROR', - PAYMENT_CANCELLED: 'PAYMENT_CANCELLED', - NOT_LOGGED_IN: 'NOT_LOGGED_IN', - USER_NOT_ACTIVE: 'USER_NOT_ACTIVE', - AMOUNT_TOO_SMALL: 'AMOUNT_TOO_SMALL', - AMOUNT_TOO_LARGE: 'AMOUNT_TOO_LARGE', - INVALID_TENDER_TYPE: 'INVALID_TENDER_TYPE', - UNSUPPORTED_TENDER_TYPE: 'UNSUPPORTED_TENDER_TYPE', - NO_NETWORK_CONNECTION: 'NO_NETWORK_CONNECTION', - TRANSACTION_ALREADY_IN_PROGRESS: 'TRANSACTION_ALREADY_IN_PROGRESS', - INVALID_REQUEST: 'INVALID_REQUEST', -} + CANNOT_OPEN_SQUARE: "CANNOT_OPEN_SQUARE", + UNKNOWN_IOS_ERROR: "UNKNOWN_IOS_ERROR", + UNKNOWN_ANDROID_ERROR: "UNKNOWN_ANDROID_ERROR", + PAYMENT_CANCELLED: "PAYMENT_CANCELLED", + NOT_LOGGED_IN: "NOT_LOGGED_IN", + USER_NOT_ACTIVE: "USER_NOT_ACTIVE", + AMOUNT_TOO_SMALL: "AMOUNT_TOO_SMALL", + AMOUNT_TOO_LARGE: "AMOUNT_TOO_LARGE", + INVALID_TENDER_TYPE: "INVALID_TENDER_TYPE", + UNSUPPORTED_TENDER_TYPE: "UNSUPPORTED_TENDER_TYPE", + NO_NETWORK_CONNECTION: "NO_NETWORK_CONNECTION", + TRANSACTION_ALREADY_IN_PROGRESS: "TRANSACTION_ALREADY_IN_PROGRESS", + INVALID_REQUEST: "INVALID_REQUEST", +}; const iosErrors = { - payment_canceled: errors.PAYMENT_CANCELLED, - not_logged_in: errors.NOT_LOGGED_IN, - user_not_active: errors.USER_NOT_ACTIVE, - amount_too_small: errors.AMOUNT_TOO_SMALL, - amount_too_large: errors.AMOUNT_TOO_LARGE, - invalid_tender_type: errors.INVALID_TENDER_TYPE, - unsupported_tender_type: errors.UNSUPPORTED_TENDER_TYPE, - no_network_connection: errors.NO_NETWORK_CONNECTION, -} + payment_canceled: errors.PAYMENT_CANCELLED, + not_logged_in: errors.NOT_LOGGED_IN, + user_not_active: errors.USER_NOT_ACTIVE, + amount_too_small: errors.AMOUNT_TOO_SMALL, + amount_too_large: errors.AMOUNT_TOO_LARGE, + invalid_tender_type: errors.INVALID_TENDER_TYPE, + unsupported_tender_type: errors.UNSUPPORTED_TENDER_TYPE, + no_network_connection: errors.NO_NETWORK_CONNECTION, +}; const androidErrors = { - TRANSACTION_CANCELED: errors.PAYMENT_CANCELLED, - USER_NOT_LOGGED_IN: errors.NOT_LOGGED_IN, - USER_NOT_ACTIVATED: errors.USER_NOT_ACTIVE, - NO_NETWORK: errors.NO_NETWORK_CONNECTION, - TRANSACTION_ALREADY_IN_PROGRESS: errors.TRANSACTION_ALREADY_IN_PROGRESS, - INVALID_REQUEST: errors.INVALID_REQUEST, -} + TRANSACTION_CANCELED: errors.PAYMENT_CANCELLED, + USER_NOT_LOGGED_IN: errors.NOT_LOGGED_IN, + USER_NOT_ACTIVATED: errors.USER_NOT_ACTIVE, + NO_NETWORK: errors.NO_NETWORK_CONNECTION, + TRANSACTION_ALREADY_IN_PROGRESS: errors.TRANSACTION_ALREADY_IN_PROGRESS, + INVALID_REQUEST: errors.INVALID_REQUEST, +}; const RNSquarePos = { - ERRORS: errors, - configure: (options) => { - SquarePOS.setApplicationId(options.applicationId) - callbackUrl = options.callbackUrl - }, - transaction: (amount, currency, options = {}) => { - return new Promise((resolve, reject) => { - if (Platform.OS === 'android') { - SquarePOS.startTransaction(amount, currency, options, () => { - return reject({ - errorCode: errors.CANNOT_OPEN_SQUARE - }) - }) + ERRORS: errors, + configure: (options) => { + SquarePOS.setApplicationId(options.applicationId); + callbackUrl = options.callbackUrl; + }, + transaction: (amount, currency, options = {}) => { + let subscription = null; + return new Promise((resolve, reject) => { + if (Platform.OS === "android") { + SquarePOS.startTransaction(amount, currency, options, () => { + return reject({ + errorCode: errors.CANNOT_OPEN_SQUARE, + }); + }); - function handleResponse(data) { - DeviceEventEmitter.removeListener('RNSquarePOSResponse', handleResponse); - if (data.errorCode) { - if (androidErrors[data.errorCode]) { - return reject({ - errorCode: androidErrors[data.errorCode], - squareResponse: data - }) - } else { - return reject({ - errorCode: errors.UNKNOWN_ANDROID_ERROR, - originalCode: data.errorCode, - squareResponse: data - }) - } - } else { - return resolve(data) - } - } + function handleResponse(data) { + subscription.remove(); + subscription = null; + if (data.errorCode) { + if (androidErrors[data.errorCode]) { + return reject({ + errorCode: androidErrors[data.errorCode], + squareResponse: data, + }); + } else { + return reject({ + errorCode: errors.UNKNOWN_ANDROID_ERROR, + originalCode: data.errorCode, + squareResponse: data, + }); + } + } else { + return resolve(data); + } + } + const eventEmitter = new NativeEventEmitter(SquarePOS); + subscription = eventEmitter.addListener( + "RNSquarePOSResponse", + handleResponse + ); + } else if (Platform.OS === "ios") { + SquarePOS.startTransaction( + amount, + currency, + options, + callbackUrl, + (errorCode, errorDescription) => { + switch (errorCode) { + case 6: + reject({ + errorCode: errors.CANNOT_OPEN_SQUARE, + }); + break; - DeviceEventEmitter.addListener('RNSquarePOSResponse', handleResponse); - } else if (Platform.OS === 'ios') { - SquarePOS.startTransaction(amount, currency, options, callbackUrl, (errorCode, errorDescription) => { - switch (errorCode) { - case 6: - reject({ - errorCode: errors.CANNOT_OPEN_SQUARE - }) - break + default: + reject({ + errorCode: errors.UNKNOWN_IOS_ERROR, + errorDescription, + }); + break; + } + } + ); - default: - reject({ - errorCode: errors.UNKNOWN_IOS_ERROR, - errorDescription - }) - break - } - }) + function handleIOSResponse(event) { + const url = event.url; + subscription.remove(); + subscription = null; - function handleIOSResponse(event) { - Linking.removeEventListener('url', handleIOSResponse); - const url = event.url + if (url.match(callbackUrl)) { + const data = JSON.parse( + decodeURIComponent(url.split("?data=")[1]) + ); - if (url.match(callbackUrl)) { - const data = JSON.parse(decodeURIComponent(url.split('?data=')[1])) - - if (data.error_code) { - if (iosErrors[data.error_code]) { - return reject({ - errorCode: iosErrors[data.error_code] - }) - } else { - return reject({ - errorCode: errors.UNKNOWN_IOS_ERROR, - originalCode: data.error_code - }) - } - } else { - return resolve({ - transactionId: data.transaction_id, - clientTransactionId: data.client_transaction_id - }) - } - } - } - - Linking.addEventListener('url', handleIOSResponse); - } - }) - }, -} + if (data.error_code) { + if (iosErrors[data.error_code]) { + return reject({ + errorCode: iosErrors[data.error_code], + }); + } else { + return reject({ + errorCode: errors.UNKNOWN_IOS_ERROR, + originalCode: data.error_code, + }); + } + } else { + return resolve({ + transactionId: data.transaction_id, + clientTransactionId: data.client_transaction_id, + }); + } + } + } + subscription = Linking.addEventListener( + "url", + handleIOSResponse + ); + } + }); + }, +}; export default RNSquarePos; -