Skip to content

Commit

Permalink
Fix amount in transaction history
Browse files Browse the repository at this point in the history
  • Loading branch information
devnied committed May 22, 2014
1 parent fda8f30 commit e96d5a0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class EMVPaymentRecord extends AbstractByteBean<EMVPaymentRecord> impleme
public final static int DEFAULT_SIZE = 128;

/**
* Amount authorized
* Amount authorized (Amount need to be formated with currency)
*/
@Data(index = 1, size = 48)
@Data(index = 1, size = 48, format = DataFactory.BCD_FORMAT)
private Float amount;

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ public class EMVPaymentRecord extends AbstractByteBean<EMVPaymentRecord> impleme
private Date transactionDate;

/**
* Transaction type
* Transaction type (0:Payment, other:Withdrawal)
*/
@Data(index = 6, size = 16)
private Integer transactionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public final class DataFactory {
*/
public static final int HALF_BYTE_SIZE = 4;

/**
* BCD format
*/
public static final String BCD_FORMAT = "BCD_Format";

/**
* Method to get a date from the bytes table
*
Expand Down Expand Up @@ -93,7 +98,7 @@ public static Object getObject(final AnnotationData pAnnotation, final BitUtils
if (clazz.equals(Integer.class)) {
obj = getInteger(pAnnotation, pBit);
} else if (clazz.equals(Float.class)) {
obj = (float) getInteger(pAnnotation, pBit);
obj = getFloat(pAnnotation, pBit);
} else if (clazz.equals(String.class)) {
obj = getString(pAnnotation, pBit);
} else if (clazz.equals(Date.class)) {
Expand All @@ -106,6 +111,27 @@ public static Object getObject(final AnnotationData pAnnotation, final BitUtils
return obj;
}

/**
* Method use to get float
*
* @param pAnnotation
* annotation
* @param pBit
* bit utils
* @return
*/
private static Float getFloat(final AnnotationData pAnnotation, final BitUtils pBit) {
Float ret = null;

if (BCD_FORMAT.equals(pAnnotation.getFormat())) {
ret = Float.parseFloat(pBit.getNextHexaString(pAnnotation.getSize()));
} else {
ret = (float) getInteger(pAnnotation, pBit);
}

return ret;
}

/**
* This method is used to get an enum with his key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testPSE() throws CommunicationException {
Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("02/2016");
Assertions.assertThat(card.getListPayment()).isNotNull();
EMVPaymentRecord record = card.getListPayment().get(0);
Assertions.assertThat(record.getAmount()).isEqualTo(17920);
Assertions.assertThat(record.getAmount()).isEqualTo(4600);
Assertions.assertThat(record.getCyptogramData()).isEqualTo("40");
Assertions.assertThat(record.getTransactionType()).isEqualTo(144);
Assertions.assertThat(record.getCurrency()).isEqualTo(CurrencyEnum.EUR);
Expand Down
4 changes: 2 additions & 2 deletions sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.devnied.emvnfccard"
android:versionCode="8"
android:versionName="1.1.2" >
android:versionCode="9"
android:versionName="1.2.0" >

<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="19"/>
<uses-permission android:name="android.permission.NFC"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void onBackPressed() {

List<EMVPaymentRecord> list = new ArrayList<EMVPaymentRecord>();
EMVPaymentRecord payment = new EMVPaymentRecord();
payment.setAmount(new Float(234.698));
payment.setAmount(new Float(234));
payment.setCurrency(CurrencyEnum.EUR);
payment.setTransactionDate(new Date());
list.add(payment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public View getView(final int position, final View pConvertView, final ViewGroup
// Set amount
amount.setText(event.getCurrency().format(event.getAmount().longValue()));
} else {
amount.setText(String.valueOf(event.getAmount().longValue()));
amount.setText(String.valueOf(event.getAmount().longValue() / 100));
}
} else {
amount.setText(event.getCurrency().format(event.getAmount().longValue()));
amount.setText(event.getCurrency().format(event.getAmount().longValue() / 100));
}

// Apply faceType
Expand Down

0 comments on commit e96d5a0

Please sign in to comment.