-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from konduto/payment-types
Payment types
- Loading branch information
Showing
42 changed files
with
599 additions
and
257 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = 2.7.0 | ||
version = 2.8.0 |
This file contains 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/konduto/sdk/adapters/KondutoBoletoPaymentSerializer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.konduto.sdk.adapters; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.konduto.sdk.models.KondutoBoletoPayment; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
/** | ||
* Created by rsampaio on 9/8/16. | ||
* | ||
* Serializes a boleto payment. | ||
* Note the expiration date formatting. | ||
*/ | ||
public class KondutoBoletoPaymentSerializer extends KondutoPaymentSerializer { | ||
public JsonObject completeSerialization(JsonObject paymentAsJson, KondutoBoletoPayment boletoPayment) { | ||
Date expirationDate = boletoPayment.getExpirationDate(); | ||
if(expirationDate == null) { return paymentAsJson; } | ||
SimpleDateFormat boletoDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
paymentAsJson.addProperty("expiration_date", boletoDateFormat.format(expirationDate)); | ||
return paymentAsJson; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/konduto/sdk/adapters/KondutoCreditCardPaymentSerializer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.konduto.sdk.adapters; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.konduto.sdk.models.KondutoCreditCardPayment; | ||
|
||
/** | ||
* Created by rsampaio on 9/8/16. | ||
* | ||
* Serializes a credit card payment. | ||
*/ | ||
public class KondutoCreditCardPaymentSerializer extends KondutoPaymentSerializer { | ||
JsonElement completeSerialization(JsonObject paymentAsJson, KondutoCreditCardPayment creditCardPayment) { | ||
paymentAsJson.addProperty("status", creditCardPayment.getStatusAsString()); | ||
paymentAsJson.addProperty("bin", creditCardPayment.getBin()); | ||
paymentAsJson.addProperty("last4", creditCardPayment.getLast4()); | ||
paymentAsJson.addProperty("expiration_date", creditCardPayment.getExpirationDate()); | ||
return paymentAsJson; | ||
} | ||
} |
68 changes: 0 additions & 68 deletions
68
src/main/java/com/konduto/sdk/adapters/KondutoPaymentAdapter.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
src/main/java/com/konduto/sdk/adapters/KondutoPaymentCollectionDeserializer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.konduto.sdk.adapters; | ||
|
||
import com.google.gson.*; | ||
import com.konduto.sdk.models.*; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
/** | ||
* | ||
* Deserialization of KondutoPayment collections. | ||
* | ||
*/ | ||
public class KondutoPaymentCollectionDeserializer implements JsonDeserializer<Collection<KondutoPayment>> { | ||
|
||
/** | ||
* Method to deserialize a JSON object into a collection of KondutoPayment. | ||
* | ||
* @param json a serialized object | ||
* @param typeOfT the object type | ||
* @param context GSON serialization context | ||
* @return an ArrayList of payments | ||
* @throws JsonParseException | ||
*/ | ||
@Override | ||
public Collection<KondutoPayment> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | ||
throws JsonParseException { | ||
|
||
Collection<KondutoPayment> payments = new ArrayList<KondutoPayment>(); | ||
|
||
for(JsonElement je : json.getAsJsonArray()) { | ||
KondutoPaymentType type = | ||
KondutoPaymentType.valueOf(((JsonObject) je).get("type").getAsString().toUpperCase()); | ||
switch (type){ | ||
case BOLETO: | ||
KondutoBoletoPayment boletoPayment = new KondutoBoletoPayment(); | ||
String expirationDateAsStr = ((JsonObject) je).get("expiration_date").getAsString(); | ||
boletoPayment.setExpirationDate(expirationDateAsStr); | ||
payments.add(boletoPayment); | ||
break; | ||
case CREDIT: | ||
payments.add((KondutoCreditCardPayment) context.deserialize(je, KondutoCreditCardPayment.class)); | ||
break; | ||
case DEBIT: | ||
payments.add((KondutoDebitPayment) context.deserialize(je, KondutoDebitPayment.class)); | ||
break; | ||
case TRANSFER: | ||
payments.add((KondutoTransferPayment) context.deserialize(je, KondutoTransferPayment.class)); | ||
break; | ||
case VOUCHER: | ||
payments.add((KondutoVoucherPayment) context.deserialize(je, KondutoVoucherPayment.class)); | ||
break; | ||
} | ||
} | ||
|
||
return payments; | ||
} | ||
} | ||
|
41 changes: 41 additions & 0 deletions
41
src/main/java/com/konduto/sdk/adapters/KondutoPaymentSerializer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.konduto.sdk.adapters; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
import com.konduto.sdk.models.KondutoBoletoPayment; | ||
import com.konduto.sdk.models.KondutoCreditCardPayment; | ||
import com.konduto.sdk.models.KondutoPayment; | ||
import com.konduto.sdk.models.KondutoPaymentType; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Created by rsampaio on 9/8/16. | ||
* | ||
*/ | ||
public class KondutoPaymentSerializer implements JsonSerializer<KondutoPayment> { | ||
/** | ||
* KondutoPayment serializer | ||
* | ||
* @param payment the payment that needs to be converted to Json. | ||
* @param typeOfSrc the actual type (fully genericized version) of the source object. | ||
* @param context the serialization context | ||
* @return a JsonElement corresponding to the specified object. | ||
*/ | ||
@Override | ||
public JsonElement serialize(KondutoPayment payment, Type typeOfSrc, JsonSerializationContext context) { | ||
JsonObject paymentAsJson = new JsonObject(); | ||
paymentAsJson.addProperty("type", payment.getTypeAsString()); | ||
if(payment.getType().equals(KondutoPaymentType.CREDIT)) { | ||
KondutoCreditCardPaymentSerializer creditCardPaymentSerializer = new KondutoCreditCardPaymentSerializer(); | ||
return creditCardPaymentSerializer.completeSerialization(paymentAsJson, (KondutoCreditCardPayment) payment); | ||
} | ||
if(payment.getType().equals(KondutoPaymentType.BOLETO)) { | ||
KondutoBoletoPaymentSerializer boletoPaymentSerializer = new KondutoBoletoPaymentSerializer(); | ||
return boletoPaymentSerializer.completeSerialization(paymentAsJson, (KondutoBoletoPayment) payment); | ||
} | ||
return paymentAsJson; | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/java/com/konduto/sdk/adapters/KondutoShoppingCartAdapter.java
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.