Skip to content

AssemblyPayments/ios-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PromisePay - iOS SDK

CI Status Version License Platform

#1. Installation

Manual

Download the latest release from GitHub, then add the PromisePay holder to your relevant xcode project.

CocoaPods

PromisePay is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PromisePay"

#2. Usage Import the header and create PromisePay object.

#import "PromisePay.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Initialize the PromisePay with the Environment and PublickKey
    PromisePay *promisePay = [[PromisePay alloc] initWithEnvironment:@"prelive" publicKey:@"cbd748a608eda8635e1f325d914080b4"];

    // Create the Card
    PPCard *card = [[PPCard alloc] initWithNumber:@"4111111111111111"
                                         fullName:@"Bobby Buyer"
                                      expiryMonth:@"12"
                                       expiryYear:@"2020"
                                              cvv:@"123"];
    [promisePay createCardAccount:@"460b3a207121352b1d48aa0724734e4b" card:card callBack:^(id  result, NSError * error) {
        // TODO: process with the callback
    }];
}

###Using the card scanner

Declare conformity to the PromisePayCardScannerDelegate protocol.

#import "PromisePayCardScanner.h"

@interface ViewController : UIViewController <PromisePayCardScannerDelegate>

@end

Implement the delegate methods in your view controller.

#import "PromisePay.h"

@interface ViewController ()

@property (nonatomic, strong) PromisePay *promisePay;
@property (nonatomic, strong) PromisePayCardScanner *promisePayCardScanner;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Initialize the PromisePay with the Environment and PublickKey
    PromisePay *promisePay = [[PromisePay alloc] initWithEnvironment:@"prelive" publicKey:@"cbd748a608eda8635e1f325d914080b4"];

    // Initialize the PromisePayCardScanner
    self.promisePayCardScanner = [[PromisePayCardScanner alloc] init];
    self.promisePayCardScanner.delegate = self;

}

#pragma mark - PromisePayCardScannerDelegate methods

- (void)userDidScanCard:(PPCard *)card {
    [self.promisePay createCardAccount:@"460b3a207121352b1d48aa0724734e4b" card:card callBack:^(id  result, NSError * error) {
        // TODO: process with the callback
    }];
}

- (void)userDidCancelCardScanning {
    NSLog(@"user cancelled");
}

@end

Start the card scanner

[self.promisePayCardScanner scanCardFromViewController:self];

#3. Examples ##Configuration Initialize PromisePay using as following.

PromisePay *promisePay = [[PromisePay alloc] initWithEnvironment:@"prelive" publicKey:@"PUBLIC_KEY"];

##Create Card Account Create the PPCard object with the information of card like this.

PPCard *card = [[PPCard alloc] initWithNumber:@"4111111111111111"
                                     fullName:@"Bobby Buyer"
                                  expiryMonth:@"12"
                                   expiryYear:@"2020"
                                          cvv:@"123"];

Now calling the createCardAccount method, you can get the callback of result.

[promisePay createCardAccount:@"CARD_TOKEN" card:card callBack:^(id  _Nonnull result, NSError * _Nonnull error) {
    if(error != nil) {
        NSLog(@"error = %@", error);
    }
    else {
        NSLog(@"Succeed to create card account, result=%@", result);
    }
}];
```

Alternatively use the card scanner to return a PPCard object by implementing the delegate methods.
```ObjectiveC
- (void)userDidScanCard:(PPCard *)card {
    [self.promisePay createCardAccount:@"460b3a207121352b1d48aa0724734e4b" card:card callBack:^(id  result, NSError * error) {
        // TODO: process with the callback
    }];
}

- (void)userDidCancelCardScanning {
    NSLog(@"user cancelled");
}
```

Start the card scanner
```Objective-C
[self.promisePayCardScanner scanCardFromViewController:self];
```

#4. License

PromisePay is available under the MIT license. See the LICENSE file for more info.

#5. Requirements

Third-party open source libraries used within PromisePay:

1. [CardIO](https://github.com/card-io/card.io-iOS-SDK) - Credit card scanning