Skip to content

Commit

Permalink
Updated "RECURRING_CONTRACT" eventCode in webhook controller (#100)
Browse files Browse the repository at this point in the history
* Updated "RECURRING_CONTRACT" eventCode in webhook controller
* Updated readme to include setting up the "RECURRING_CONTRACT" eventCode
* Run workflow once on push vs. pull request
* Upgrade dependencies to latest versions


---------

Co-authored-by: Kwok He Chu <>
  • Loading branch information
Kwok-he-Chu authored Jun 26, 2023
1 parent e9e7231 commit a4a7dad
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Java CI with Gradle

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ env.tmp
.terraform*
terraform.tfstate*
terraform.tfvars

### Visual Studio ###
.vs
4 changes: 2 additions & 2 deletions checkout-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '3.0.6'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}
Expand All @@ -18,7 +18,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'com.adyen:adyen-java-api-library:20.0.0'
implementation 'com.adyen:adyen-java-api-library:20.1.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
Expand Down
4 changes: 2 additions & 2 deletions giftcard-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '3.0.6'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}
Expand All @@ -18,7 +18,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'com.adyen:adyen-java-api-library:20.0.0'
implementation 'com.adyen:adyen-java-api-library:20.1.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
Expand Down
4 changes: 2 additions & 2 deletions paybylink-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.6'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id "com.moowork.node" version "1.3.1"
}
Expand All @@ -16,7 +16,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.adyen:adyen-java-api-library:20.0.0'
implementation 'com.adyen:adyen-java-api-library:20.1.0'

}

Expand Down
8 changes: 6 additions & 2 deletions subscription-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ This demo provides a simple webhook integration at `/api/webhooks/notifications`
- Define username and password (Basic Authentication) to [protect your endpoint](https://docs.adyen.com/development-resources/webhooks/best-practices#security) - Basic authentication only guarantees that the notification was sent by Adyen, not that it wasn't modified during transmission
- Generate the [HMAC Key](https://docs.adyen.com/development-resources/webhooks/verify-hmac-signatures) and set the `ADYEN_HMAC_KEY` in your [Gitpod Environment Variables](https://gitpod.io/variables) with a scope of `*/*` - This key is used to [verify](https://docs.adyen.com/development-resources/webhooks/best-practices#security) whether the HMAC signature that is included in the notification, was sent by Adyen and not modified during transmission
- For the URL, enter `https://gitpod.io` for now, we will need to update this webhook URL in step 7
- Make sure the webhook is **Enabled** to send notifications
- Make sure that the `Recurring contract` setting is **enabled** on `Merchant` account-level - In the `Customer Area`, under `Developers` -> `Webhooks` -> `Settings` -> Enable `Recurring contract` on `Merchant`-level and hit "Save".
- Make sure that your webhook sends the `RECURRING_CONTRACT` event when you've created the webhook
- Make sure the webhook is **enabled** to send notifications


5. In the Customer Area, go to `Developers``Additional Settings` → Under `Payment` enable `Recurring Details` for subscriptions.
Expand Down Expand Up @@ -103,7 +105,9 @@ If you use a tunneling service like ngrok, the webhook URL will be the generated
- Generate the [HMAC Key](https://docs.adyen.com/development-resources/webhooks/verify-hmac-signatures) - This key is used to [verify](https://docs.adyen.com/development-resources/webhooks/best-practices#security) whether the HMAC signature that is included in the notification, was sent by Adyen and not modified during transmission
- See script below that allows you to easily set your environmental variables
- For the URL, enter `https://ngrok.io` for now - We will need to update this webhook URL in step 10
- Make sure the webhook is **Enabled** to send notifications
- Make sure that the `Recurring contract` setting is **enabled** on `Merchant` account-level - In the `Customer Area`, under `Developers` -> `Webhooks` -> `Settings` -> Enable `Recurring contract` on `Merchant`-level and hit "Save".
- Make sure that your webhook sends the `RECURRING_CONTRACT` event when you've created the webhook
- Make sure the webhook is **enabled** to send notifications


7. Set the following environment variables in your terminal environment: `ADYEN_API_KEY`, `ADYEN_CLIENT_KEY`, `ADYEN_MERCHANT_ACCOUNT` and `ADYEN_HMAC_KEY`. Note that some IDEs will have to be restarted for environmental variables to be injected properly.
Expand Down
4 changes: 2 additions & 2 deletions subscription-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '3.0.6'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}
Expand All @@ -18,7 +18,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'com.adyen:adyen-java-api-library:20.0.0'
implementation 'com.adyen:adyen-java-api-library:20.1.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public ResponseEntity<String> webhooks(@RequestBody String json) throws IOExcept

// consume payload
if(item.isSuccess()) {

if (item.getEventCode().equals("AUTHORISATION") && item.getAdditionalData() != null && item.getAdditionalData().get("recurring.shopperReference") != null) {
// read about eventcode "RECURRING_CONTRACT" here: https://docs.adyen.com/online-payments/tokenization/create-and-use-tokens?tab=subscriptions_2#pending-and-refusal-result-codes-1
if (item.getEventCode().equals("RECURRING_CONTRACT") && item.getAdditionalData() != null && item.getAdditionalData().get("recurring.shopperReference") != null) {
// webhook with recurring token
log.info("Recurring authorized - recurringDetailReference {}", item.getAdditionalData().get("recurring.recurringDetailReference"));

Expand Down

0 comments on commit a4a7dad

Please sign in to comment.