Documentation
HOMEAPI ReferencePayment Demo
English
English
  • 📖Home
  • API Reference
  • Wallet
    • Activate Account
    • Multi-currency Balance
    • Global Collection Account
    • Payout
    • Account settings
  • Payment
    • Get started
    • Accept a payment
      • Hosted payment page
      • In-page checkout
      • iOS
      • Android
      • API-Direct
    • Save a card during payment
      • iOS
      • Android
    • Pre-authorize a payment
    • 3D secure authentication
      • iOS
      • Android
    • Subscriptions
      • Recurring
    • Add payment methods
      • Supported APM codes and attributes list
      • APM Integration Guide
    • After the payment
      • Webhook
      • Refunds
      • Response handling
    • About the APIs
      • Currencies
      • Payments
        • How payments work
  • Business Operation
    • MoneyCollect dashboard
      • Home
      • Mobile apps
    • Account
      • Your account
      • Multiple Accounts
      • Account security
    • Alternative payment methods
      • Apply for APMs from your dashboard
        • Google pay
    • Customers
      • Customer portal
    • Products & Prices
      • Pricing table
    • Invoicing
      • How invoicing works
      • Use the dashboard
        • Customers
        • Products and prices
        • Invoice page
      • Hosted Invoice Page
      • No-code quickstart guide
    • Subscriptions
      • Subscription status
      • Subscription settings
      • Create a subscription
    • Pricing
      • Reserves
      • Fees for APMs
    • Payouts
    • Financial reports
      • Select preferred report
      • Balance summary
      • Payout reconciliation
    • Partners
      • Partner pricing
    • Risk management
      • Disputes
        • How disputes work
        • Respond to disputes
          • Dispute reasons
        • Measuring disputes
      • Fraud
        • Monitoring programs
        • High risk merchant lists
        • Tools
        • Fraud prevention
    • Start a team
      • Teams
      • User roles
    • Startup incorporation
  • Developer tools
    • API-Keys
    • Libraries
    • Plugins
      • WooCommerce
      • Magento
        • Using Magento 2 Admin Panel
      • Shopify
        • MoneyCollect Payments App
        • Legacy Version
          • Credit Card Direct Payments App
          • Credit Card Redirected Payments App
          • Alternative Payment Methods App
      • Wix
      • SHOPLINE
      • SHOPLAZZA
      • Xshoppy
      • ShopBase
      • PrestaShop
      • OpenCart
      • AllValue
        • Using Allvalue Panel
Powered by GitBook
On this page
  • 1. Set up MoneyCollect
  • 2. Create PaymentMethod
  • 3. Create a payment
  • 4. Confirm a payment
  • 5. Verification action required
  • 6. Inquire about a transaction
  • 7.Additional testing resources
  1. Payment
  2. Accept a payment

API-Direct

PreviousAndroidNextSave a card during payment

Last updated 1 year ago

Use Server to Server : Connect through the JAVA SDK provided by MoneyCollect.

1. Set up MoneyCollect

Firstly, make sure that you have set up an account name on the MoneyCollect dashboard.

2. Create PaymentMethod

PaymentMethod is the necessary prerequisite to charge.

PaymentMethod can specify different payment methods,such as credit cards, Alipay, WeChat Pay, etc. Different payment methods require different parameters. For example: Billing information and card information are required for credit cards, but not for Alipay.

The following code shows how to create a PaymentMethod through the SDK:

// Use your private key
MoneyCollect.apiKey = "live_pr_KQjlYQdmWygTO8m*********";

// Build card
PaymentMethodCreateParams.Card card = PaymentMethodCreateParams.Card.builder()
        .setCardNo("4242424242424242")
        .setExpYear("2024")
        .setExpMonth("12")
        .setSecurityCode("123")
        .build();
        
// Build billing details for card
PaymentMethodCreateParams.BillingDetails billingDetails = PaymentMethodCreateParams.BillingDetails.builder()
        .setAddress(PaymentMethodCreateParams.Address.builder()
                .setCity("Hong Kong")
                .setCountry("CN")
                .setLine1("193 Prince Edward Road")
                .setLine2("")
                .setPostalCode("12222")
                .setState("Hong Kong").build() )
        .setEmail("test@mc.com")
        .setFirstName("Su")
        .setLastName("Diana")
        .setPhone("12222211")
        .build();
// Build payment method
PaymentMethodCreateParams params =
        PaymentMethodCreateParams.builder()
                .setType(PaymentMethodCreateParams.PaymentMethodType.CARD)
                .setCard(card)
                .setBillingDetails(billingDetails)
                .build();
// Create payment method
PaymentMethod paymentMethod = PaymentMethod.create(params);

3. Create a payment

 PaymentCreateParams params =
        PaymentCreateParams.builder()
                .setAmount(18*100L)
                .setCurrency("USD")
                .setOrderNo("MC"+System.currentTimeMillis())
                .setNotifyUrl("http://localhost:4242/notify")
                .setIp("103.48.140.12") // customer ip 
                .build();

Payment payment =  Payment.create(params);  //

Create a payment and automatically charge by setting the "confirm" parameter to true and specifying the "paymentMethod" parameter.

4. Confirm a payment

PaymentConfirmParams paymentConfirmParams = PaymentConfirmParams.builder()
                                            .setPaymentMethod({{paymentMethodId}})
                                            .build();
Payment payment = Payment.retrieve({{paymentId}});
payment.confirm(paymentConfirmParams);

If you want to create a transaction and charge automatically, you can refer to the following code:

PaymentCreateParams params =
        PaymentCreateParams.builder()
                .setAmount(18*100L)
                .setCurrency("USD")
                .setOrderNo("MC"+System.currentTimeMillis())
                .setNotifyUrl("http://localhost:4242/notify")
                .setIp("103.48.140.12") // customer ip
                .setConfirm(true)
                .setPaymentMethod({{paymentMethodId}})
                .build();

Payment payment =  Payment.create(params);  

5. Verification action required

For some transactions, customers may be required to perform verification actions, such as 3D secure authentication or Alipay to scan code. Payment will return nextAction when confirming the charge. At this time, you need to do additional actions, redirect or display the QR code according to the different type of nextAction.

"nextAction": {
    "type": "redirect",
    "redirectToUrl": "
        https://test-payment.moneycollect.com/authentication?type=2&param=eyJwYXltZW50SWQiOiJwdF8xNDk4MTE3MzQxMjc0NDIzMjk4IiwidGhyZWVEc1VybCI6Imh0dHBzOi8XXXXXXXX
}

6. Inquire about a transaction

After the payment is completed, we will return the result to thereturnUrlyou set and send a notification tonotifyUrl. You can also inquire the result of this payment through API or SDK.

Payment payment = Payment.retrieve("pt_1497139547656585217");

7.Additional testing resources

There are several test cards you can use to make sure your integration is ready for production. Use them with any CVC, postal code, and future expiration date.

Card Number
Brand
Description

4242 4242 4242 4242

Visa

Succeeds and immediately processes the payment.

3566 0020 2036 0505

JCB

Succeeds and immediately processes the payment.

6011 1111 1111 1117

Discover

Succeeds and immediately processes the payment.

3782 8224 6310 0052

American Express

Succeeds and immediately processes the payment.

5555 5555 5555 4444

Mastercard

Succeeds and immediately processes the payment.

4000002500003155

Visa

This card requires 3D authentication on all transaction

4000 0000 0000 0077

Visa

Always fails with a decline code of declined.

Download our SDK