Skip to content

vincenzolabs/PayMaya-Java-Spring-SDK

Repository files navigation

Maya Java Spring SDK

Java CI with Gradle

The Maya-Java-Spring-SDK is a client library written in Java 17 and Spring Boot 3 for invoking Maya (formerly PayMaya) payment services.

Development Environment

Compilation and Unit Testing

  • Run ./gradlew clean build

Component Testing

  • Run ./gradlew clean componentTest

Integration Testing

  • Run ./gradlew clean integrationTest

Usage

Gradle

  • In your build.gradle, add the dependency:
implementation "org.vincenzolabs:maya-java-spring-sdk:$mayaVersion"

Maven

  • In your pom.xml, add the dependency:
<dependency>
    <groupId>org.vincenzolabs</groupId>
    <artifactId>maya-java-spring-sdk</artifactId>
    <version>${maya.version}</version>
</dependency>

Configuration

  • In your application-test.yaml, set the following properties:
maya:
  key:
    public: pk-MOfNKu3FmHMVHtjyjG7vhr7vFevRkWxmxYL1Yq6iFk5
    secret: sk-NMda607FeZNGRt9xCdsIRiZ4Lqu6LT898ItHbN4qPSe
  payment:
    gateway:
      url: https://pg-sandbox.paymaya.com
  • In your application.yaml, specify your production keys and point the payment gateway URL to https://pg.paymaya.com.

Client

  • In your client code, inject MayaV1Client.
  • To let your customer pay using their PayMaya wallet:
PaymentRequest request = PaymentRequest.builder()
    .totalAmount(Amount.builder()
        .currency(Currency.PHP)
        .value(BigDecimal.valueOf(100.00))
        .build())
    .redirectUrl(RedirectUrl.builder()
        .success("http://shop.someserver.com/success?id=6319921")
        .failure("http://shop.someserver.com/failure?id=6319921")
        .cancel("http://shop.someserver.com/cancel?id=6319921")
        .build())
    .requestReferenceNumber("6319921")
    .build();

Mono<SinglePaymentPOSTResponse> responseMono = client.createSinglePayment(request);
  • To let your customer pay using a credit card, debit card, digital wallet e.g. GCash, or PayPal:
CheckoutRequest request = CheckoutRequest.builder()
    .totalAmount(Amount.builder()
        .value(BigDecimal.valueOf(100))
        .currency(Currency.PHP)
        .details(Amount.Details.builder()
            .subtotal(BigDecimal.valueOf(100))
            .build())
        .build())
    .buyer(Customer.builder()
        .firstName("John")
        .middleName("Paul")
        .lastName("Doe")
        .birthday(LocalDate.of(1995, 10, 24))
        .customerSince(LocalDate.of(1995, 10, 24))
        .sex(Sex.M)
        .contact(Customer.Contact.builder()
            .phone("+639181008888")
            .email("merchant@merchantsite.com")
            .build())
        .shippingAddress(Customer.ShippingAddress.builder()
            .firstName("John")
            .middleName("Paul")
            .lastName("Doe")
            .phone("+639181008888")
            .email("merchant@merchantsite.com")
            .line1("6F Launchpad")
            .line2("Reliance Street")
            .state("Metro Manila")
            .zipCode("1552")
            .countryCode("PH")
            .shippingType(ShippingType.ST)
            .build())
        .billingAddress(Customer.Address.builder()
            .line1("6F Launchpad")
            .line2("Reliance Street")
            .state("Metro Manila")
            .zipCode("1552")
            .countryCode("PH")
            .build())
        .build())
    .items(Collections.singleton(Item.builder()
        .name("Canvas Slip Ons")
        .quantity(1)
        .code("CVG-096732")
        .description("Shoes")
        .amount(Amount.builder()
            .value(BigDecimal.valueOf(100))
            .details(Amount.Details.builder()
                .subtotal(BigDecimal.valueOf(100))
                .build())
            .build())
        .totalAmount(Amount.builder()
            .value(BigDecimal.valueOf(100))
            .details(Amount.Details.builder()
                .subtotal(BigDecimal.valueOf(100))
                .build())
            .build())
        .build()))
    .redirectUrl(RedirectUrl.builder()
        .success("https://www.merchantsite.com/success")
        .failure("https://www.merchantsite.com/failure")
        .cancel("https://www.merchantsite.com/cancel")
        .build())
    .requestReferenceNumber("1551191039")
    .build();

Mono<CheckoutPOSTResponse> responseMono = client.createCheckoutPayment(request);

About

The PayMaya client library using Java 15 and Spring 5.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages