Skip to content

payload-code/payload-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payload Logo

Powerfully Simple Payments

Payload Documentation Payload Support Java CI

Payload Java Library

A Java library for integrating Payload.

Installation

Maven Dependency

<dependency>
  <groupId>com.payload</groupId>
  <artifactId>payload</artifactId>
  <version>1.0.0</version>
</dependency>

Manual Installation

  1. Download the latest version from GitHub.
  2. Include in Project: Include the Payload folder in your Android Studio or Eclipse project.

Get Started

Once you've included the Payload Java library in your project, include the com.payload.pl namespace to get started. All Payload objects and methods are accessible using the pl static class.

API Authentication

To authenticate with the Payload API, you'll need a live or test API key, accessible from the Payload dashboard.

import com.payload.Session;

Session sess = Session("secret_key_3bW9JMZtPVDOfFNzwRdfE");

Creating an Object

Interfacing with the Payload API is done primarily through Payload Objects. Below is an example of creating a customer using the pl.Customer object.

// Create a Customer
pl.Customer customer = sess.create(new pl.Customer(){{
    set("email", "[email protected]");
    set("full_name", "Matt Perez");
}});
// Create a Payment
pl.Payment payment = sess.create(new pl.Payment(){{
    set("amount", 100.0);
    set("payment_method", new pl.Card(){{
        set("card_number", "4242 4242 4242 4242");
    }});
}});

Accessing Object Attributes

Object attributes are accessible through getStr, getInt, and getFloat.

System.out.print(customer.getStr("email"));

Updating an Object

Updating an object is a simple call to the update object method.

// Updating a customer's email
customer.update(pl.attr("email", "[email protected]"));

Get an Object by ID

Grab an existing object by its ID using the get method.

// Get a customer by id
pl.Customer customer = sess.select(pl.Customer.class).get("cust_id");

Selecting Objects

Objects can be selected using any of their attributes.

// Select a customer by email
List<pl.Customer> customers = sess.select(pl.Customer.class).filter_by(
    "email", "[email protected]"
);

Use the pl.attr attribute helper interface to write powerful queries with a little extra syntax sugar.

List<pl.Payment> payments = sess.select(pl.Payment.class).filter_by(
    pl.attr("amount").gt(100),
    pl.attr("amount").lt(200),
    pl.attr("description").contains("Test"),
    pl.attr("created_at").gt(LocalDate.of(2019, 02, 20))
).all();

Testing the Payload Java Library

Tests are contained within the src/tests directory. To run tests, use the following command in terminal:

API_KEY=your_test_secret_key mvn test

Documentation

For further information on Payload's Java library and API capabilities, visit the Payload Documentation.

About

Payload Java Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages