Skip to content

MoneyCollect/moneycollect-java-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation


Money Collect SDK for Java

This document introduces how to obtain and call Money Collect SDK for Java. If you have any problem while using Money Collect SDK for Java, please submit an issue.

Money Collect Features Supported by SDK

Requirements

  • Money Collect SDK requires Java 1.8 or later.

Installation

To use the SDK as an example, you only need to declare the following dependency in the file.pom.xml

<dependency>
  <groupId>com.moneycollect</groupId>
  <artifactId>moneycollect-java</artifactId>
  <version>1.0.4</version>
</dependency>

Quick Examples

Before starting, you need to confirm that you have a Private key. see: API-Keys

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

  1. Set Private key.
  2. Build parameters.
  3. Initiate the request and handle the response or exceptions.
package com.moneycollect.MoneyCollect.helloworld;


import com.moneycollect.MoneyCollect;
import com.moneycollect.exception.MoneyCollectException;
import com.moneycollect.model.checkout.Session;
import com.moneycollect.param.checkout.SessionCreateParams;

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

import com.moneycollect.param.checkout.SessionCreateParams.Address;
import com.moneycollect.param.checkout.SessionCreateParams.BillingDetails;
import com.moneycollect.param.checkout.SessionCreateParams.Shipping;
import com.moneycollect.param.checkout.SessionCreateParams.LineItem;

public class Main {
  public static void main(String[] args) throws MoneyCollectException {
    // 1.Set Private key.
    // MoneyCollect.apiKey = "your-api-key";

    // If there is a need to override the API's Base URL, invoke this method.
    // MoneyCollect.overrideApiBase("your-api-base-url");
    // Otherwise, the default provided by SDK will be used.

    // 2.Build parameters.
    List<LineItem> lineItems = new ArrayList<>();
    lineItems.add(LineItem.builder()
            .setAmount(80000L)
            .setCurrency("USD")
            .setName("iPhone")
            .setQuantity(2)
            .setImages(Arrays.asList("https://www.moneycollect.com/static/common/img/shopcart.png"))
            .build());

    SessionCreateParams params = SessionCreateParams.builder()
            .setCustomer("cus_1777230416823037954")
            .setCustomerEmail("[email protected]")
            .setBillingDetails(
                    BillingDetails
                            .builder()
                            .setFirstName("Mark")
                            .setLastName("Merrill")
                            .setPhone("210-627-6464")
                            .setEmail("[email protected]")
                            .setAddress(
                                    Address.builder()
                                            .setCity("North Carolina")
                                            .setCountry("US")
                                            .setLine1("3968 Fidler Drive")
                                            .setState("Asheville")
                                            .setPostalCode("28806")
                                            .build())
                            .build())
            .setShipping(
                    Shipping
                            .builder()
                            .setAddress(Address.builder()
                                    .setCity("North Carolina")
                                    .setCountry("US")
                                    .setLine1("3968 Fidler Drive")
                                    .setState("Asheville")
                                    .setPostalCode("28806")
                                    .build())
                            .setFirstName("Mark")
                            .setLastName("Merrill")
                            .setPhone("210-627-6464")
                            .build())
            .setLineItems(lineItems)
            .setAmountTotal(990L)
            .setCurrency("USD")
            .setCancelUrl("http://localhost:4242/cancle.html")
            .setReturnUrl("http://localhost:4242/return.html")
            .setNotifyUrl("http://localhost:4242/notify.html")
            .setOrderNo("order_id_123456")
            .setWebsite("http://yourwebsite.org")
            .setSubmitType("Pay")
            .setPreAuth(SessionCreateParams.PreAuth.NO)
            .build();

    // 3.Initiate the request and handle the response or exceptions
    Session session = null;
    try {
      session = Session.create(params);
    } catch (MoneyCollectException e) {
      e.printStackTrace();
    }

  }
}

This is just a simple example. You can find what you need in the example project, or you can find unit test cases in the 'src/test' directory of this project.

Issues

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

References

License

Apache-2.0

About

SDK for java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages