|
| 1 | +# <img src="./docs/wallet.png" alt="Goboony" height="50"/> Passkit |
| 2 | + |
| 3 | +Your out-of-the-box solution to start serving Wallet Passes in your Ruby On Rails application. |
| 4 | + |
| 5 | +Do you have a QRCode or a Barcode anywhere in your app that you want to distribute as Wallet Pass, compatible for iOS and Android? Look no further! |
| 6 | + |
| 7 | +This gem provides everything necessary to distribute Wallet Passes in pkpass format, and gives you all the steps to follow for what we cannot provide. |
| 8 | + |
| 9 | +**We provide:** |
| 10 | + |
| 11 | +* A (not yet) fancy dashboard to manage your passes, registered devices and logs. |
| 12 | +* All API endpoints to serve your passes: create, register, update, unregister, etc... |
| 13 | +* All necessary ActiveRecord models. |
| 14 | +* A BasePass model that you can extend to create your own passes. |
| 15 | +* Some helpers to generate the necessary URLs, so that you can include them in the emails. |
| 16 | +* Examples for everything. |
| 17 | + |
| 18 | +**We don't provide (yet):** |
| 19 | + |
| 20 | +* Full tests coverage: we are working on it! |
| 21 | +* A fancy dashboard: our dashboard is really really simple right now. Pull requests are welcome! |
| 22 | +* Push notifications: this is the most wanted feature I believe. Pull requests are welcome! |
| 23 | +* Google Wallet integration: we use https://walletpasses.io/ on Android to read .pkpass format. |
| 24 | + |
| 25 | +## Apple documentation |
| 26 | + |
| 27 | +* [Apple Wallet Passes](https://developer.apple.com/documentation/walletpasses) |
| 28 | +* [Send Push Notifications](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns) |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +Add this line to your application's Gemfile: |
| 33 | + |
| 34 | +```ruby |
| 35 | +gem 'passkit' |
| 36 | +``` |
| 37 | + |
| 38 | +And then execute: |
| 39 | + |
| 40 | + $ bundle install |
| 41 | + |
| 42 | +Or install it yourself as: |
| 43 | + |
| 44 | + $ gem install passkit |
| 45 | + |
| 46 | +Run the initializer: |
| 47 | + |
| 48 | + $ rails g passkit:install |
| 49 | + |
| 50 | +that will generate the migrations and the initializer file. |
| 51 | + |
| 52 | +Mount the engine in your `config/routes.rb`: |
| 53 | + |
| 54 | +```ruby |
| 55 | +mount Passkit::Engine => '/passkit', as: 'passkit' |
| 56 | +``` |
| 57 | + |
| 58 | +and run `bin/rails db:migrate`. |
| 59 | + |
| 60 | +### Setup environment variables |
| 61 | + |
| 62 | +If you followed the installation steps, you already saw that Passkit provides |
| 63 | +you the tables and ActiveRecord models, and also an engine with the necessary APIs already implemented. |
| 64 | + |
| 65 | +Now is your turn. Before proceeding, you need to set these ENV variables: |
| 66 | +* `PASSKIT_WEB_SERVICE_HOST` |
| 67 | +* `PASSKIT_CERTIFICATE_KEY` |
| 68 | +* `PASSKIT_PRIVATE_P12_CERTIFICATE` |
| 69 | +* `PASSKIT_APPLE_INTERMEDIATE_CERTIFICATE` |
| 70 | +* `PASSKIT_APPLE_TEAM_IDENTIFIER` |
| 71 | +* `PASSKIT_PASS_TYPE_IDENTIFIER` |
| 72 | + |
| 73 | +We have a [specific guide on how to get all these](docs/passkit_environment_variables.md), please follow it. |
| 74 | +You cannot start using this library without these variables set, and we cannot do the work for you. |
| 75 | + |
| 76 | +## Usage |
| 77 | + |
| 78 | +If you followed the installation steps and you have the ENV variables set, we can start looking at what is provided for you. |
| 79 | + |
| 80 | +### Dashboard |
| 81 | + |
| 82 | +Head to `http://localhost:3000/passkit/previews` and you will see a first `ExampleStoreCard` available for download. |
| 83 | +You can click on the button and you will obtain a `.pkpass` file that you can simply open or install on your phone. |
| 84 | +The dashboard has also a view for logs, and a view for emitted passes. |
| 85 | + |
| 86 | +### Mailer Helpers |
| 87 | + |
| 88 | +If you use mailer previews, you can create the following file in `spec/mailers/previews/passkit/example_mailer_preview.rb`: |
| 89 | + |
| 90 | +```ruby |
| 91 | +module Passkit |
| 92 | + class ExampleMailerPreview < ActionMailer::Preview |
| 93 | + def example_email |
| 94 | + Passkit::ExampleMailer.example_email |
| 95 | + end |
| 96 | + end |
| 97 | +end |
| 98 | +``` |
| 99 | + |
| 100 | +and head to `http://localhost:3000/rails/mailers/` to see an example of email with links to download the Wallet Pass. |
| 101 | +Please check the source code of [ExampleMailer](app/mailers/passkit/example_mailer.rb) to see how to distribute your own Wallet Passes. |
| 102 | + |
| 103 | +### Example Passes |
| 104 | + |
| 105 | +Please check the source code of the [ExampleStoreCard](lib/passkit/example_store_card.rb) to see how to create your own Wallet Passes. |
| 106 | + |
| 107 | +Again, looking at these examples, is the easiest way to get started. |
| 108 | + |
| 109 | +### Create your own Wallet Pass |
| 110 | + |
| 111 | +You can create your own Wallet Passes by creating a new class that inherits from `Passkit::BasePass` and |
| 112 | +defining the methods that you want to override. |
| 113 | + |
| 114 | +You can define colors, fields and texts. You can also define the logo and the background image. |
| 115 | + |
| 116 | +You should place the images in a 'private/passkit/<your_downcased_passname>' folder. |
| 117 | +There is a [dummy app in the gem](test/dummy) that you can use to check how to create your own Wallet Passes. |
| 118 | + |
| 119 | +### Serve your Wallet Pass |
| 120 | + |
| 121 | +Use the [Passkit::UrlGenerator](lib/passkit/url_generator.rb) to generate the URL to serve your Wallet Pass. |
| 122 | +You can initialize it with: |
| 123 | + |
| 124 | +```ruby |
| 125 | +Passkit::UrlGenerator.new(pass_class: Passkit::MyPass, generator: User.find(1)) |
| 126 | +``` |
| 127 | + |
| 128 | +and then use `.android` or `.ios` to get the URL to serve the Wallet Pass. |
| 129 | +Again, check the example mailer included in the gem to see how to use it. |
| 130 | + |
| 131 | +## Debug issues |
| 132 | + |
| 133 | +* On Mac, open the `Console.app` to view the errors. |
| 134 | +* Check the logs on http://localhost:3000/passkit/logs |
| 135 | +* In case of error "The passTypeIdentifier or teamIdentifier provided may not match your certificate, |
| 136 | +or the certificate trust chain could not be verified." the certificate (p12) might be expired. |
| 137 | + |
| 138 | +## Development |
| 139 | + |
| 140 | +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. |
| 141 | + |
| 142 | +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
| 143 | + |
| 144 | +## Contributing |
| 145 | + |
| 146 | +Bug reports and pull requests are welcome on GitHub at https://github.com/coorasse/passkit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/coorasse/passkit/blob/master/CODE_OF_CONDUCT.md). |
| 147 | + |
| 148 | +## License |
| 149 | + |
| 150 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
| 151 | + |
| 152 | +## Code of Conduct |
| 153 | + |
| 154 | +Everyone interacting in the Passkit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/coorasse/passkit/blob/master/CODE_OF_CONDUCT.md). |
| 155 | + |
| 156 | +## Credits |
| 157 | + |
| 158 | +* <a href="https://www.flaticon.com/free-icons/credit-card" title="credit card icons">Credit card icons created by Iconfromus - Flaticon</a> |
| 159 | + |
| 160 | +* https://www.sitepoint.com/whats-in-your-wallet-handling-ios-passbook-with-ruby/ |
0 commit comments