├── LICENSE ├── README.md ├── RNSumup ├── RNSumup.h └── RNSumup.m ├── index.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 APSL 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-sumup 2 | 3 | A React Native implementation of SumupSDK. 4 | 5 |

6 | Sumup Login 7 |

8 | 9 | ## Installation 10 | 11 | First install the iOS Sumup SDK, [instructions here](https://github.com/sumup/sumup-ios-sdk#preparing-your-xcode-project). 12 | 13 | Then, ``npm install react-native-sumup --save`` and add ``RNSumup.h`` and ``RNSumup.m`` to your project. Check that the ``*.m`` file is under **Compile Sources**. 14 | 15 | ## Compatibility 16 | 17 | This library has been tested with Sumup iOS SDK version **1.2.2**. 18 | 19 | ## Example usage 20 | ```javascript 21 | import Sumup from 'react-native-sumup' 22 | // Setup Sumup 23 | Sumup.setupWithAPIKey('API_KEY') 24 | // Open login 25 | Sumup.presentLoginFromViewController() 26 | .then(response => { 27 | console.log('Response', response) 28 | }) 29 | .catch(error => { 30 | console.log('error', error) 31 | }) 32 | 33 | // Checkout 34 | let request = { 35 | totalAmount: '20.0', 36 | title: 'Test', 37 | currencyCode: 'EUR', 38 | paymentOption: Sumup.paymentOptionMobilePayment 39 | } 40 | Sumup.checkoutWithRequest(request) 41 | .then(response) => { 42 | console.log('Response', response) 43 | }) 44 | .catch(error) => { 45 | console.log('Error', error) 46 | }) 47 | ``` 48 | 49 | ## API 🚧 50 | 51 | This library is still a work in progress, only some methods have been implemented. Please feel free to open any issues if you need another SDK method implemented. 52 | 53 | | Method | Params | Description | 54 | |--------|--------|-------------| 55 | | ``setupWithAPIKey `` | ``apiKey``: String | Method to initialize SumupSDK. | 56 | | ``presentLoginFromViewController`` | ``completionBlock``: function | Opens a Sumup login view. | 57 | | ``checkoutWithRequest`` | ``request``: Object, ``completionBlock(response)``: function, ``errorBlock(error)``: function | Creates a Sumup payment request. | 58 | | `isLoggedIn` | | Returns `true` if the user has logged-in into the SDK. | 59 | 60 | ### ``Request`` param 61 | 62 | | Param | Type | Description | 63 | |-------|-------|-------------| 64 | | ``totalAmount`` | ``string`` | Will be parsed as ``decimalNumber``. | 65 | | ``title`` | ``string`` | | 66 | | ``currencyCode`` | ``string`` | | 67 | | ``paymentOption`` | ``SMPPaymentOptions`` | An enum of type ``SMPPaymentOptions``. Possible values: ``SMPPaymentOptionAny``, ``SMPPaymentOptionCardReader``, ``SMPPaymentOptionMobilePayment``. | 68 | 69 | ## License 70 | 71 | MIT. 72 | 73 | ## Development sponsor 74 | 75 | This development has been sponsored by [SupSpot](http://supspot.ch). 76 | -------------------------------------------------------------------------------- /RNSumup/RNSumup.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNSumup.h 3 | // RNSumup 4 | // 5 | // Created by Alvaro Medina Ballester on 11/02/16. 6 | // Copyright © 2016 APSL. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface RNSumup : NSObject 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /RNSumup/RNSumup.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNSumup.m 3 | // RNSumup 4 | // 5 | // Created by Alvaro Medina Ballester on 11/02/16. 6 | // Copyright © 2016 APSL. All rights reserved. 7 | // 8 | 9 | 10 | #import "RNSumup.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 RNSumup 23 | 24 | RCT_EXPORT_MODULE(); 25 | 26 | - (NSDictionary *)constantsToExport 27 | { 28 | return @{ @"SMPPaymentOptionAny": @(SMPPaymentOptionAny), 29 | @"SMPPaymentOptionCardReader": @(SMPPaymentOptionCardReader), 30 | @"SMPPaymentOptionMobilePayment": @(SMPPaymentOptionMobilePayment)}; 31 | } 32 | 33 | RCT_EXPORT_METHOD(setupWithAPIKey:(NSString *)apiKey completionBlock:(RCTPromiseResolveBlock)completionBlock errorBlock:(RCTPromiseRejectBlock)errorBlock) 34 | { 35 | BOOL successfulSetup = [SumupSDK setupWithAPIKey:apiKey]; 36 | if (successfulSetup) { 37 | completionBlock(nil); 38 | } else { 39 | errorBlock(@"000", @"Error setting up SumupSDK", nil); 40 | } 41 | } 42 | 43 | RCT_EXPORT_METHOD(presentLoginFromViewController:(RCTPromiseResolveBlock)completionBlock error:(RCTPromiseRejectBlock)errorBlock) 44 | { 45 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 46 | dispatch_sync(dispatch_get_main_queue(), ^{ 47 | [SumupSDK presentLoginFromViewController:rootViewController 48 | animated:YES 49 | completionBlock:^(BOOL success, NSError *error) { 50 | if (error) { 51 | // Force view controller dismissal to avoid a RN error for the completion block 52 | [rootViewController dismissViewControllerAnimated:YES completion:nil]; 53 | errorBlock(@"001", @"Error authenticating", error); 54 | } else { 55 | completionBlock(@{@"success": @(success)}); 56 | } 57 | }]; 58 | }); 59 | } 60 | 61 | RCT_EXPORT_METHOD(checkoutWithRequest:(NSDictionary *)request completionBlock:(RCTPromiseResolveBlock)completionBlock errorBlock:(RCTPromiseRejectBlock)errorBlock) 62 | { 63 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 64 | NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString:[RCTConvert NSString:request[@"totalAmount"]]]; 65 | NSString *title = [RCTConvert NSString:request[@"title"]]; 66 | NSString *currencyCode = [RCTConvert NSString:request[@"currencyCode"]]; 67 | NSUInteger paymentOption = [RCTConvert SMPPaymentOptions:request[@"paymentOption"]]; 68 | SMPCheckoutRequest *checkoutRequest = [SMPCheckoutRequest requestWithTotal:total 69 | title:title 70 | currencyCode:currencyCode 71 | paymentOptions:paymentOption]; 72 | dispatch_sync(dispatch_get_main_queue(), ^{ 73 | [SumupSDK checkoutWithRequest:checkoutRequest 74 | fromViewController:rootViewController 75 | completion:^(SMPCheckoutResult *result, NSError *error) { 76 | if (error) { 77 | errorBlock(@"002", @"Error performing checkout", error); 78 | } else { 79 | completionBlock(@{@"success": @([result success]), @"transactionCode": [result transactionCode]}); 80 | } 81 | }]; 82 | }); 83 | } 84 | 85 | RCT_EXPORT_METHOD(isLoggedIn:(RCTPromiseResolveBlock)completionBlock error:(RCTPromiseRejectBlock)errorBlock) 86 | { 87 | BOOL isLoggedIn = [SumupSDK isLoggedIn]; 88 | completionBlock(@{@"isLoggedIn": @(isLoggedIn)}); 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules } from 'react-native' 2 | const SumupSDK = NativeModules.RNSumup 3 | 4 | var Sumup = { 5 | setupWithAPIKey(apiKey) { 6 | return SumupSDK.setupWithAPIKey(apiKey); 7 | }, 8 | presentLoginFromViewController() { 9 | return SumupSDK.presentLoginFromViewController(); 10 | }, 11 | checkoutWithRequest(request) { 12 | return SumupSDK.checkoutWithRequest(request); 13 | }, 14 | isLoggedIn() { 15 | return SumupSDK.isLoggedIn().then(result => result.isLoggedIn) 16 | }, 17 | paymentOptionAny: SumupSDK.SMPPaymentOptionAny, 18 | paymentOptionCardReader: SumupSDK.SMPPaymentOptionCardReader, 19 | paymentOptionMobilePayment: SumupSDK.SMPPaymentOptionMobilePayment, 20 | }; 21 | module.exports = Sumup; 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-sumup", 3 | "version": "0.2.0", 4 | "description": "A React Native implementation of SumupSDK.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/APSL/react-native-sumup.git" 12 | }, 13 | "keywords": [ 14 | "react-native", 15 | "ios", 16 | "react-component" 17 | ], 18 | "author": "Alvaro Medina Ballester ", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/APSL/react-native-sumup/issues" 22 | }, 23 | "homepage": "https://github.com/APSL/react-native-sumup#readme" 24 | } --------------------------------------------------------------------------------