amzn/amazon-instant-access-sdk-java

Name: amazon-instant-access-sdk-java

Owner: Amazon

Description: Java SDK to aid in 3p integration with Instant Access

Created: 2015-06-03 22:59:11.0

Updated: 2017-11-01 16:52:33.0

Pushed: 2018-03-13 18:41:37.0

Homepage: null

Size: 103

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Amazon-instant-access-sdk-java

Installation Guide
  1. Download the zip file on GitHub:
    clone https://github.com/amzn/amazon-instant-access-sdk-java.git
    
  2. Import the SDK project as a Maven project in your IDE.
  3. Implement the servlets required for subscriptions or one time purchase.
  4. Run Junit tests to ensure everything is working correctly.

Example Implementation of AccountLinkingServlet

The following example is available under the examples.servlet package:


opyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

icensed under the Apache License, Version 2.0 (the "License").
ou may not use this file except in compliance with the License.
 copy of the License is located at

http://aws.amazon.com/apache2.0

r in the "license" file accompanying this file. This file is distributed
n an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
xpress or implied. See the License for the specific language governing
ermissions and limitations under the License.


age examples.servlet;

rt com.amazon.dtasdk.signature.CredentialStore;
rt com.amazon.dtasdk.v2.serialization.messages.GetUserIdSerializableResponseValue;
rt com.amazon.dtasdk.v3.serialization.messages.GetUserIdSerializableRequest;
rt com.amazon.dtasdk.v3.serialization.messages.GetUserIdSerializableResponse;
rt com.amazon.dtasdk.v3.servlets.AccountLinkingServlet;
rt org.apache.commons.logging.Log;
rt org.apache.commons.logging.LogFactory;


ervlet class that listens to the account linking requests

ic class AccountLinkingServletImpl extends AccountLinkingServlet {

private static final Log log = LogFactory.getLog(AccountLinkingServletImpl.class);

@Override
public CredentialStore getCredentialStore() {
    CredentialStore store = new CredentialStore();

    /**
     *  Add your public and private keys to the CredentialStore
     */

    return store;
}

@Override
public GetUserIdSerializableResponse getUserId(GetUserIdSerializableRequest request) {
    log.info(String.format("Started getUserId with request[%s]", request));

    GetUserIdSerializableResponse response = new GetUserIdSerializableResponse();

    try {
        /**
         * Retrieve userId and set it in the response object
         * response.setUserId(service.getUserId(request));
         */

        response.setResponse(GetUserIdSerializableResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing getUserId[%s]", request), e);
        response.setResponse(GetUserIdSerializableResponseValue.FAIL_ACCOUNT_INVALID);
    }

    log.info(String.format("Finished getUserId with response[%s]", response));

    return response;
}

Example Implementation of PurchaseServlet

The following example is available under examples.servlet package:


opyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

icensed under the Apache License, Version 2.0 (the "License").
ou may not use this file except in compliance with the License.
 copy of the License is located at

http://aws.amazon.com/apache2.0

r in the "license" file accompanying this file. This file is distributed
n an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
xpress or implied. See the License for the specific language governing
ermissions and limitations under the License.


age examples.servlet;

rt com.amazon.dtasdk.base.SubscriptionResponse;
rt com.amazon.dtasdk.base.SubscriptionResponseValue;
rt com.amazon.dtasdk.signature.CredentialStore;
rt com.amazon.dtasdk.v2.serialization.messages.FulfillPurchaseResponseValue;
rt com.amazon.dtasdk.v2.serialization.messages.RevokePurchaseResponseValue;
rt com.amazon.dtasdk.v3.serialization.messages.FulfillPurchaseRequest;
rt com.amazon.dtasdk.v3.serialization.messages.FulfillPurchaseResponse;
rt com.amazon.dtasdk.v3.serialization.messages.RevokePurchaseRequest;
rt com.amazon.dtasdk.v3.serialization.messages.RevokePurchaseResponse;
rt com.amazon.dtasdk.v3.serialization.messages.SubscriptionActivateRequest;
rt com.amazon.dtasdk.v3.serialization.messages.SubscriptionDeactivateRequest;
rt com.amazon.dtasdk.v3.serialization.messages.SubscriptionGetRequest;
rt com.amazon.dtasdk.v3.serialization.messages.SubscriptionGetResponse;
rt com.amazon.dtasdk.v3.serialization.messages.SubscriptionUpdateRequest;
rt com.amazon.dtasdk.v3.servlets.PurchaseServlet;
rt org.apache.commons.logging.Log;
rt org.apache.commons.logging.LogFactory;



ervlet class that listens to the purchases/subscriptions requests

ic class PurchaseServletImpl extends PurchaseServlet {
private static final Log log = LogFactory.getLog(PurchaseServletImpl.class);

@Override
public CredentialStore getCredentialStore() {
    CredentialStore store = new CredentialStore();

    /**
     *  Add your public and private keys to the CredentialStore
     */

    return store;
}

@Override
public FulfillPurchaseResponse fulfillPurchase(FulfillPurchaseRequest request) {
    log.info(String.format("Started fulfillPurchase with request[%s]", request));

    FulfillPurchaseResponse response = new FulfillPurchaseResponse();

    try {
        /**
         * Add logic to fulfill a purchase
         */
        response.setResponse(FulfillPurchaseResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing team fulfillPurchase[%s]", request), e);
        response.setResponse(FulfillPurchaseResponseValue.FAIL_OTHER);
    }

    log.info(String.format("Finished fulfillPurchase with response[%s]", response));

    return response;
}

@Override
public RevokePurchaseResponse revokePurchase(RevokePurchaseRequest request) {
    log.info(String.format("Started revokePurchase with request[%s]", request));

    RevokePurchaseResponse response = new RevokePurchaseResponse();

    try {
        /**
         * Add logic to revoke a purchase
         */

        response.setResponse(RevokePurchaseResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing revokePurchase[%s]", request), e);
        response.setResponse(RevokePurchaseResponseValue.FAIL_OTHER);
    }

    log.info(String.format("Finished revokePurchase with response[%s]", response));

    return response;
}

@Override
public SubscriptionResponse processSubscriptionActivate(SubscriptionActivateRequest request) {
    log.info(String.format("Started processSubscriptionActivate with request[%s]", request));

    SubscriptionResponse response = new SubscriptionResponse();

    try {
        /**
         * Add logic to activate a subscription
         */
        response.setResponse(SubscriptionResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing processSubscriptionActivate[%s]", request), e);
        response.setResponse(SubscriptionResponseValue.FAIL_OTHER);
    }

    log.info(String.format("Finished processSubscriptionActivate with response[%s]", response));

    return response;
}

@Override
public SubscriptionResponse processSubscriptionDeactivate(SubscriptionDeactivateRequest request) {
    log.info(String.format("Started processSubscriptionDeactivate with request[%s]", request));

    SubscriptionResponse response = new SubscriptionResponse();

    try {
        /**
         * Add logic to deactivate a subscription
         */
        response.setResponse(SubscriptionResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing processSubscriptionDeactivate[%s]", request), e);
        response.setResponse(SubscriptionResponseValue.FAIL_OTHER);
    }

    log.info(String.format("Finished processSubscriptionDeactivate with response[%s]", response));

    return response;
}

@Override
public SubscriptionGetResponse processSubscriptionGet(SubscriptionGetRequest request) {
    log.info(String.format("Started processSubscriptionGet with request[%s]", request));

    SubscriptionGetResponse response = new SubscriptionGetResponse();

    try {
        /**
         * Add logic to get a subscription
         */
        response.setResponse(SubscriptionResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing processSubscriptionGet[%s]", request), e);
        response.setResponse(SubscriptionResponseValue.FAIL_OTHER);
    }

    log.info(String.format("Finished processSubscriptionGet with response[%s]", response));

    return response;
}

@Override
public SubscriptionResponse processSubscriptionUpdate(SubscriptionUpdateRequest request) {
    log.info(String.format("Started processSubscriptionUpdate with request[%s]", request));

    SubscriptionResponse response = new SubscriptionResponse();

    try {
        /**
         * Add logic to update a subscription
         */
        response.setResponse(SubscriptionResponseValue.OK);
    } catch (Exception e) {
        log.error(String.format("Error while processing processSubscriptionUpdate[%s]", request), e);
        response.setResponse(SubscriptionResponseValue.FAIL_OTHER);
    }

    log.info(String.format("Finished processSubscriptionUpdate with response[%s]", response));

    return response;
}


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.