Skip to content

Instantly share code, notes, and snippets.

@wehub
Last active June 29, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wehub/49d321f61a1a7c01332e2bb00c651937 to your computer and use it in GitHub Desktop.
Save wehub/49d321f61a1a7c01332e2bb00c651937 to your computer and use it in GitHub Desktop.
Java_SDK
package com.wepay;
import com.wepay.exception.InvalidParams;
import com.wepay.exception.WePayException;
import com.wepay.model.resource.PaymentMethod;
import com.wepay.model.additional_params.PaymentMethodsCreateAdditionalParams;
import com.wepay.endpoints.PaymentMethodsApi;
import com.wepay.model.data.AddressPaymentsReq;
import com.wepay.model.data.Phone;
import com.wepay.model.data.CardHolderReq;
import com.wepay.model.data.RequestCreditCard;
import com.wepay.model.data.PaymentMethodReq;
import com.wepay.model.enums.CountryEnum;
import com.wepay.model.enums.TypeEnum3;
import com.wepay.model.enums.VirtualTerminalModeEnum2;
import com.wepay.network.Configuration;
import com.wepay.network.WePayRequest;
import java.util.logging.Level;
import java.util.logging.Logger;
public class WePay {
private final static Logger LOGGER =
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.setAppId(<APP ID>);
configuration.setAppToken(<APP Token>);
configuration.setEnvironment(Configuration.Environment.STAGE);
WePayRequest.initializeRequest();
try {
PaymentMethodsCreateAdditionalParams paymentMethodsCreateAdditionalParams = new PaymentMethodsCreateAdditionalParams();
paymentMethodsCreateAdditionalParams.setClientIp("100.166.99.123");
paymentMethodsCreateAdditionalParams.setUniqueKey("234445");
paymentMethodsCreateAdditionalParams.setWepayRiskToken("123e4567-e89b-12d3-a456-426655440000");
AddressPaymentsReq addressPaymentsReq = new AddressPaymentsReq();
addressPaymentsReq.setCity("Redwood City");
addressPaymentsReq.setCountryCode(CountryEnum.US);
addressPaymentsReq.setLine1("150 Convention Way");
addressPaymentsReq.setPostalCode("94025");
addressPaymentsReq.setRegion("CA");
Phone phone = new Phone();
phone.setCountryCode("1");
phone.setPhoneNumber("5555551111");
phone.setType(TypeEnum3.MOBILE);
CardHolderReq holderReq = new CardHolderReq();
holderReq.setEmail("example@wepay.com");
holderReq.setHolderName("John Snow");
holderReq.setAddressPaymentsReq(addressPaymentsReq);
holderReq.setPhone(phone);
RequestCreditCard creditCard = new RequestCreditCard();
creditCard.setAutoUpdate(false);
creditCard.setCardNumber("5496198584584769");
creditCard.setCardOnFile(false);
creditCard.setCvv("007");
creditCard.setExpirationMonth(4);
creditCard.setExpirationYear(2023);
creditCard.setVirtualTerminalMode(VirtualTerminalModeEnum2.MOBILE);
creditCard.setTriggerVerification(true);
creditCard.setHolderReq(holderReq);
PaymentMethodReq paymentMethodReq = new PaymentMethodReq(TypeEnum3.CREDIT_CARD, creditCard);
PaymentMethod paymentMethod = PaymentMethodsApi.create(paymentMethodReq, paymentMethodsCreateAdditionalParams);
}
catch (InvalidParams e) {
LOGGER.info("handling invalid params error");
LOGGER.warning(e.getMessage());
}
catch (WePayException e) {
LOGGER.info("handling invalid params error");
LOGGER.warning(e.getMessage());
for (WePayException.Detail detail : e.getDetails()) {
LOGGER.warning(String.join(".", detail.getTarget()));
LOGGER.warning(detail.getMessage());
}
}
catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment