Ir para o conteúdo

[DEPRECATED] Batch inquiry via API

This is a query via Content Provider that allows other applications to query information about the batches, making it possible to perform exclusive filters and obtain different batch data according to the return object (see Batch Closing).

Integration with Payment Application via Content Provider

It will only be allowed to list payments made by the application that is performing the query.

Declare this permission in your Application's AndroidManifest.xml to have access to the Content Provider.

<uses-permission android:name="br.com.phoebus.android.payments.provider.READ_PERMISSION"/>

content://br.com.phoebus.android.payments.provider/periodBatch content://br.com.phoebus.android.payments.provider/batchNumber content://br.com.phoebus.android.payments.provider/currentBatch

URI (Uniform Resource Identifier) for obtaining the batch information.

To request the query by period between dates, it is necessary to add this dependency.

implementation 'com.jakewharton.threetenabp:threetenabp:1.0.3'

Filters

Name Type Mantatory Description
batchFilter BatchFilter Yes Informs which type of batch filter is requested.
startDate Date No Filters batches whose date is greater than or equal to the past value, required when BatchFilter.PERIOD_BATCH.
finishDate Date No Filters batches whose date is less than or equal to the past value, required when BatchFilter.PERIOD_BATCH.
batchNumber Long No Filter batches by specific number, required field when BatchFilter.BATCH_NUMBER.

BatchFilter

Name Description
CURRENT_BATCH Current batch.
LAST_CLOSED_BATCH Last batch closed.
BATCH_NUMBER Specific lot number.
PERIOD_BATCH Batch by start datetime and end datetime.

Return

The response object is the List<SettlementCallbackV2> (see Batch closing).

Info

For ease of use, provider access classes are available:

  • BatchProviderRequest
  • BatchProviderApi
  • BatchContract
Example
import androidx.appcompat.app.AppCompatActivity;

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

import com.jakewharton.threetenabp.AndroidThreeTen;

import java.math.BigDecimal;

import java.text.SimpleDateFormat;
import java.util.Arrays;

import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import br.com.phoebus.android.payments.api.ApplicationInfo;
import br.com.phoebus.android.payments.api.Credentials;

import br.com.phoebus.android.payments.api.Payment;
import br.com.phoebus.android.payments.api.PaymentClient;
import br.com.phoebus.android.payments.api.PaymentStatus;
import br.com.phoebus.android.payments.api.provider.PaymentContract;
import br.com.phoebus.android.payments.api.provider.PaymentProviderApi;
import br.com.phoebus.android.payments.api.provider.PaymentProviderRequest;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    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();
        AndroidThreeTen.init(getApplication());

    }

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

    public void doExecute() {
        //setting the credentials
        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");

        //creating request object for  batch content provider
        BatchProviderRequest request = createRequest(applicationInfo);

        //selecting returned properties
        String[] columns = new String[]{
                BatchContract.column.batchData
        };

        try {
            //requesting the batch list
            request.setColumns(columns);
            List<SettleRequestResponseV2> batchList = BatchProviderApi.create(this).findAll(request);
            //********* Another way to query ******************************************
            // Cursor cursor = getApplicationContext().getContentResolver().query(request.getUriBuilder().build(), columns, null, null, null);
            // List<SettleRequestResponseV2> batchList = SettleRequestResponseV2.fromCursor(cursor);
            //***************************************************************************************

            Toast.makeText(this, batchList.size()+"", Toast.LENGTH_LONG).show();

        } catch (Exception e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            Log.e(TAG, e.getMessage(), e);
        }
    }

    private BatchProviderRequest createRequest(ApplicationInfo appInfo) {

        BatchProviderRequest batchRequest = new BatchProviderRequest();
        batchRequest.setApplicationInfo(appInfo);

        //filtering by period
        SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

        try {
            batchRequest.setBatchFilter(BatchFilter.PERIOD_BATCH);
            Date dateStart = isoFormat.parse("2020-04-06T00:00:00.000");
            Date dateFinish =isoFormat.parse("2020-04-06T23:59:59.000");
            batchRequest.setStartDate(dateStart);
            batchRequest.setFinishDate(dateFinish);
        } catch (Exception e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            Log.e(TAG, e.getMessage(), e);

        }

        return batchRequest;
    }


}