Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dzhang update java quickstart #221

Open
wants to merge 26 commits into
base: ac-update-quickstart-docker
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
53262c7
add stub for missing assets endpoint
davidzhanghp Jul 21, 2020
e654218
fix major version for python
davidzhanghp Jul 21, 2020
b8ae678
do not use npm.plaid.com
davidzhanghp Jul 21, 2020
ed790a9
pin ruby to major version
davidzhanghp Jul 21, 2020
1463cf4
Merge pull request #126 from plaid/ac-update-quickstart-docker
davidzhanghp Jul 22, 2020
bd203fe
Merge pull request #125 from plaid/dzhang-sanitize
davidzhanghp Jul 22, 2020
9f3b022
quickstart polishing.
davidzhanghp Jul 22, 2020
0910dca
Merge pull request #127 from plaid/dzhang-polish
davidzhanghp Jul 22, 2020
8a3ee3f
fix typo for check
davidzhanghp Jul 22, 2020
6f32081
Merge pull request #128 from plaid/dzhang-fix-typo
davidzhanghp Jul 22, 2020
f91d1ea
update readmes
Jul 22, 2020
b4e3d5f
Update README.md
otherchen Jul 23, 2020
a93ec2c
Update README.md
otherchen Jul 23, 2020
bb2e84e
Update go/README.md
otherchen Jul 23, 2020
667a7e3
Update node/README.md
otherchen Jul 23, 2020
c92d1f8
Update node/README.md
otherchen Jul 23, 2020
0cc6245
Update ruby/README.md
otherchen Jul 23, 2020
420f05b
Update python/README.md
otherchen Jul 23, 2020
64f04ec
Update README.md
otherchen Jul 23, 2020
b563dc5
Merge pull request #130 from plaid/update-readmes-for-payment-initiation
otherchen Jul 23, 2020
729082b
Update README.md
otherchen Jul 23, 2020
c4c642a
update the rest of the readmes
Jul 23, 2020
116f34c
Merge pull request #131 from plaid/ac-fix-readme-issue
otherchen Jul 23, 2020
8db7b79
format ruby files
davidzhanghp Jul 29, 2020
1726b35
Merge pull request #132 from plaid/dzhang-rubyh-format
davidzhanghp Jul 29, 2020
bcc6350
update java quickstart for 7.0.1
davidzhanghp Aug 6, 2020
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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PLAID_PRODUCTS=transactions
PLAID_COUNTRY_CODES=US,CA
PLAID_REDIRECT_URI=
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Here you'll find full example integration apps using our [**client libraries**][
- [Python][python-example]
- [Java][java-example]

If [docker][] is available to you, you can quickly spin up an example using: `% make QUICKSTART=go up`.
If [docker][docker] is available to you, you can quickly spin up an example using: `% make QUICKSTART=go up`.
Be sure to have `PLAID_CLIENT_ID` and `PLAID_SECRET` defined in your environment or
replace the respective `${VARIABLES}` in the `x-environment` section in
[`docker-compose.yml`](/docker-compose.yml) directly.
Expand All @@ -19,6 +19,10 @@ To further adjust the quickstart to your use-case, you can define `PLAID_PRODUCT
`PLAID_REDIRECT_URI` in your environment or set the respective `${VARIABLES}` in in the `x-environment`
section in [`docker-compose.yml`](/docker-compose.yml) directly.

Note - If you are attempting to test out the OAuth flow, you will need to register your
`PLAID_REDIRECT_URI` in the [Plaid dashboard][dashboard-api-section]. Additionally, if you want to use
the [Payment Initiation][payment-initiation] product, you will need to [contact Sales][contact-sales] to get this product enabled.

To see the log output of the quickstart run: `% make QUICKSTART=go logs` (when done, quit using `CTRL-C`).

To stop the quickstart use: `% make QUICKSTART=go stop`
Expand All @@ -29,9 +33,12 @@ Replace `go` in the command examples above with the name of the quickstart you w

[quickstart]: https://plaid.com/docs/quickstart
[libraries]: https://plaid.com/docs/libraries
[payment-initiation]: https://plaid.com/docs/#payment-initiation
[node-example]: /node
[ruby-example]: /ruby
[python-example]: /python
[java-example]: /java
[go-example]: /go
[docker]: https://www.docker.com
[dashboard-api-section]: https://dashboard.plaid.com/team/api
[contact-sales]: https://plaid.com/contact
15 changes: 8 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: "3.4"
x-environment: &QUICKSTART_ENVIRONMENT
# These are read from .env file. The values in the .env file maybe overriden by shell envvars
PLAID_CLIENT_ID: ${PLAID_CLIENT_ID}
PLAID_SECRET: ${PLAID_SECRET}
PLAID_PRODUCTS: transactions
PLAID_COUNTRY_CODES: US,CA
PLAID_REDIRECT_URI:
PLAID_PRODUCTS: ${PLAID_PRODUCTS}
PLAID_COUNTRY_CODES: ${PLAID_COUNTRY_CODES}
PLAID_REDIRECT_URI: ${PLAID_REDIRECT_URI}
services:
go:
build:
Expand All @@ -14,28 +15,28 @@ services:
environment:
<< : *QUICKSTART_ENVIRONMENT
java:
build:
build:
context: .
dockerfile: ./java/Dockerfile
ports: ["8000:8000"]
environment:
<< : *QUICKSTART_ENVIRONMENT
node:
build:
build:
context: .
dockerfile: ./node/Dockerfile
ports: ["8000:8000"]
environment:
<< : *QUICKSTART_ENVIRONMENT
python:
build:
build:
context: .
dockerfile: ./python/Dockerfile
ports: ["8000:8000"]
environment:
<< : *QUICKSTART_ENVIRONMENT
ruby:
build:
build:
context: .
dockerfile: ./ruby/Dockerfile
ports: ["8000:8000"]
Expand Down
8 changes: 7 additions & 1 deletion go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ which the client can then use to initialize Plaid Link.
When the client initializes Plaid Link with the link token, the Plaid Link
initialization parameters associated with the Plaid Token will be applied.

Note - If you want to use the [Payment Initiation][payment-initiation] product, you will need to [contact Sales][contact-sales] to get this product enabled.
## The OAuth redirect flow
Some European institutions require an OAuth redirect authentication flow,
where the end user is redirected to the bank’s website or mobile app to
authenticate. For this flow, you should provide an additional parameter,
`PLAID_REDIRECT_URI`.
`PLAID_REDIRECT_URI`. You will also need to make sure that you register
this `PLAID_REDIRECT_URI` in the [Plaid dashboard][dashboard-api-section].

``` bash
# You will need to configure the PLAID_REDIRECT_URI for
Expand All @@ -67,3 +69,7 @@ go run server.go

# Go to http://localhost:8000
```

[dashboard-api-section]: https://dashboard.plaid.com/team/api
[payment-initiation]: https://plaid.com/docs/#payment-initiation
[contact-sales]: https://plaid.com/contact
52 changes: 34 additions & 18 deletions go/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ var itemID string

var paymentID string

func renderError(c *gin.Context, err error) {
if plaidError, ok := err.(plaid.Error); ok {
// Return 200 and allow the front end to render the error.
c.JSON(http.StatusOK, gin.H{"error": plaidError})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
}

func getAccessToken(c *gin.Context) {
publicToken := c.PostForm("public_token")
response, err := client.ExchangePublicToken(publicToken)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
renderError(c, err)
return
}
accessToken = response.AccessToken
Expand Down Expand Up @@ -96,25 +105,25 @@ func createLinkTokenForPayment(c *gin.Context) {
Country: "GB",
})
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}
paymentCreateResp, err := client.CreatePayment(recipientCreateResp.RecipientID, "payment-ref", plaid.PaymentAmount{
Currency: "GBP",
Value: 12.34,
})
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}
paymentID = paymentCreateResp.PaymentID
fmt.Println("payment id: " + paymentID)

linkToken, httpErr := linkTokenCreate(&plaid.PaymentInitiation{
linkToken, tokenCreateErr := linkTokenCreate(&plaid.PaymentInitiation{
PaymentID: paymentID,
})
if httpErr != nil {
c.JSON(httpErr.errorCode, gin.H{"error": httpErr.Error()})
if tokenCreateErr != nil {
renderError(c, tokenCreateErr)
}
c.JSON(http.StatusOK, gin.H{
"link_token": linkToken,
Expand All @@ -124,7 +133,7 @@ func createLinkTokenForPayment(c *gin.Context) {
func auth(c *gin.Context) {
response, err := client.GetAuth(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -137,7 +146,7 @@ func auth(c *gin.Context) {
func accounts(c *gin.Context) {
response, err := client.GetAccounts(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -149,7 +158,7 @@ func accounts(c *gin.Context) {
func balance(c *gin.Context) {
response, err := client.GetBalances(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -161,13 +170,13 @@ func balance(c *gin.Context) {
func item(c *gin.Context) {
response, err := client.GetItem(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

institution, err := client.GetInstitutionByID(response.Item.InstitutionID)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -180,7 +189,7 @@ func item(c *gin.Context) {
func identity(c *gin.Context) {
response, err := client.GetIdentity(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -197,7 +206,7 @@ func transactions(c *gin.Context) {
response, err := client.GetTransactions(accessToken, startDate, endDate)

if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -212,7 +221,7 @@ func transactions(c *gin.Context) {
func payment(c *gin.Context) {
response, err := client.GetPayment(paymentID)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -225,8 +234,9 @@ func investmentTransactions(c *gin.Context) {
endDate := time.Now().Local().Format("2006-01-02")
startDate := time.Now().Local().Add(-30 * 24 * time.Hour).Format("2006-01-02")
response, err := client.GetInvestmentTransactions(accessToken, startDate, endDate)
fmt.Println("error", err)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -238,7 +248,7 @@ func investmentTransactions(c *gin.Context) {
func holdings(c *gin.Context) {
response, err := client.GetHoldings(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -260,7 +270,7 @@ func createPublicToken(c *gin.Context) {
// This public_token can be used to initialize Link in update mode for a user
publicToken, err := client.CreatePublicToken(accessToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
renderError(c, err)
return
}

Expand All @@ -272,7 +282,8 @@ func createPublicToken(c *gin.Context) {
func createLinkToken(c *gin.Context) {
linkToken, err := linkTokenCreate(nil)
if err != nil {
c.JSON(err.errorCode, gin.H{"error": err.error})
renderError(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"link_token": linkToken})
}
Expand Down Expand Up @@ -315,6 +326,10 @@ func linkTokenCreate(
return resp.LinkToken, nil
}

func assets(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "unfortunate the go client library does not support assets report creation yet."})
}

func main() {
if APP_PORT == "" {
APP_PORT = "8000"
Expand Down Expand Up @@ -356,6 +371,7 @@ func main() {
r.POST("/api/create_link_token", createLinkToken)
r.GET("/api/investment_transactions", investmentTransactions)
r.GET("/api/holdings", holdings)
r.GET("/api/assets", assets)

err := r.Run(":" + APP_PORT)
if err != nil {
Expand Down
52 changes: 26 additions & 26 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ <h3 class="box__heading">Item management</h3>
}

var accessToken = qs('access_token');
if (accessToken != null && accessToken != '') {
if (accessToken != null && accessToken !== '') {
$.post('/api/set_access_token', {
access_token: accessToken
}, function(data) {
Expand Down Expand Up @@ -374,7 +374,7 @@ <h3 class="box__heading">Item management</h3>
data.numbers.ach.forEach(function(achNumbers, idx) {
// Find the account associated with this set of account and routing numbers
var account = data.accounts.filter(function(a) {
return a.account_id == achNumbers.account_id;
return a.account_id === achNumbers.account_id;
})[0];
html += '<tr>';
html += '<td>' + account.name + '</td>';
Expand All @@ -387,7 +387,7 @@ <h3 class="box__heading">Item management</h3>
data.numbers.eft.forEach(function(eftNumber, idx) {
// Find the account associated with this set of account and routing numbers
var account = data.accounts.filter(function(a) {
return a.account_id == eftNumber.account_id;
return a.account_id === eftNumber.account_id;
})[0];
html += '<tr>';
html += '<td>' + account.name + '</td>';
Expand Down Expand Up @@ -444,16 +444,16 @@ <h3 class="box__heading">Item management</h3>
$('#get-item-btn').on('click', function(e) {
$.get('/api/item', function(data) {
$('#get-item-data').slideUp(function() {
if (data.error) {
if (data.error != null) {
displayError(this, data.error);
} else {
var html = '';
html += '<tr><td>Institution name</td><td>' + data.institution.name + '</td></tr>';
html += '<tr><td>Billed products</td><td>' + data.item.billed_products.join(', ') + '</td></tr>';
html += '<tr><td>Available products</td><td>' + data.item.available_products.join(', ') + '</td></tr>';

$(this).html(html).slideDown();
return;
}
var html = '';
html += '<tr><td>Institution name</td><td>' + data.institution.name + '</td></tr>';
html += '<tr><td>Billed products</td><td>' + data.item.billed_products.join(', ') + '</td></tr>';
html += '<tr><td>Available products</td><td>' + data.item.available_products.join(', ') + '</td></tr>';

$(this).html(html).slideDown();
});
});
});
Expand All @@ -480,22 +480,22 @@ <h3 class="box__heading">Item management</h3>
$(this).html(errorHtml).slideDown();
});
});
} else {
$('#get-transactions-data').slideUp(function() {
var html = '<tr><td><strong>Name</strong></td><td><strong>Amount</strong></td><td><strong>Date</strong></td></tr>';
data.transactions.forEach(function(txn, idx) {
html += '<tr>';
html += '<td>' + txn.name + '</td>';
html += '<td>$' + txn.amount + '</td>';
html += '<td>' + txn.date + '</td>';
html += '</tr>';
});
return;
}
$('#get-transactions-data').slideUp(function () {
var html = '<tr><td><strong>Name</strong></td><td><strong>Amount</strong></td><td><strong>Date</strong></td></tr>';
data.transactions.forEach(function (txn, idx) {
html += '<tr>';
html += '<td>' + txn.name + '</td>';
html += '<td>$' + txn.amount + '</td>';
html += '<td>' + txn.date + '</td>';
html += '</tr>';
});

$(this).slideUp(function() {
$(this).html(html).slideDown();
});
$(this).slideUp(function () {
$(this).html(html).slideDown();
});
}
});
});
});

Expand Down Expand Up @@ -640,7 +640,7 @@ <h3 class="box__heading">Item management</h3>
});
});
});
};
}
$.post('/api/info', {}, function(result) {
render_page(jQuery, result);
});
Expand Down
Loading