Giter Club home page Giter Club logo

paddle-verifier's Introduction

Paddle Verifier Logo

Paddle Webhook Verifier

Maven Central Quality Gate Status Coverage Maintainability Rating Reliability Rating GitHub license

What is it?

A small utility library (without any external dependecies) for verifying paddle webhooks via Public key and given signature. Paddle is an online payment gateway and more details about verifying paddle webhooks can be found on their official documentation.


How to get it?

Maven

Include it in your Maven projects.

<dependency>
  <groupId>com.jamiussiam</groupId>
  <artifactId>paddle-verifier</artifactId>
  <version>2.1</version>
</dependency>

Gradle

Include it in your Gradle projects.

implementation 'com.jamiussiam:paddle-verifier:2.1'

Jar File

You can download the *.jar file from release.


How to use it?

Using Paddle Verifier is very easy. Firstly, import it from the package.

import com.jamiussiam.paddle.verifier.Verifier;

Then use it as shown,

String publicKey;
String postBody;

Verifier verifier = new Verifier(publicKey);
boolean isValid = verifier.verifyDataWithSignature(postBody);

Detailed Guide

Constructor Parameter

publicKey is quite self explanatory, it's the String representation of your public key. For example,

String publicKey =  "-----BEGIN PUBLIC KEY-----\n" +
                    "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIfVXds6Dfo+EZGFcOJPuhUverHOConA\n" +
                    "j51EQuVpAEhPw6PgyZCi504jxNgiGj6YVOkEJtz5C2d3mgJzsBJs6fUCAwEAAQ==\n" +
                    "-----END PUBLIC KEY-----\n";

Method Parameter

postBody is your POST data from Paddle webhook and it should be in this format,

alert_id=1688369608&balance_currency=GBP&balance_earnings=438.94&balance_fee=689.32  ....

It should contain p_signature key. The key value pairs should be separated by & and the post body should be URL Encoded. (Paddle does this by dafault)


Spring Boot

In spring boot, you can define the bean by,

String publicKey;

@Bean
public Verifier getVerifier() {
    return new Verifier(publicKey);
}

Then, inject it inside your Controller or Component like,

@Autowired
Verifier verifier;

Finally, you can use it to verify incoming requests from Paddle,

@PostMapping(value = "/webhook/", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
private boolean webhook(HttpEntity<String> httpEntity) {

    // Get the validity staus of the request
    boolean isValid = verifier.verifyDataWithSignature(httpEntity.getBody());

    if (isValid) {
        // ... your logic goes here
    }

    return isValid;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.