Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
app
bootstrap
config
database
phpdocker
public
resources
routes
storage
tests
.editorconfig
.env.example
.gitattributes
.gitignore
artisan
composer.json
composer.lock
dash.sh
docker-compose.yml
package.json
phpunit.xml
readme.md
server.php
webpack.mix.js

readme.md

Amazon Dash Button Example

This example illustrate how a workflow of a Amazon Dash Button can be implemented.

Requirements

  • Docker 18.09
  • curl
  • An account on Zenaton

Running the example

Build all docker images:

docker-compose build

Copy the .env.example to .env

cp .env.example .env

Retrieve your App ID and Api Token from the Zenaton Website and use them to fill the ZENATON_APP_ID and ZENATON_API_TOKEN in the .env file.

Now we can install required dependencies using composer (inside docker of course!)

docker run --rm -v $(pwd):/application -w /application composer:1.6 composer install

You can now start your docker containers!

docker-compose up -d

Migrate the database and seed it:

docker-compose exec php-fpm php artisan migrate --seed

Push the button

We provide a virtual Amazon Dash button. If you want to press it you can run the following command:

./dash.sh

At this point, your first order has been accepted. You can go to http://localhost:1080/ and you should see an invoice in your mailbox. You can run ./dash.sh again to receive more invoices.

Now, go to app/Services/Payment.php and change method chargeCustomerForOrder to return false:

$result = false;

Run the ./dash.sh script again to make a new order. This time, you received an email with a link to enter new payment information. When clicking it, you will see a form to enter payment details. Just enter a credit card number ending with an even digit to make the payment a success. You will then receive an invoice in the mailbox, meaning the order was a success.

If you want to try the case when you don't provide new payment information, go to app/Workflows/OrderFromDashButton.php and change the wait instruction from 14 days to 14 seconds.

$event = (new Wait(OrderPaid::class))->seconds(14)->execute();

Now run the ./dash.sh script one more time, and this time your order will be canceled. You can see the order being canceled in the log file of the application: storage/logs/laravel.log. Everything happening is logged in this file!

Uninstalling the project

Just run this command:

docker-compose down --volumes

After that, you're free to delete the project directory.

You can’t perform that action at this time.