Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from Mangopay/develop
Browse files Browse the repository at this point in the history
Issue #19
  • Loading branch information
hobailey authored Jul 25, 2016
2 parents e5c5fc8 + c9f73b7 commit 1c8f94e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ private void getCardRegistration() {
.preregistrationData(preregistrationData)
.cardPreregistrationId(cardPreregistrationId)
.cardNumber("3569990000000157")
.cardExpirationDate("0920")
//.cardExpirationDate("0920")
.cardExpirationYear(2017)
.cardExpirationMonth(2)
.cardCvx("123")
.logLevel(LogLevel.FULL)
.callback(new Callback() {
@Override public void success(CardRegistration cardRegistration) {
Log.d(MainActivity.class.getSimpleName(), cardRegistration.toString());
}
@Override public void failure(MangoError error) {
@Override public void failure(MangoException error) {
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
}).start();
Expand Down
17 changes: 13 additions & 4 deletions mangopay/src/main/java/com/mangopay/android/sdk/MangoPay.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ public void registerCard() {
registerCard(null, null);
}

public void registerCard(Callback callback) {
registerCard(null, callback);
}

public void registerCard(MangoCard card, Callback callback) {
PrintLog.debug("MangoPay SDK register card started");
if (mCallback == null)
PrintLog.debug("MangoPay SDK register card started ");
if (callback != null) {
this.mCallback = callback;
if (mCard == null)
mCard = card;
}
if (card != null && !card.equals(mCard)) {
this.mCard = card;
}

GetTokenInteractor.Callback serviceCallback = new GetTokenInteractor.Callback() {
@Override public void onGetTokenSuccess(String response) {
Expand All @@ -72,6 +78,9 @@ public void registerCard(MangoCard card, Callback callback) {
mSettings.validate();
mCard.validate();

PrintLog.debug(mSettings.toString());
PrintLog.debug(mCard.toString());

getTokenInteractor.execute(serviceCallback, mSettings.getCardRegistrationURL(),
mSettings.getPreregistrationData(), mSettings.getAccessKey(),
mCard.getCardNumber(), mCard.getExpirationDate(), mCard.getCvx());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;

import com.mangopay.android.sdk.model.LogLevel;
import com.mangopay.android.sdk.model.MangoCard;
import com.mangopay.android.sdk.util.PrintLog;

import java.util.Calendar;
Expand Down Expand Up @@ -207,9 +206,18 @@ public MangoPayBuilder logLevel(LogLevel logLevel) {
return this;
}

/**
* Starts the card registration process
*/
public void start() {
MangoCard mCard = new MangoCard(cardNumber, expirationDate, cvx);
build().registerCard(mCard, callback);
build().registerCard(callback);
resetBuilderCardInfo();
}

private void resetBuilderCardInfo() {
this.cardNumber= null;
this.expirationDate= null;
this.cvx= null;
}

public MangoPay build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,35 @@ private void validateCardCvx() {
private boolean isFieldValid(String field, String regex) {
return field != null && field.matches(regex);
}

@Override
public String toString() {
return "MangoCard{" +
"cardNumber='" + cardNumber + '\'' +
", expirationDate='" + expirationDate + '\'' +
", cvx='" + cvx + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

MangoCard mangoCard = (MangoCard) o;

if (cardNumber != null ? !cardNumber.equals(mangoCard.cardNumber) : mangoCard.cardNumber != null)
return false;
if (expirationDate != null ? !expirationDate.equals(mangoCard.expirationDate) : mangoCard.expirationDate != null)
return false;
return cvx != null ? cvx.equals(mangoCard.cvx) : mangoCard.cvx == null;
}

@Override
public int hashCode() {
int result = cardNumber != null ? cardNumber.hashCode() : 0;
result = 31 * result + (expirationDate != null ? expirationDate.hashCode() : 0);
result = 31 * result + (cvx != null ? cvx.hashCode() : 0);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@ public void validate() throws MangoException {
throw new MangoException(e);
}
}

@Override
public String toString() {
return "MangoSettings{" +
"baseURL='" + baseURL + '\'' +
", clientId='" + clientId + '\'' +
", cardPreregistrationId='" + cardPreregistrationId + '\'' +
", cardRegistrationURL='" + cardRegistrationURL + '\'' +
", preregistrationData='" + preregistrationData + '\'' +
", accessKey='" + accessKey + '\'' +
'}';
}
}

0 comments on commit 1c8f94e

Please sign in to comment.