Name: swa-sample-seller
Owner: Amazon
Description: Sample website demonstrating how to use LWA and SWA APIs
Created: 2016-08-17 22:27:58.0
Updated: 2017-06-03 06:52:16.0
Pushed: 2018-03-13 18:44:28.0
Homepage:
null
Size: 576
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
Other Committers
User | Email | Most Recent Commit | # Commits |
README
WARNING
- This application is provided for your convenience. Please refer to the SWA Getting Started Guide at https://s3-us-west-2.amazonaws.com/swa-public-documents/integration-guides for detailed information.
- Deploy Sample Seller only to your local machine.
- Anyone who visits this web application will have access to confidential data about your seller account.
Subscribe with Amazon (SWA) Sample Seller
Sample Seller is a sample web application storefront that uses LWA and SWA APIs.
Before you start
- This README will refer to the SWA Getting Started Guide at https://s3-us-west-2.amazonaws.com/swa-public-documents/integration-guides/SWA_SellerIntegrationGuide.pdf. For example, [4.1.1] refers to section 4.1.1 in the guide.
path/to/repo
represents the root directory of the Sample Seller repository you've downloaded. README.md
is in the root directory.
Install dependencies
- Install Java Development Kit (JDK) 8.
- Verify installation by running
javac
from your terminal.
- Install Apache Maven.
- Verify installation by running
mvn
from your terminal.
Edit src/main/resources/config.json
- Retrieve your Client ID and Client Secret Key from the Technical Details of your product.
- Set
clientId
to your client ID.
- Set
clientSecret
to your client secret.
- Set
detailPageUrl
to the URL for the detail page of your product.
- Set
port
to an open port you want to serve Sample Seller on.
- Ex:
8444
- Set
redirectUri
to https://127.0.0.1:port/login
- Ex:
https://127.0.0.1:8444/login
- In Sample Seller, we want LWA to redirect the user to the
/login
path so Sample Seller can query and display the user's subscriptions information.
- Set
logoutRedirectUri
to https://127.0.0.1:port
.\
- Ex:
https://127.0.0.1:8444
- In Sample Seller, we want to redirect the uselr to the landing page.
Configure your LWA application. [2.4]
- Sign into the App Console at http://login.amazon.com/manageApps.
- Select the LWA application associated with your SWA subscription.
- Expand the “Web Settings” tab.
- Add
https://127.0.0.1:port
to “Allowed JavaScript Origins”
- Ex:
https://127.0.0.1:8444
- Add
redirectUri
to “Allowed Return URLs”.
- Ex:
https://127.0.0.1:8444/login
Build Sample Seller
ath/to/repo # Switch to the repo root directory.
package # Build the program with Maven.
Run Sample Seller
Run the JAR file to start the web application:
ath/to/repo # Switch to the repo root directory.
-jar target/swa_sample_seller-1.0-SNAPSHOT.jar # Run the JAR file.
Visit the application at https://127.0.0.1:port
Ex https://127.0.0.1:8444
Take a tour of Sample Seller
- Visit the index page at https://127.0.0.1:port.
- Ex: https://127.0.0.1:8444
- Click the Login with Swanly button.
- Click the LWA button and login with an Amazon account that has not purchased your subscription.
- Verify that you see a Subscribe Now button.
- Expand the Information for developers tab.
- Scroll to the bottom
- Verify that you do not see any
ACTIVE
subscriptions in the Subscriptions Response body.
- Logout.
- Click the LWA button and login with an Amazon account that has purchased your subscription.
- Verify that you see at least 1
ACTIVE
subscriptions in the Subscriptions Response body.
View code snippets
- View code for the LWA button with
view-source:https://127.0.0.1:port
[3.1]
- Ex:
view-source:https://127.0.0.1:8444
- View code for making the API requests:
- In
src/main/java/com/github/amznlabs/swa_sample_seller/controllers/helpers/AmazonApiHelpers.java
- Customer profile
- See
// REQUEST CUSTOMER PROFILE
- [4.1.1, Step 3]
- Security API
- See
// REQUEST SELLER ACCESS TOKEN
- [4.2.1]
- Subscriptions API
- See
// REQUEST SUBSCRIPTIONS
- [4.1.1, Step 3], [4.2.5]
- View code for handling SWA API response codes [4.2.3]:
- In
src/main/java/com/github/amznlabs/swa_sample_seller/controllers/RequestController.java
- See
// HANDLE SWA API RESPONSE CODE
- View code for parsing an List Subscriptions API request [4.2.5]:
- In
src/main/java/com/github/amznlabs/swa_sample_seller/controllers/RequestController.java
- See
parseSubscriptionsResponse()
SWA Sample Push Notification Endpoint
Sample Push Notification Endpoint is a collection of services running on Amazon Web Services (AWS) that implement an endpoint to catch SWA push notifications.
You do not have to use AWS to implement your endpoint. See the FAQ section for more information.
Setup Python
Install Python 2 or Python 3 from https://www.python.org/downloads/
Verify your installation by running python
and pip
from your terminal.
Install the Python boto3
library:
install boto3
Setup AWS
- Create an AWS account at https://aws.amazon.com/
- Create an IAM user named
swa_sample_seller
with the AdministratorAccess
permission.
- See http://docs.aws.amazon.com/lambda/latest/dg/setting-up.html
- Make note of your access key ID and access key secret.
Edit src/main/resources/config.json
- Set
awsAccessKeyId
to your user's access key ID.
- Set
awsSecretAccessKey
to your user's secret access key.
- [Optional] Change
awsResourcesName
to a name of your choice.
- Ex:
sample_seller_resources
- All AWS resources will be created with this name.
- Use a name that will be easy to find in your AWS console.
- [Optional] Change
awsRegionName
- See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
Create a sample endpoint to catch push notifications
Run:
ath/to/repo
on src/main/python/aws_create.py
Make note of the endpoint printed out by the script.
Ex: Your push notification endpoint is YOUR_ENDPOINT
Send a test notification [4.2.5]
- Visit https://sellercentral.amazon.com/swa/dashboard.
- Edit the Technical Details of your product.
- Continue to the Push Notifications page.
- Set the Enter your HTTPS endpoint field to
YOUR_ENDPOINT
- Click Send Test Notification.
View the test notification
- In your DynamoDB dashboard, view the Table with the name of your
awsResourcesName
field.
- View the Items of the table.
- Verify that there is an entry for the test push notification you just sent.
View a real push notification
- Purchase / Renew / Cancel your subscription.
- View the table in your DynamoDB dashboard.
Delete your sample endpoint
Run:
ath/to/repo
on src/main/python/aws_delete.py
View code snippets
- Read the comments in
src/main/python/aws_create.py
for a better understanding what AWS services will be setup.
- Read
src/main/python/lambda_function_template.py
for code that processes a push notification.
FAQ
- Is the AWS usage free?
- See https://aws.amazon.com/free/ for details on AWS Free Tier.
- See the pricing pages of the individual AWS services.
- Why can't Sample Seller receive real push notifications?
- Amazon only sends push notifications to a publicly accessible IP that serves a trusted SSL certificate.
- Sample Seller should not be deployed to a publicly accessible IP.
- Sample Seller uses a self-signed SSL certificate.
- Do I need to use AWS to receive push notifications?
- You do not need to use AWS.
- You can use any service that serves a publicly accessible IP with a trusted SSL certificate.
- See
src/main/python/lambda_function.py
for code to process a push notification.
- What SSL certificates are trusted by Amazon's push notification sender?
- See https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.https.ca.html.