Payment

The Application API provides information about your app and its associated users.

Authorization

Create an authorization url in order for your users to give consent for the payment.

PaymentRequest paymentRequest = new PaymentRequest();

Amount amount = new Amount();
amount.setAmount(new BigDecimal(1));
amount.setCurrency("GBP");

Payee payee = new Payee();
payee.setName("John Doe");

List<AccountIdentification> payeeAccountIdentifications = new ArrayList<>();

AccountIdentification accountNumberIdentification = new AccountIdentification();
accountNumberIdentification.setType(AccountIdentification.TypeEnum.ACCOUNT_NUMBER);
accountNumberIdentification.setIdentification("70000005");
payeeAccountIdentifications.add(accountNumberIdentification);

AccountIdentification sortCodeIdentification = new AccountIdentification();
sortCodeIdentification.setType(AccountIdentification.TypeEnum.SORT_CODE);
sortCodeIdentification.setIdentification("700001");
payeeAccountIdentifications.add(sortCodeIdentification);

payee.setAccountIdentifications(payeeAccountIdentifications);

paymentRequest.setAmount(amount);
paymentRequest.setPayee(payee);
paymentRequest.setType(PaymentRequest.TypeEnum.DOMESTIC_PAYMENT);
paymentRequest.setReference("Sending £1.00 to John Doe via. Yapily");
paymentRequest.setPaymentIdempotencyId("anyUniqueStringOver18characters");

PaymentsApi paymentsApi = new PaymentsApi();
PaymentAuthorisationRequest paymentAuthorisationRequest = new PaymentAuthorisationRequest();
paymentAuthorisationRequest.setApplicationUserId(applicationUserId);
paymentAuthorisationRequest.setInstitutionId(institutionId);
paymentAuthorisationRequest.setPaymentRequest(paymentRequest);
ApiResponseOfPaymentAuthorisationRequestResponse authorizationResponse = 
                        paymentsApi.createPaymentAuthorisationUsingPOST(paymentAuthorisationRequest, null, null, null);

String redirectUrl = authorizationResponse.getData().getAuthorisationUrl();

Redirect

Once you've retrieved the redirectUrl for the user's institution, you should redirect the user to the banks page where they will be asked to consent for the payment.

Payment

Submit a payment request using the same payment request object in the authorization request and the AUTHORIZED consent given by the user:

String consentToken = consent.getConsentToken();
ApiResponseOfPaymentResponse response = paymentsApi.createPaymentUsingPOST(consentToken, paymentRequest);

String consentToken = consent.getConsentToken();
String paymentId =  paymentResponse.getData().getId();
ApiResponseOfPaymentResponse apiResponseOfPaymentResponse = paymentsApi.getPaymentStatusUsingGET(paymentId, consentToken);