Code Monkey home page Code Monkey logo

paymongo-java's Introduction

PayMongo Java Library

PayMongo Java library provides java applications an easy access to the PayMongo API. Explore various classes that can represent API resources on object instantiation. The goal of this library is simplify PayMongo integration with any java application.

Pending TODOs

  • Unit Tests

Documentation

See the PayMongo API docs.

Requirements

  • Java 1.8 or later

Gradle users

Add this dependency to your project's build file:

  • TBD

Maven users

Add this dependency to your project's POM:

  • TBD

Others

You'll need to manually install the following JARs:

  • [The PayMongo JAR]

Usage

The library needs to be configured with your account's secret key which is available in your [PayMongo Dashboard][api-keys]. Initialize the library to its value:

PaymongoExample.java

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.paymongo.Paymongo;
import com.paymongo.services.PaymentIntent;

public class PaymongoExample {
  public static void main(String[] args) {
    // Set api key config
    Paymongo.api_key = "sk_...";

    // Payment Method
    var payment_method = PaymentMethod.retrieve("pm_...");

    // Retrieve attributes
    System.out.println(payment_method.id);
    System.out.println(payment_method.type);

    Map<String, Object> params = new HashMap<>();
    params.put("email", "[email protected]");
    params.put("name", "Pay Mongo");
    params.put("phone", "09123456789");
    params.put("type", "gcash");

    PaymentMethod.create(params);

    // Payment Intent
    var payment_intent = PaymentIntent.retrieve("pi_...");

    Map<String, Object> params = new HashMap<>();
    params.put("amount", 10000);
    params.put("currency", "PHP");
    params.put("description", "Dog Treat");
    params.put("payment_method_allowed", Arrays.asList("gcash"));

    PaymentIntent.create(params);

    Map<String, Object> params = new HashMap<>();
    params.put("payment_method", "pi_...");
    params.put("return_url", "https://test/success");

    PaymentIntent.attach("pi_...", params);

    PaymentIntent.cancel("pi_...");

    Map<String, Object> params = new HashMap<>();
    params.put("amount", payment_intent.amount);

    PaymentIntent.capture("pi_...", params);

    // Payment
    Payment.retrieve("pay_...");

    // Refund
    Refund.retrieve("ref_...");

    Map<String, Object> params = new HashMap<>();
    params.put("amount", 10000);
    params.put("payment_id", "pay_...");
    params.put("reason", "requested_by_customer");

    Refund.create(params);

    // Customers
    Map<String, Object> params = new HashMap<>();
    params.put("default_device", "phone");
    params.put("email", "[email protected]");
    params.put("first_name", "Pay");
    params.put("last_name", "Mongo");
    params.put("phone", "+624123456784");

    Customer.create(params);

    Customer.retrieve("cus_...");

    Map<String, Object> params = new HashMap<>();
    params.put("first_name", "Pay_");
    params.put("last_name", "Mongo_");

    Customer.update("cus_...", params);

    Customer.delete("cus_...");
  }
}
// Links
Link.retrieve("link_...");

Link.archive("link_...");

Link.unarchive("link_...");

Map<String, Object> params = new HashMap<>();
params.put("amount", 10000);
params.put("description", "link description");
params.put("remarks", "link remarks");

Link.create(params);

Map<String, Object> params = new HashMap<>();
params.put("reference_number", "1234abc");

Link.all(params);
// Webhooks
Webhook.retrieve("hook_...");

Map<String, Object> params = new HashMap<>();
params.put("events",  Arrays.asList("payment.refunded", "payment.refund.updated"));
params.put("url", "http://localhost:3100/webhook");

Webhook.create(params);

Webhook.disable("hook_...");

Webhook.enable("hook_...");

Map<String, Object> params = new HashMap<>();
params.put("events",  Arrays.asList("payment.refunded", "payment.refund.updated"));
params.put("url", "http://localhost:3101/webhook");

Webhook.update("hook_...", params);

Webhook.all();

Error handling

try {
  Paymongo.api_key = "sk_...";

  var payment_intent = PaymentIntent.retrieve("pi_...");
} catch (StandardException e) {
  // Handle error
  System.out.println(e.getErrors().get(0).getCode());
  System.out.println(e.getErrors().get(0).getDetail());
  System.out.println(e.getErrors().get(0).getSource());
}

paymongo-java's People

Contributors

aleliepangilinan avatar traqy-paymongo avatar josephisleta avatar rhizamae 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.