Ir para o conteúdo

Integration with V2 Payments


One of the ways to integrate with the Phoebus payments app is via IPC. A library is provided for this, payments-api-x.x.x.x.aar , containing all the code needed to be used for such calls.

Using this API, it is possible to carry out the entire payment flow, that is, confirmation (or undoing) and reversal. Payment can be made with a pre-defined amount or with an open amount, to be entered by the terminal operator. In addition, you can inform a list of payment types (debit, cash credit, credit in installments, etc.) allowed.

Although this integration takes place through an API, the Phoebus payment application can display information on the terminal interface, such as messages (e.g., "Insert or swipe the card"), or even request information from the operator (e.g., CVV ). Therefore, while performing any operation, the application that requested the operation must not interact with the device's interface until the operation is completed.

The following is a detailed specification of available operations.

For integration with the payments API, the PaymentClient interface present in the library is provided.

Warning

The PaymentClient.Bind(_callback) method must be called before calling any Payment Integration method. The bind is asynchronous, i.e. the next line after the bind() will be executed before receiving your response, so make sure that before calling the integration methods, the bind is connected .

Payment flow

assets/images/FluxoDePagamento

Steps Success Error
1. Payment Request The payment has been made and its status is Pending Payment has not been made. The response contains error information.
2. Response Payment Request The response contains information about the payment made. The response contains request error information.
3. Request for confirmation Confirmation performed, its status is Confirmed, cannot be undone. Confirmation not performed. The response contains error information.
4. Confirmation response The response contains information from the confirmation performed. Voucher Print The response contains request error information. At this point, the undo can be sent.
5. Undo request Undo performed, its status is Undo. It cannot be confirmed. The response contains request error information. The status remains Pending.
6. Undo response The response contains information from the undo performed. The response contains request error information.

The payment is only finalized when there is a confirmation or a cancellation (undo). In case of confirmation, the receipt will be available for printing or sending by SMS/email, depending on the terminal's functionalities.

As of version 3.1.4.3

When a transaction is made and the app requests its confirmation (confirmPayment()) or undoing (cancelPayment()), the request response will be sent to the app as soon as the transaction is resolved locally by the terminal, eliminating the need for the app wait for the resolution with the authorizer to continue the flow.

After that, the terminal will try to resolve the transaction with the authorizer. This can occur immediately when finalizing the transaction, or later, in the resolution of pending issues.

Methods

Signature Description
void startPaymentV2(PaymentRequestV2 paymentRequest, PaymentCallback paymentCallback) Performs the payment authorization process.
void confirmPayment(String paymentId, PaymentCallback paymentCallback) Confirms a previously performed payment authorization.
void cancelPayment(String paymentId, PaymentCallback paymentCallback) Undoes a previously performed payment authorization.

startPaymentV2()

This method must be called when you want to make a payment authorization request. During its execution, payment data will be validated, additional information will be requested from the operator (e.g. password and CVV), and authorization will be made with the acquirer.

Parameters

Name Type Mandatory Description
request PaymentRequestV2 Yes Data transfer object that will contain the payment request information. Note that not all parameters are required.
callback PaymentCallback Yes Interface that will be executed for notifications of success or error of the payment process.

Parameter Details

request (PaymentRequestV2)

Name Type Mandatory Description
value BigDecimal No Requested payment amount. If it is not filled in (null), the interface will ask the operator for the value. The value must be formatted with two decimal places.
additionalValueType AdditionalValueType No Additional value type (Cashback, TIP, etc.). If it is not filled in (null), the "additionalValue" field must be ignored. 'AdditionalValueType' must admit, for FastTrack, only the CASHBACK value. After reading the card, if the AdditionalValueType informed is not compatible with the Card's banner product, the terminal displays an error on the screen and ends the transaction. To prevent this error from occurring, it is recommended to use this field only together with a "productShortName", which must be filled in as a product that supports the use of the additional value type in question.
additionalValue BigDecimal No Value added to the transaction value. If "additionalValueType" is reported and "additionalValue" has not been filled in (null) or is equal to 0 (zero), the interface will ask the operator for the additional value. If "additionalValueType" is populated and "additionalValue" has a value higher than 0 (zero), the interface will not ask the operator for the additional value.
paymentTypes List<PaymentType> No Payment types (Debit, Credit, Voucher, etc.) allowed for this payment. If it is empty, that is, null, it means that all types are allowed. If it contains only one, this type will be used (if possible) and the operator will not be asked anything.
installments Integer No Number of installments. Used only for payment types that support installments and in this case it is mandatory. Value must be between 2 and 99. This parameter is considered in payments with static QR code, i.e. when operationMethodAllowed = 1.
accountTypeId String No Account Type. If not filled in (null), the interface may ask the operator for the type of account, depending on the configuration of the main product associated with the card used in the transaction. After reading the card, if the accountTypeId entered does not exist in the configuration of the Card's flag product, the terminal displays an error on the screen and ends the transaction. To prevent this error from occurring, it is recommended to use this field only together with a "productShortName", which must contain a product that supports the use of the account type.
planId String No Payment plan identification. It can be one or two characters, depending on the selected acquirer rule. If not filled in (null), the interface can request the plan from the operator, according to the configuration of the brand product associated with the card used in the transaction. After reading the card, if the reported planId is not compatible with the number of installments (captured in the terminal or informed in the "Parcelas" parameter) and with the configuration of the card's flag product (observing the planCondition, planType and planList settings) , the terminal shows an error on the screen and ends the transaction. In order to prevent this error from occurring, it is recommended to use this field only together with a "productShortName", which must contain a product that supports the referred plan.
appTransactionId String Yes Integrated transaction identifier for the software. The Identifier referred to is the one used in the application that originated the payment request and must be unique, without repetitions.
ApplicationInfo.softwareVersion String Yes Version of the application that is requesting payment.
showReceiptView (DEPRECATED) Boolean No The Solution will use the value of the printMerchantReceipt and printCustomerReceipt parameters to execute the printing after the confirmation is executed.
printMerchantReceipt Boolean No Indicates whether or not the merchant's receipt should be printed after confirmation of the transaction. The default value is true, ie the voucher is printed.
printCustomerReceipt Boolean No Indicates whether or not the customer receipt should be printed after confirmation of the transaction. The default value is true, ie the voucher is printed.
tokenizeCard Boolean No Indicates whether or not to tokenize the card after the payment is approved or not. The default value is false, that is, no tokenization will be performed.
tokenizeEmail String If tokenizeCard is true then yes, otherwise no. Cardholder email. If “tokenizeCard” is false, this parameter is ignored.
tokenizeNationalDocument String No CPF or CNPJ of the cardholder. If “tokenizeCard” is false, this parameter is ignored. If it is true, but this parameter is not informed, then the call to the e-commerce token creation API will not use it either.
productShortName String No Brief identification of the card's flag product. After reading the card and identifying the branded product, if it does not match the referred productShortName, the terminal displays an error on the screen and ends the transaction. This parameter is considered in payments with a static QR code, that is, when operationMethodAllowed = 1, the terminal displays an error if the field is informed and this value corresponds to a product whose acquirerParams.allowQRCode field is false; Or the acquirerParams.qrPaymentMethodId field is not defined; Or if the product exists but is not enabled in the terminal.
note String No Additional value that is entered as Note. (can be invoice number)
dni String No Document number.
operationMethodAllowed Integer Yes Indicates the payment, cancellation and return operation method. Allow the following values: 0 - Only with physical card (read or typed); 1 - Only with QRCode.
allowBenefit Boolean No Indicates whether the QRCode should be generated with the product options associated with the benefits. The default value is 'true', ie the benefits will be added.
previewMerchantReceipt Boolean No Indicates whether the merchant voucher preview screen should be displayed after confirming the transaction. The default value is true, which means the voucher will be displayed.
previewCustomerReceipt Boolean No Indicates whether the customer voucher preview screen should be displayed after confirming the transaction. The default value is true, which means the voucher will be displayed.
merchantGroupCode String If allowMultimerchant= true, groupCode is required Merchant group code.

callback (PaymentCallback)

Name Type Mantatory Description
onSuccess Method for notification on success
Payment.value BigDecimal Yes Payment amount. This is the value that was approved by the acquirer. It must always be validated in the response, even if it has been passed as a parameter, as there are acquirers that, for some situations, approve values different from those requested.
Payment.additionalValueType AdditionalValueType No Present only when there is an additional value in the context of the executed transaction.
Payment.additionalValue BigDecimal No Present only when there is an additional value in the context of the executed transaction.
Payment.paymentType PaymentType Yes Type of payment (Debit, Credit, Voucher, etc.).
Payment.installments Integer No Number of payment installments.
Payment.accountTypeId String No Only present when an account type exists in the context of the executed transaction.
Payment.planId String No Present only when a plan exists in the context of the executed transaction.
Payment.productShortName String Yes Corresponds to the productShortName corresponding to the main product in the transaction context.
Payment.ticketNumber String No ticketNumber generated by the terminal for the transaction.
Payment.batchNumber String Yes Lot number.
Payment.nsuTerminal String Yes NSU generated by the terminal for the transaction.
Payment.acquirer String Yes Purchaser who authorized the payment.
Payment.paymentId String Yes Transaction identifier for the payment application. This is the information to use for commit and undo.
Payment.Card.brand String Yes Card banner.
Payment.Card.bin String Yes card BIN.
Payment.Card.panLast4Digits String Yes Last 4 digits of the card's PAN.
Payment.captureType CaptureType Yes Card capture method.
Payment.paymentStatus PaymentStatus Yes Payment status. In the case of successfully returned requests, this information will always be PENDING, requiring confirmation or undoing for its definitive conclusion.
Payment.paymentDate Date Yes Payment date/time for the payment application.
Payment.acquirerId String Yes Transaction identifier for the acquirer. This is the identifier that appears in the file that the acquirer provides (EDI). In this way, it is possible to reconcile the payment with the integrated transaction.
Payment.acquirerResponseCode String Yes Acquirer response code.
Payment.acquirerResponseDate String Yes Date/time returned by the acquirer.
Payment.acquirerAdditionalMessage String No Additional message sent by acquirer in transaction response
Payment.acquirerAuthorizationNumber String Yes Authorization number provided by the acquirer (it appears on the Cardholder's customer receipt).
Payment.Receipt.clientVia String No Voucher content - customer's copy.
Payment.Receipt.merchantVia String No Content of the voucher - copy of the establishment.
Payment.cardToken String No Card token used in the transaction.
Payment.cardholderName String No Cardholder name.
Payment.terminalId String Yes Terminal ID.
Payment.note String Yes Additional value that is entered as note (may be the invoice number). This field will only appear in the response if it has been filled in in the payment request via the api; In case it is captured by the voucher, it is not possible to return, because as the voucher is displayed after confirmation, by that time the payment response has already been sent to the app.
Payment.dni String Yes Document number. This field will only appear in the response if it was filled in in the payment request by the api; If it is captured by the voucher, it is not possible to return it, as the voucher is displayed after confirmation, at which point the payment response has already been sent to the app.
Payment.qrId String No QrCode identifier generated by the capture terminal.
Payment.originalValue BigDecimal No Original sale value. Present in payments with QR Code, whose benefit was applied to the sale value.
Payment.acquirerNsu String No NSU Acquirer for consultation and identification of transactions.
Payment.Card.aid String Yes AID to identify the application to process the transaction. It's returned on EMV transactions.
Payment.Card.cardAppName String Yes APN, or card application name. It's returned on EMV transactions.
Payment.correlationId String Yes Common transaction identifier between terminal, PhAST and PayStore. This identifier in UUID format is unique for each transaction
onError Method for notification in case of error.
ErrorData.paymentsResponseCode String Yes Response code for the error that occurred. See Response Codes
ErrorData.acquirerResponseCode String No Response code for the occurred error returned by the acquirer. Note that this error will only be returned if the transaction is not authorized by the acquirer.
ErrorData.responseMessage String Yes Descriptive message of the reason for the non-authorization. If the transaction was denied by the acquirer, it will contain the message returned by the acquirer.
ErrorData.acquirerAdditionalMessage String No Additional message sent by the acquirer in the transaction response.
### confirmPayment()

This method must be called to confirm a transaction that the terminal was able to fully process the authorization leg sent by the Authorizer.

This method must not be called for a transaction that has already been confirmed, that is, in which the confirmPayment() method has already been executed.

This method should not be called for a transaction that has already been undone, that is, in which the cancelPayment() method has been executed previously.

This method must not be called for a transaction that was denied by the Authorizer, that is, the transaction must have been authorized by the Authorizer.

After executing this confirmation, the transaction can only be canceled through a reversal operation (the reversal is the operation performed by the terminal's CANCEL menu).

If the consumer App of this API has successfully completed its business process, but has not called the confirmPayment() method, the transaction will remain with the following status: PayStore Status = "Pending". Resolution on Acquirer = "Pending".

As a result, we may experience transactional inconsistency, as at the turn of the day some acquiring networks automatically confirm transactions that have not received the confirmation leg. Other acquirer networks only work with two legs, without the need for a confirmation leg. In this case, if there is any problem completing the transaction on the terminal side, it is imperative that the capture solution executes the cancelPayment() method, in order to undo the transaction on the acquirer and avoid charging the Cardholder customer. Card.

Parameters

Name Type Mandatory Description
paymentId String Yes Identifier of the transaction to be committed. The Identifier referred to is the one used in the payment application.
callback PaymentCallback Yes Interface that will be executed for success or error notifications.

Parameter details

callback

Name Type Mandatory Description
onSuccess Method for notification on success
onError Method for notification in case of error.
ErrorData.paymentsResponseCode String Yes Response code for the error that occurred. See Response Codes
ErrorData.acquirerResponseCode String No Response code for the occurred error returned by the acquirer. Note that this error will only be returned if the transaction is not authorized by the acquirer.
ErrorData.responseMessage String Yes Descriptive message of the reason for the non-authorization. If the transaction was denied by the acquirer, it will contain the message returned by the acquirer.

cancelPayment()

This method must always be called to undo a transaction that the terminal was unable to fully process the authorization leg sent by the Authorizer.

This method must not be called for a transaction that has already been confirmed, that is, in which the confirmPayment() method has already been executed.

This method must not be called to undo a transaction that has already been undone, that is, in which the cancelPayment() method has already been executed

This method should not be called for a transaction that was denied by the Authorizer.

This method is not a chargeback. The chargeback is the operation performed by the CANCEL menu of the terminal. The reversal is performed on transactions that have completed successfully, that is, have been committed.

After executing the undo, cancelPayment(), the transaction can no longer be confirmed by the terminal application, that is, the confirmPayment() method can no longer be executed.

If the consumer App of this API has not successfully completed its business process, it is essential to call the cancelPayment() method. The consequence of not canceling a transaction that has not had its business process completed is similar to the consequence of not confirming. However, in this case, with an aggravating factor, as the customer will probably not take the product/service associated with the financial transaction, or a new attempt to sell may be made, resulting in a duplicate charge for the Cardholder customer.

Parameters

Name Type Mandatory Description
paymentId String Yes Identifier of the transaction to be rolled back. The Identifier referred to is the one used in the payment application.
callback PaymentCallback Yes Interface that will be executed for success or error notifications.

Parameter details

callback

Name Type Mandatory Description
onSuccess Method for notification on success.
onError Method for notification in case of error.
ErrorData.paymentsResponseCode String Yes Response code for the error that occurred. See Response Codes
ErrorData.acquirerResponseCode String No Response code for the occurred error returned by the acquirer. Note that this error will only be returned if the transaction is not authorized by the acquirer.
ErrorData.responseMessage String Yes Descriptive message of the reason for the non-authorization. If the transaction was denied by the acquirer, it will contain the message returned by the acquirer.

Additional field api_pending

In addition to the payment resolution methods (confirmPayment and cancelPayment), there is the possibility of configuring an additional field in the Paystore Portal to perform this resolution automatically, at a certain time. For this, an additional field must be created in the Paystore Portal with the type JSON and the key api_pending.

Field value

Name Type Mandatory Description
confirmationTime String Yes Interval, in minutes, for resolving pending issues.
transactionConfirmation String Yes Action to be taken. Allows the values CONFIRM (Confirm the transaction) or UNDO (Undo the transaction).
{
    "confirmationTime": "10",
    "transactionConfirmation": "CONFIRM"
}
Example of the payment flow
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.math.BigDecimal;

import br.com.phoebus.android.payments.api.ApplicationInfo;
import br.com.phoebus.android.payments.api.Credentials;
import br.com.phoebus.android.payments.api.ErrorData;
import br.com.phoebus.android.payments.api.PaymentClient;
import br.com.phoebus.android.payments.api.PaymentRequestV2;
import br.com.phoebus.android.payments.api.PaymentV2;
import br.com.phoebus.android.payments.api.exception.ClientException;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, PaymentClient.PaymentCallback<PaymentV2> {

    Button bt_start;
    private PaymentClient paymentClient;
    public static final String TEST_APPLICATION_ID = "0";
    public static final String TEST_SECRET_TOKEN = "000000000000000000000000";
    public static final String TAG = "TAG_DEMO";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bt_start = (Button) this.findViewById(R.id.button);
        bt_start.setOnClickListener(this);
        paymentClient = new PaymentClient();

    }


    @Override
    public void onClick(View view) {
        doExecute();
    }

    @Override
    protected void onResume() {
        super.onResume();
        paymentClient.bind(this);
    }

    @Override
    protected void onDestroy() {
        try {
            paymentClient.unbind(this);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }
        super.onDestroy();
    }

    public void doExecute(){
        PaymentRequestV2 request = new PaymentRequestV2();
        BigDecimal value = BigDecimal.valueOf(5000).movePointLeft(2);
        request.setValue(value);
        request.setAppTransactionId("2d2f7dc7-88e5-467e-86a3-f173fb3c7792");

        Credentials credentials = new Credentials();
        credentials.setApplicationId(TEST_APPLICATION_ID);
        credentials.setSecretToken(TEST_SECRET_TOKEN);

        ApplicationInfo applicationInfo = new ApplicationInfo();
        applicationInfo.setCredentials(credentials);
        applicationInfo.setSoftwareVersion("1.0");

        request.setAppInfo(applicationInfo);

        try {
            paymentClient.startPaymentV2(request, this);
        } catch (ClientException e) {
            Log.e(TAG, "Error starting payment", e);
        }
    }


    @Override
    public void onSuccess(PaymentV2 paymentV2) {
        Log.i(TAG, paymentV2.toString());

        doConfirmPayment(paymentV2);
        /*
            If, in your business rule, you need to undo the transaction for some reason,
           call the method doCancelPayment(paymentV2)
        **/
    }

    @Override
    public void onError(ErrorData errorData) {
        Log.e(TAG, errorData.getResponseMessage());
        Toast.makeText(this, errorData.getResponseMessage(), Toast.LENGTH_LONG).show();
    }

    private void doConfirmPayment(PaymentV2 paymentV2) {
        try {
            paymentClient.confirmPayment(paymentV2.getPaymentId(),
                    new PaymentClient.PaymentCallback<PaymentV2>() {

                        @Override
                        public void onError(ErrorData errorData) {
                            Log.e(TAG, errorData.getResponseMessage());
                            Toast.makeText(MainActivity.this, errorData.getResponseMessage(), Toast.LENGTH_LONG).show();

                        }

                        @Override
                        public void onSuccess(Object o) {
                            Log.i(TAG, "Payment successfully completed confirmation!");
                        }


                    });
        } catch (ClientException e) {
            Log.e(TAG, "Error confirmPayment", e);
        }

    }

    private void doCancelPayment(PaymentV2 paymentV2) {
        try {
            paymentClient.cancelPayment(paymentV2.getPaymentId(),
                    new PaymentClient.PaymentCallback<PaymentV2>() {

                        @Override
                        public void onError(ErrorData errorData) {
                            Log.e(TAG, errorData.getResponseMessage());
                            Toast.makeText(MainActivity.this, errorData.getResponseMessage(), Toast.LENGTH_LONG).show();

                        }

                        @Override
                        public void onSuccess(Object o) {
                            Log.i(TAG, "Undo Completed!");
                        }


                    });
        } catch (ClientException e) {
            Log.e(TAG, "Error cancelPayment", e);
        }

    }


}