forked from etsy/applepay-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6cbb03
Showing
11 changed files
with
1,286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
applepay |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) <2015> <Adam Saponara, Stephen Buckley, Keyur Govande, Rasmus Lerdorf> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# applepay-php | ||
|
||
applepay-php is a PHP extension that verifies and decrypts Apple Pay payment | ||
tokens according to Apple's spec[1]. It relies on OpenSSL for all crypto | ||
operations. Currently, it serves as the backbone for Etsy's PHP-based Apple Pay | ||
token handling endpoint. | ||
|
||
### Build | ||
|
||
$ # Clone repo | ||
$ git clone https://github.com/etsy/applepay-php.git | ||
$ cd applepay-php | ||
$ | ||
$ # Install OpenSSL development files | ||
$ sudo yum install openssl-devel | ||
$ # -or- sudo apt-get install libssl-dev | ||
$ # etc... | ||
$ | ||
$ # Build extension | ||
$ phpize && ./configure && make | ||
$ | ||
$ # Optionally install | ||
$ sudo make install | ||
$ echo 'extension=applepay.so' | sudo tee /etc/php.d/applepay.ini | ||
$ # -or- echo 'extension=applepay.so' | sudo tee -a /etc/php.ini | ||
$ # etc... | ||
|
||
### Demo | ||
|
||
Before running the demo, you'll need a merchant certificate and a private key | ||
from Apple (merch.cer and priv.p12 below). You can generate these at Apple's Dev | ||
Center. You'll also need an example payment token generated on an end-user | ||
device and the timestamp at which it was generated. For more info check out the | ||
Apple Pay Programming Guide[2]. | ||
|
||
$ # Copy in your merchant cert, private key, and test token | ||
$ cd examples | ||
$ cp /secret/place/priv.p12 . | ||
$ cp /secret/place/merch.cer . | ||
$ cp /secret/place/token.dat . | ||
$ | ||
$ # Get intermediate and root certs from Apple | ||
$ wget -O int.cer 'https://www.apple.com/certificateauthority/AppleAAICAG3.cer' | ||
$ wget -O root.cer 'https://www.apple.com/certificateauthority/AppleRootCA-G3.cer' | ||
$ | ||
$ # Verify chain of trust | ||
$ openssl x509 -inform DER -in merch.cer -pubkey > pub.pem | ||
$ openssl x509 -inform DER -in root.cer > root.pem | ||
$ openssl x509 -inform DER -in int.cer > int_merch.pem | ||
$ openssl x509 -inform DER -in merch.cer >> int_merch.pem | ||
$ openssl verify -verbose -CAfile root.pem int_merch.pem # should output OK | ||
$ | ||
$ # Run demo | ||
$ cd .. | ||
$ php -denable_dl=on -dextension=`pwd`/modules/applepay.so examples/applepay.php -p <privkey_pass> -c examples/token.dat -t <time_of_transaction> | ||
|
||
If everything goes well you should see decrypted payment data. | ||
|
||
### Future work | ||
|
||
* Split up library into libapplepay and a PHP wrapper | ||
* PHP7 compatibility | ||
* HHVM port | ||
|
||
[1] https://developer.apple.com/library/prerelease/ios/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html | ||
|
||
[2] https://developer.apple.com/library/ios/ApplePay_Guide/ |
Oops, something went wrong.