Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions CRIP/CRIP-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
| proposal | title | description | author | discussions-to | status | type | category | created | requires |
|----------|--------------------|-------------------------------|----------------------------|----------------|--------|-------------|----------|------------|----------|
| CRIP-1 | Amazon Seller Integration | Integration with Amazon Seller API to verify orders | Aetesh Ch [email protected] | | Draft | Integration | CRIP | 2024-07-09 | |

## Title

Amazon Seller Integration

## Introduction

This proposal outlines the integration of Amazon Seller as a data provider for the Catoff-Reclaim integration project. The integration aims to retrieve and process user order data from Amazon Seller, such as the number of orders sold, to be used within the Catoff platform. This will enable users to validate their sales performance and use it for various challenges and verifications on Catoff.

## External APIs Needed

- Amazon Seller API: https://developer-docs.amazon.com/sp-api/docs

## Use Cases

1. **User Verification**: Verify the sales activity of users on Amazon by checking their order history.
2. **Loan Applications**: Support users in providing verified sales data for loan or credit applications, showcasing their business performance.
3. **Tax Documentation**: Provide users with verified sales data for accurate and streamlined tax reporting and redemption.

## Data Provider

- **Name**: Amazon Seller Orders - Fix
- **Hash Value**: 0x37a34b1c65f5d2a8e74b919a8e7743b5c2e0c98b4d8b9c2f64e3e7e9a84a9f2e

## Code Snippet

Below is a code snippet that demonstrates the key parts of the GitHub integration. The full implementation should follow the service file template.

**`services/amazonSellerService.js`**

```javascript
const axios = require('axios')
const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse')

exports.processAmazonSellerData = async (proof, providerName) => {
const sellerId = JSON.parse(proof[0].claimData.context).extractedParameters
.sellerId
const lastUpdateTimeStamp = proof[0].claimData.timestampS

const orderCount = await getSellerOrders(sellerId)

return new ReclaimServiceResponse(
providerName,
lastUpdateTimeStamp,
sellerId,
orderCount,
proof[0]
)
}

const getSellerOrders = async sellerId => {
// Defining the start date to calculate orders
const startDate = '2020-01-01'
const endDate = new Date().toISOString().split('T')[0]
const url = `https://sellingpartnerapi-na.amazon.com/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER&CreatedAfter=${startDate}&CreatedBefore=${endDate}&SellerId=${sellerId}`
const amazonToken = process.env.RECLAIM_AMAZON_SELLER_TOKEN

const response = await axios.get(url, {
headers: {
'x-amz-access-token': amazonToken,
'x-amz-date': new Date().toISOString(),
'x-amz-security-token': process.env.AMAZON_SESSION_TOKEN,
Authorization: `AWS4-HMAC-SHA256 Credential=${process.env.AWS_ACCESS_KEY_ID}/${new Date().toISOString().split('T')[0]}/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=${process.env.AWS_SECRET_ACCESS_KEY}`,
},
})

const orders = response.data.Orders
console.log(
`Total orders for seller ${sellerId} since ${startDate}: ${orders.length}`
)
return orders.length
}
```
74 changes: 0 additions & 74 deletions CRIP/CRIP-1.md

This file was deleted.

41 changes: 41 additions & 0 deletions src/services/amazonSellerService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const axios = require('axios')
const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse')

exports.processAmazonSellerData = async (proof, providerName) => {
const sellerId = JSON.parse(proof[0].claimData.context).extractedParameters
.sellerId
const lastUpdateTimeStamp = proof[0].claimData.timestampS

const orderCount = await getSellerOrders(sellerId)

return new ReclaimServiceResponse(
providerName,
lastUpdateTimeStamp,
sellerId,
orderCount,
proof[0]
)
}

const getSellerOrders = async sellerId => {
// Defining the start date to calculate orders
const startDate = '2020-01-01'
const endDate = new Date().toISOString().split('T')[0]
const url = `https://sellingpartnerapi-na.amazon.com/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER&CreatedAfter=${startDate}&CreatedBefore=${endDate}&SellerId=${sellerId}`
const amazonToken = process.env.RECLAIM_AMAZON_SELLER_TOKEN

const response = await axios.get(url, {
headers: {
'x-amz-access-token': amazonToken,
'x-amz-date': new Date().toISOString(),
'x-amz-security-token': process.env.AMAZON_SESSION_TOKEN,
Authorization: `AWS4-HMAC-SHA256 Credential=${process.env.AWS_ACCESS_KEY_ID}/${new Date().toISOString().split('T')[0]}/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=${process.env.AWS_SECRET_ACCESS_KEY}`,
},
})

const orders = response.data.Orders
console.log(
`Total orders for seller ${sellerId} since ${startDate}: ${orders.length}`
)
return orders.length
}
4 changes: 4 additions & 0 deletions src/services/reclaimService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { Reclaim } = require('@reclaimprotocol/js-sdk')
const { RECLAIM_PROVIDER_ID, RECLAIM_APP_ID } = require('../utils/constants')
const { processTwitterData } = require('./twitterService')
const { processGitHubData } = require('./githubService')
const { processAmazonSellerData } = require('./amazonSellerService')

exports.signWithProviderID = async (userId, providerId) => {
const providerName = RECLAIM_PROVIDER_ID[providerId]
Expand Down Expand Up @@ -49,6 +50,9 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => {
case 'GITHUB_ACCOUNT_VERIFICATION':
processedData = await processGitHubData(proof, providerName)
break
case 'AMAZON_SELLER_INTEGRATION_SERVICE':
processedData = await processAmazonSellerData(proof, providerName)
break
default:
throw new Error(`No handler for provider: ${providerName}`)
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
exports.RECLAIM_PROVIDER_ID = {
twitter: 'TWITTER_ANALYTICS_VIEWS',
github: 'GITHUB_ACCOUNT_VERIFICATION',
amazonSeller: 'AMAZON_SELLER_INTEGRATION_SERVICE',
}

exports.RECLAIM_APP_ID = {
TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id',
GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id',
AMAZON_SELLER_INTEGRATION_SERVICE: 'your-amazon-seller-app-id',
}
Loading