Git Product home page Git Product logo

opay-sdk-java's Introduction

OPay sdk for java

Latest Stable Version

Welcome to use OPay SDK for Java. OPay SDK for Java allows you to call API without complicated programming.

This document introduces how to obtain and call OPay SDK for Java.

If you have any problem while using OPay SDK for Java, please submit an issue.

Requirements

  • To use OPay SDK for Java, you must have an OPay merchant account as well as an Merchant ID and an AccessKey Secret. Create and view your AccessKey on the Merchant Dashboard.

  • The OPay Java SDK requires JDK 1.8 or later.

Installation

If you use Apache Maven to manage Java projects, you only need to add corresponding dependencies to the pom.xml files of the projects.

<dependency>
     <groupId>com.opayweb</groupId>
     <artifactId>java-sdk-core</artifactId>
     <version>1.0.0-RELEASE</version>
 </dependency>

If maven is not downloading jar packages from a central repository, you need to add these dependencies in the pom.xml file, or a NoClassDefFoundError exception will be reported

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.16</version>
</dependency>

<dependency>
    <groupId>com.konghq</groupId>
    <artifactId>unirest-java</artifactId>
    <version>3.11.11</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.30</version>
</dependency>

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.73</version>
</dependency>

<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk15on</artifactId>
    <version>1.60</version>
    <scope>compile</scope>
</dependency>

Quick Examples

The following code example shows the three main steps to use OPay SDK for Java :

  1. Create and initialize a OPayPaymentClient instance.

  2. Create an API request and set parameters.

  3. Initiate the request and handle the response or exceptions.

package com.opay.java.sdk.samples.cashier;
import com.opay.java.sdk.samples.Config;
import com.opay.sdk.OPayPaymentClient;
import com.opay.sdk.common.DefaultProfile;
import com.opay.sdk.enums.CashierPayMethodEnum;
import com.opay.sdk.enums.CashierPayTypeEnum;
import com.opay.sdk.enums.Environment;
import com.opay.sdk.exception.OPayException;
import com.opay.sdk.model.request.CashierInitializeRequest;
import com.opay.sdk.model.response.CashierInitializeResponse;
import org.apache.http.util.Asserts;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
       
        //initialize config
        DefaultProfile profile = DefaultProfile.getProfile(Environment.SANDBOX, "<your-merchant-id>", "<your-public-key>", "<your-private-key>");
        //Create and initialize a OPayPaymentClient instance
        OPayPaymentClient client = new OPayPaymentClient(profile);
        //Create an API request and set parameters
        CashierInitializeRequest request = new CashierInitializeRequest();
        request.setReference(System.currentTimeMillis() + "");
        request.setMchShortName("Test");
        request.setProductDesc("The best wireless earphone in history");
        request.setProductName("IPhone");
        request.setUserPhone("+2348161564736");
        request.setUserRequestIp("123.4.5.6");
        request.setAmount("100");
        request.setCurrency("NGN");
        List<CashierPayTypeEnum> payTypes = new ArrayList();
        payTypes.add(CashierPayTypeEnum.BalancePayment);
        payTypes.add(CashierPayTypeEnum.OWealth);
        payTypes.add(CashierPayTypeEnum.BonusPayment);
        request.setPayTypes(payTypes);
        List<CashierPayMethodEnum> payMethods = new ArrayList();
        payMethods.add(CashierPayMethodEnum.account);
        payMethods.add(CashierPayMethodEnum.qrcode);
        payMethods.add(CashierPayMethodEnum.bankCard);
        request.setPayMethods(payMethods);
        request.setCallbackUrl("http://www.baidu.com");
        request.setReturnUrl("http://www.baidu.com");
        request.setExpireAt("10");
        System.out.println(request);
        // Initiate the request and handle the response or exceptions
        CashierInitializeResponse response = null;
        try {
            response = client.cashierInitialize(request);
        } catch (OPayException e) {
            e.printStackTrace();
        }
    }
    
        
}

Click here for more samples.

Issues

Opening an Issue, Issues not conforming to the guidelines may be closed immediately.

Changelog

Detailed changes for each release are documented in the release notes.

References

opay-sdk-java's People

Contributors

anwj avatar knightjiang 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.