Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# com.passslot.cordova.plugin.passbook
# cordova-plugin-passbook

This plugin provides support for showing Passbook passs to your users and allows them to add it to their native Wallet (regardless of how you create your passes, whether you do it on your own or using any third-party services like [PassSlot](http://www.PassSlot.com))

Expand All @@ -14,9 +14,7 @@ Or the latest (unstable) version:

## Supported Platforms


- iOS
- ~~Android~~ (coming soon)

## Example

Expand All @@ -25,9 +23,7 @@ Or the latest (unstable) version:
```javascript
Passbook.downloadPass('https://d.pslot.io/cQY2f', function (pass, added) {
console.log(pass, added);
if (added) {
Passbook.openPass(pass);
} else {
if (!added) {
alert('Please add the pass');
}
}, function (error) {
Expand All @@ -46,16 +42,43 @@ Or the latest (unstable) version:

Passbook.downloadPass(callData, function (pass, added) {
console.log(pass, added);
if (added) {
Passbook.openPass(pass);
} else {
if (!added) {
alert('Please add the pass');
}
}, function (error) {
console.error(error);
});
```

### Multiple passes

```javascript
Passbook.downloadPasses(['https://d.pslot.io/cQY2f', 'https://d.pslot.io/AeY3D'], function (passes, added) {
console.log(passes, added);
if (!added) {
alert('Please add the passes');
}
}, function (error) {
console.error(error);
});
```

### Multiple passes with headers

```javascript
Passbook.downloadPasses({
urls: ['https://d.pslot.io/cQY2f', 'https://d.pslot.io/AeY3D'],
headers: {authorization: "Bearer <token>"}
}, function (passes, added) {
console.log(passes, added);
if (!added) {
alert('Please add the passes');
}
}, function (error) {
console.error(error);
});
```

## Documentation

Plugin documentation: [doc/index.md](doc/index.md)
Expand Down
178 changes: 134 additions & 44 deletions doc/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# com.passslot.cordova.plugin.passbook
# cordova-plugin-passbook

This plugin provides basic support for Passbook on iOS.
It allows you to show Passbook passes so that your users can add them directly to Passbook.
Expand All @@ -7,7 +7,7 @@ On cordova >= 3.1.0, this plugin registers for .pkpass URLs and automatically do

## Installation

cordova plugin add com.passslot.cordova.plugin.passbook
cordova plugin add cordova-plugin-passbook

## Supported Platforms

Expand All @@ -31,26 +31,25 @@ Returns if Passbook is available on the current device to the `resultCallback` c


### Example
```javascript
// onSuccess Callback
// This method accepts a boolean, which specified if Passbook is available
//
var onResult = function(isAvailable) {
if(!isAvailable) {
alert('Passbook is not available');
}
};

// onSuccess Callback
// This method accepts a boolean, which specified if Passbook is available
//
var onResult = function(isAvailable) {
if(!isAvailable) {
alert('Passbook is not available');
}
};

Passbook.available(onResult);

Passbook.available(onResult);
```
## Passbook.downloadPass

Downloads a pass from a the provided URL and shows it to the user.
When the pass was successfully downloaded and was shown to the user, and the user either canceld or added the pass, the `passCallback` callback executes. If there is an error, the `errorCallback` callback executes with an error string as the parameter

Passbook.downloadPass(callData,
[passCallback],
[errorCallback]);
```javascript
Passbook.downloadPass(callData, [passCallback], [errorCallback]);
```

### Parameters

Expand All @@ -64,19 +63,19 @@ When the pass was successfully downloaded and was shown to the user, and the use
### Simple Example

```javascript
// onSuccess Callback
function onSuccess(pass, added) {
console.log('Pass shown to the user');
console.log(pass, added);
}
// onSuccess Callback
function onSuccess(pass, added) {
console.log('Pass shown to the user');
console.log(pass, added);
}

// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show pass: ' + error);
}
// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show pass: ' + error);
}

Passbook.downloadPass('https://d.pslot.io/cQY2f', onSuccess, onError);
Passbook.downloadPass('https://d.pslot.io/cQY2f', onSuccess, onError);
```

### Adding Header
Expand All @@ -99,40 +98,131 @@ var callData = {
"headers":{ "authorization": "Bearer <token>" }
};
Passbook.downloadPass(callData, onSuccess, onError);
```

## Passbook.downloadPasses

Downloads a list of passes from a the provided URLs and shows them to the user.
When the passes are successfully downloaded, shown to the user, and the user either cancelled or added the pass, the `passCallback` callback executes passing an array of passes and a boolean of value of if they were added or not. If there is an error, the `errorCallback` callback executes with an error string as the parameter
```javascript
Passbook.downloadPasses(callData, [passCallback], [errorCallback]);
```
### Parameters

- __callData__: It could be either an array of URL strings or an Object in the form `{ urls:[<url1>,<url2>], headers?:<{}> }` .

- __passCallback__: (Optional) The callback that executes when the pass is shown to the user. Returns the downloaded pass (passTypeIdentifier, serialNumber, passURL) and if it was added to Passbook.

- __errorCallback__: (Optional) The callback that executes if an error occurs, e.g if Passbook is not available, the URL is invalid or no valid pass was found at the given URL.

### Simple Example

```javascript
// onSuccess Callback
function onSuccess(passes, added) {
console.log('Passes shown to the user');
console.log(passes, added);
}

// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show passes: ' + error);
}

Passbook.downloadPasses(['https://d.pslot.io/cQY2f', 'https://d.pslot.io/DbM3E'], onSuccess, onError);
```

### Adding Header

```javascript
// onSuccess Callback
function onSuccess(passes, added) {
console.log('Pass shown to the user');
console.log(passes, added);
}

// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show passes: ' + error);
}

var callData = {
"urls":['https://d.pslot.io/cQY2f', 'https://d.pslot.io/DbM3E'],
"headers":{ "authorization": "Bearer <token>" }
};
Passbook.downloadPasses(callData, onSuccess, onError);
```

## Passbook.addPass

Add a pass from a the provided local file and shows it to the user.
When the pass was successfully shown to the user, and the user either canceled or added the pass, the `passCallback` callback executes. If there is an error, the `errorCallback` callback executes with an error string as the parameter
```javascript
Passbook.addPass(file, [passCallback], [errorCallback]);
```
### Parameters

- __file__: The file of the pass that should be shown. (e.g. file:///..../sample.pkpass)

- __passCallback__: (Optional) The callback that executes when the pass is shown to the user. Returns the local pass (passTypeIdentifier, serialNumber, passURL) and if it was added to Passbook.

- __errorCallback__: (Optional) The callback that executes if an error occurs, e.g if Passbook is not available, the URL is invalid or no valid pass was found at the given URL.

Passbook.addPass(file,
[passCallback],
[errorCallback]);

### Example
```javascript
// onSuccess Callback
function onSuccess(pass, added) {
console.log('Pass shown to the user');
console.log(pass, added);
}

// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show pass: ' + error);
}

Passbook.addPass(cordova.file.applicationDirectory + 'sample.pkpass', onSuccess, onError);
```
## Passbook.addPasses

Add a list of passes from a the provided local files and shows it to the user.
When the passes are successfully shown to the user, and the user either cancelled or added the passes, the `passCallback` callback executes. If there is an error, the `errorCallback` callback executes with an error string as the parameter
```javascript
Passbook.addPass(files, [passCallback], [errorCallback]);
```
### Parameters

- __file__: The file of the pass that should be downloaded. (e.g. file:///..../sample.pkpass)
- __files__: The files of the passes that should be shown. (e.g. ["file:///..../sample1.pkpass","file:///..../sample2.pkpass"])

- __passCallback__: (Optional) The callback that executes when the pass is shown to the user. Returns the local pass (passTypeIdentifier, serialNumber, passURL) and if it was added to Passbook.

- __errorCallback__: (Optional) The callback that executes if an error occurs, e.g if Passbook is not available, the URL is invalid or no valid pass was found at the given URL.


### Example
```javascript
// onSuccess Callback
function onSuccess(passes, added) {
console.log('Passes shown to the user');
console.log(passes, added);
}

// onSuccess Callback
function onSuccess(pass, added) {
console.log('Pass shown to the user');
console.log(pass, added);
}

// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show pass: ' + error);
}
// onError Callback receives a string with the error message
//
function onError(error) {
alert('Could now show pass: ' + error);
}

Passbook.addPass(cordova.file.applicationDirectory + 'sample.pkpass', onSuccess, onError);
Passbook.addPasses(
[
cordova.file.applicationDirectory + 'sample1.pkpass',
cordova.file.applicationDirectory + 'sample2.pkpass'
],
onSuccess,
onError
);
```
17 changes: 14 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-passbook"
version="0.2.1">
version="0.3.0">

<name>Passbook</name>
<description>This plugin allows you to add passes to Passbook</description>
<description>This plugin allows you to add passes to iOS Wallet</description>
<author>PassSlot.com</author>
<license>Apache 2.0</license>
<engines>
Expand All @@ -31,5 +31,16 @@
<framework src="PassKit.framework" />

</platform>


<config-file target="*-Debug.plist" parent="com.apple.developer.pass-type-identifiers">
<array>
<string>$(TeamIdentifierPrefix)*</string>
</array>
</config-file>
<config-file target="*-Release.plist" parent="com.apple.developer.pass-type-identifiers">
<array>
<string>$(TeamIdentifierPrefix)*</string>
</array>
</config-file>

</plugin>
3 changes: 2 additions & 1 deletion src/ios/CDVPassbook.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- (void)available:(CDVInvokedUrlCommand*)command;
- (void)downloadPass:(CDVInvokedUrlCommand*)command;
- (void)downloadPasses:(CDVInvokedUrlCommand*)command;
- (void)addPass:(CDVInvokedUrlCommand*)command;
- (void)addPasses:(CDVInvokedUrlCommand*)command;
- (void)openPass:(CDVInvokedUrlCommand*)command;

@end
Loading