Query the Last Transaction Approved via API¶
This is a query via Content Provider that allows other applications to query information about the last approved transaction.
The last confirmed transaction can be a payment, a reversal, or an unreferenced devolution. It has no filters. Returns the complete structure of payments + reversals (approved or denied). It may return empty if there are no approved transactions in the terminal.
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/payments/lastTransactions
URI (Uniform Resource Identifier) for obtaining the Last Transaction Approved information.
To request the query by period between dates, it is necessary to add this dependency.
implementation 'com.jakewharton.threetenabp:threetenabp:1.0.3'
Input parameters¶
| Name | Type | Mandatory | Description |
|---|---|---|---|
applicationId |
Credentials |
Yes | Identification of the application that is performing the query. |
secretToken |
Credentials |
Yes | Access token of the application performing the query. |
softwareVersion |
String |
Yes | Version of the application that is requesting the query. |
Returned structure¶
- When the Last Approved Transaction is a payment, the payment object and the list of all reversals associated with it are returned;
- When the Last Approved Transaction is a reversal, the reversal object, the payment associated with this reversal, and, if any, other reversals associated with the same payment are returned;
- When the Last Approved Transaction is an Unreferenced devolution, the Refund object is returned.
The structure returned follows as shown in the examples below:
Example when the last transaction is a payment¶
All object return fields are available in returned structure.
The last confirmed payment will be identified through the field "lastTrx": true.
{
"payment":{
"id":"",
"value":50,
"captureType":"MANUAL",
"status":"CONFIRMED",
"date":"01/06/2023 10:45",
"nsuTerminal":123,
"lastTrx":true
...
},
"reversals":[
{
...
}
]
}
Example when the last transaction is a reversal¶
All object return fields are available in returned structure.
The last confirmed reversal will be identified through the field "lastTrx": true.
{
"payment":{
...
},
"reversals":[
{
"paymentId":"",
"value":50,
"captureType":"MANUAL",
"status":"CONFIRMED",
"date":"01/06/2023 10:45",
"lastTrx":true
...
}
]
}
Example when the last transaction is an Unreferenced devolution¶
All object return fields are available in returned structure.
The last confirmed Unreferenced Return will be identified through the field "lastTrx": true.
{
"refund":{
"id":"",
"value":50,
"captureType":"MANUAL",
"status":"CONFIRMED",
"date":"01/06/2023 10:45",
"nsuTerminal":123,
"lastTrx":true,
...
}
}
Info
Para facilitar o uso, são disponibilizadas classes de acesso ao provider:
PaymentProviderApi
Exemplo¶
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");
try {
//request the last transaction
ProviderResponse lastTransaction = PaymentProviderApi.create(this).findLastTransaction(applicationInfo);
Toast.makeText(this, lastTransaction.size()+"", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
Log.e(TAG, e.getMessage(), e);
}
}
}