Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Sample website demonstrating how to use LWA and SWA APIs

License

Notifications You must be signed in to change notification settings

amazon-archives/swa-sample-seller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WARNING

Subscribe with Amazon (SWA) Sample Seller

Sample Seller is a sample web application storefront that uses LWA and SWA APIs.

Screenshot of login page

Screenshot of subscriptions page

Before you start

Install dependencies

  1. Install Java Development Kit (JDK) 8.
  2. Verify installation by running javac from your terminal.
  3. Install Apache Maven.
  4. Verify installation by running mvn from your terminal.

Edit src/main/resources/config.json

  1. Retrieve your Client ID and Client Secret Key from the Technical Details of your product.
    1. Set clientId to your client ID.
    2. Set clientSecret to your client secret.
  2. Set detailPageUrl to the URL for the detail page of your product.
  3. Set port to an open port you want to serve Sample Seller on.
    • Ex: 8444
  4. 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.
  5. 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]

  1. Sign into the App Console at http://login.amazon.com/manageApps.
  2. Select the LWA application associated with your SWA subscription.
  3. Expand the "Web Settings" tab.
  4. Add https://127.0.0.1:port to "Allowed JavaScript Origins"
  • Ex: https://127.0.0.1:8444
  1. Add redirectUri to "Allowed Return URLs".
  • Ex: https://127.0.0.1:8444/login

Build Sample Seller

cd path/to/repo    # Switch to the repo root directory.
mvn package        # Build the program with Maven.

Run Sample Seller

  1. Run the JAR file to start the web application:

    cd path/to/repo                                         # Switch to the repo root directory.
    java -jar target/swa_sample_seller-1.0-SNAPSHOT.jar     # Run the JAR file.
    
  2. Visit the application at https://127.0.0.1:port

    • Ex https://127.0.0.1:8444

Take a tour of Sample Seller

  1. Visit the index page at https://127.0.0.1:port.
  2. Click the Login with Swanly button.
  3. Click the LWA button and login with an Amazon account that has not purchased your subscription.
  4. Verify that you see a Subscribe Now button.
  5. Expand the Information for developers tab.
  6. Scroll to the bottom
  7. Verify that you do not see any ACTIVE subscriptions in the Subscriptions Response body.
  8. Logout.
  9. Click the LWA button and login with an Amazon account that has purchased your subscription.
  10. 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

  1. Install Python 2 or Python 3 from https://www.python.org/downloads/

  2. Verify your installation by running python and pip from your terminal.

  3. Install the Python boto3 library:

    pip install boto3
    

Setup AWS

  1. Create an AWS account at https://aws.amazon.com/
  2. Create an IAM user named swa_sample_seller with the AdministratorAccess permission.

Edit src/main/resources/config.json

  1. Set awsAccessKeyId to your user's access key ID.
  2. Set awsSecretAccessKey to your user's secret access key.
  3. [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.
  4. [Optional] Change awsRegionName

Create a sample endpoint to catch push notifications

  1. Run:

    cd path/to/repo
    python src/main/python/aws_create.py
    
  2. Make note of the endpoint printed out by the script.

    • Ex: Your push notification endpoint is YOUR_ENDPOINT

Console output of running aws_create.py

Send a test notification [4.2.5]

  1. Visit https://sellercentral.amazon.com/swa/dashboard.
  2. Edit the Technical Details of your product.
  3. Continue to the Push Notifications page.
  4. Set the Enter your HTTPS endpoint field to YOUR_ENDPOINT
  5. Click Send Test Notification.

View the test notification

  1. In your DynamoDB dashboard, view the Table with the name of your awsResourcesName field.
  2. View the Items of the table.
  3. Verify that there is an entry for the test push notification you just sent.

View a real push notification

  1. Purchase / Renew / Cancel your subscription.
  2. View the table in your DynamoDB dashboard.

Delete your sample endpoint

Run:

cd path/to/repo
python src/main/python/aws_delete.py

Console output of running 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?
  • 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?

About

Sample website demonstrating how to use LWA and SWA APIs

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published