Coder Social home page Coder Social logo

pwinty-java-sdk's Introduction

Pwinty-Java-SDK

A java library for communicating with the Pwinty API.

v2.2 of the API is supported. If you want an older version, use an older build ;)

Releases

  • v2.2.6 - Added ability to add a photo via an InputStream as well as a File or URL.

Usage

Everything is done with an Order object:

// Choose Environment.LIVE for real orders
Pwinty pwinty = new Pwinty(Environment.SANDBOX, "merchant-id", "api-key");

// Construct a new Order
Order order = new Order(pwinty, CountryCode.GB, CountryCode.GB, QualityLevel.Standard, false);
order.setRecipientName("Matt Burns");
order.setAddress1("123 Some Street");
order.setAddress2("Some Village");
order.setAddressTownOrCity("Bristol");
order.setStateOrCounty("Bristol");
order.setPostalOrZipCode("BS1 123");

// Upload a photo
File file = new File("kittens.jpg");
order.addPhoto(file, Type._4x6, 1, Sizing.Crop);

// Check the Order is valid for submission
if (order.getSubmissionStatus().isValid()) {
    // Submit it for printing and posting
    order.submit();
}

Download

Best to checkout, then run gradle install. Then you can just add this to your gradle deps: compile 'uk.co.mattburns.pwinty:pwinty-java-sdk:2.2.6'

Alternatively, add the jar to your project. You can find the jar in the [build directory] (https://github.com/mattburns/pwinty-java-sdk/tree/master/build/libs)

Error Handling

Any call to the API could throw a PwintyError which is an unchecked exception. It's up to you if you want to catch and handle it. See the Pwinty API documentation for potential errors.

try {
	order.submit();
} catch (PwintyError e) {
	System.out.println(e.getCode() + ": " + e.getError());
}

Dependencies

Dependencies are managed (and listed) in build.gradle

Contribute/Extend

Everything is built using standard gradle.

Running the tests

This library has a comprehensive test suite which is helpful as the Pwinty API evolves. To run the tests yourself, run the following commands (replacing "12345" with your API ID and KEY appropriately):

git clone https://github.com/mattburns/pwinty-java-sdk.git
cd pwinty-java-sdk
echo PWINTY_MERCHANT_ID_SANDBOX=12345 > test-settings.properties
echo PWINTY_MERCHANT_KEY_SANDBOX=12345 >> test-settings.properties
cp test-settings.properties src/test/resources/uk/co/mattburns/pwinty/v2_2/

gradle test

More

See the test code for more usage examples.

pwinty-java-sdk's People

Contributors

mattburns avatar ndtreviv avatar

Watchers

James Cloos avatar  avatar  avatar

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.