Created
November 28, 2017 16:34
-
-
Save kaueDM/379dcfa77d5d6128330cd335e6ca6ab6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ruptiva_payment; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.util.Log; | |
import com.google.gson.Gson; | |
import com.zoop.api.ZoopAPI; | |
import com.zoop.api.terminal.ApplicationDisplayListener; | |
import com.zoop.api.terminal.DeviceSelectionListener; | |
import com.zoop.api.terminal.ExtraCardInformationListener; | |
import com.zoop.api.terminal.TerminalListManager; | |
import com.zoop.api.terminal.TerminalMessageType; | |
import com.zoop.api.terminal.TerminalPayment; | |
import com.zoop.api.terminal.TerminalPaymentListener; | |
import com.zoop.api.terminal.ZoopTerminalPayment; | |
import org.json.JSONObject; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.Vector; | |
public class PinpadModule extends Activity implements TerminalPaymentListener, ApplicationDisplayListener, ExtraCardInformationListener { | |
JSONObject actualTransaction = null; | |
TerminalListManager terminalListManager; | |
ZoopTerminalPayment zoopTerminalPayment; | |
ArrayList<HashMap<String, Object>> devicesArrayList; | |
boolean discoveryTerminals = false; | |
/** | |
* Dados do marketplace | |
*/ | |
String MarketplaceId = "00000"; | |
String PublishableKey = "00000"; | |
/** | |
* Variáveis para transacionar o estado do app entre o Java e o Javascript. | |
*/ | |
boolean isPaymentSuccessful = false; | |
boolean isPaymentFailed = false; | |
boolean isPaymentAbortedByUser = false; | |
boolean isSignatureRequested = false; | |
boolean isSignatureCaptured = false; | |
boolean isCVCRequested = false; | |
boolean isLast4Requested = false; | |
boolean isExpirationDateRequested = false; | |
String transactionMessage = null; | |
String transactionMessageType = null; | |
String transactionMessageDescription = null; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
try { | |
if (!discoveryTerminals) { | |
terminalListManager = new TerminalListManager(new DeviceSelectionListener() { | |
@Override | |
public void showDeviceListForUserSelection(Vector<JSONObject> vector) { | |
Log.d("test___", "showDeviceListForUserSelection"); | |
try { | |
Log.d("test___", "showDeviceListForUserSelection()"); | |
Log.d("test___", "Devices Vector: " + vector); | |
devicesArrayList = new ArrayList<>(); | |
for (JSONObject devicesObject : vector) { | |
HashMap<String, Object> hashMapDevices = new HashMap<>(); | |
hashMapDevices.put("name", devicesObject.getString("name")); | |
hashMapDevices.put("address", devicesObject.getString("address")); | |
hashMapDevices.put("dateTimeDetected", devicesObject.getString("dateTimeDetected")); | |
hashMapDevices.put("selected", devicesObject.getBoolean("selected")); | |
devicesArrayList.add(hashMapDevices); | |
} | |
} catch (Exception e) { | |
Log.e("test___", "showDeviceListForUserSelection error"); | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void updateDeviceListForUserSelecion(JSONObject devicesObject) { | |
try { | |
Log.d("test___", "updateDeviceListForUserSelecion"); | |
HashMap<String, Object> hashMapDevices = new HashMap<>(); | |
hashMapDevices.put("name", devicesObject.getString("name")); | |
hashMapDevices.put("address", devicesObject.getString("address")); | |
hashMapDevices.put("dateTimeDetected", devicesObject.getString("dateTimeDetected")); | |
hashMapDevices.put("selected", devicesObject.getBoolean("selected")); | |
devicesArrayList.add(hashMapDevices); | |
}catch (Exception e) { | |
Log.e("test___", "updateDeviceListForUserSelecion error"); | |
e.printStackTrace(); | |
} | |
} | |
}, getApplicationContext()); | |
terminalListManager.startTerminalsDiscovery(); | |
discoveryTerminals = true; | |
} else { | |
terminalListManager.finishTerminalDiscovery(); | |
discoveryTerminals = false; | |
} | |
} catch (Exception e) { | |
Log.e("test___", "Erro ao buscar devices: " + e.getMessage()); | |
e.printStackTrace(); | |
} | |
} | |
/** | |
* Métodos obrigatórios | |
*/ | |
//Payment status | |
@Override | |
public void paymentSuccessful(final JSONObject jsonObject) { // ~> Pra que serve esse json ? | |
isPaymentSuccessful = true; | |
} | |
@Override | |
public void paymentFailed(JSONObject jsonObject) { // ~> Pra que serve esse json ? | |
isPaymentFailed = true; | |
} | |
@Override | |
public void paymentAborted() { | |
isPaymentAbortedByUser = true; | |
} | |
//Signature | |
//Deprecated method. Will be replaced in future updates | |
@Override | |
public void currentChargeCanBeAbortedByUser(final boolean canBeAborted) { | |
} | |
@Override | |
public void cardholderSignatureRequested() { //ver com o Rodrigo que dado isso usa: Imagem, base64, etc | |
isSignatureRequested = true; | |
} | |
@Override | |
public void signatureResult(int result) { | |
if (TerminalPayment.RESULT_OK_SIGNATURE_ADDED_OK == result) { | |
//Valida que a assinatura foi capturada | |
} | |
} | |
//Transaction messages | |
@Override | |
public void showMessage(final String message, TerminalMessageType type) { | |
transactionMessage = message; | |
transactionMessageType = type.toString(); | |
} | |
@Override | |
public void showMessage(final String message, TerminalMessageType type, final String messageDescription) { | |
transactionMessage = message; | |
transactionMessageType = type.toString(); | |
transactionMessageDescription = messageDescription; | |
} | |
//CVV | |
@Override | |
public void cardCVCRequested() { | |
isCVCRequested = true; | |
} | |
//Last 4 digits | |
@Override | |
public void cardLast4DigitsRequested() { | |
isLast4Requested = true; | |
} | |
//Expiration date | |
@Override | |
public void cardExpirationDateRequested() { | |
isExpirationDateRequested = true; | |
} | |
/** | |
*Métodos para chamar na bridge do React Native | |
*/ | |
// public void pay(String SellerID) { | |
// try { | |
// ZoopAPI.getInstance().initialize(getApplication(), MarketplaceId, SellerID, PublishableKey); | |
// Log.d("test___", "instance initialized"); | |
// } catch (Exception e) { | |
// Log.e("test___", "pay() error"); | |
// e.printStackTrace(); | |
// } | |
// } | |
public ArrayList<HashMap<String, Object>> getDevices() { | |
return devicesArrayList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment