Skip to content

Commit

Permalink
Merge pull request #1 from wavedigital/master
Browse files Browse the repository at this point in the history
CardIO integration
  • Loading branch information
Andrew McIntosh authored Dec 29, 2016
2 parents 2703701 + 65412ab commit 97ae36b
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(':promisepay')
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
#Thu May 12 17:32:56 EST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
1 change: 1 addition & 0 deletions promisepay/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'io.card:android-sdk:5.3.4'
}


Expand Down
41 changes: 40 additions & 1 deletion promisepay/src/main/java/com/github/promisepay/PPCard.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.github.promisepay;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.HashMap;

/**
* Created by Kevin Hakans on 1/14/16.
*/
public class PPCard {
public class PPCard implements Parcelable {

/**
* The card number.
Expand Down Expand Up @@ -70,4 +73,40 @@ public HashMap<String, String> parameters() {

return params;
}

// parcelable
private PPCard(Parcel src) {
number = src.readString();
fullName = src.readString();
expiryMonth = src.readString();
expiryYear = src.readString();
cvv = src.readString();
}

@Override
public int describeContents() {
return 0;
}

@Override
public final void writeToParcel(Parcel dest, int flags) {
dest.writeString(number);
dest.writeString(fullName);
dest.writeString(expiryMonth);
dest.writeString(expiryYear);
dest.writeString(cvv);
}

public static final Parcelable.Creator<PPCard> CREATOR = new Parcelable.Creator<PPCard>() {

@Override
public PPCard createFromParcel(Parcel source) {
return new PPCard(source);
}

@Override
public PPCard[] newArray(int size) {
return new PPCard[size];
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.github.promisepay;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import java.util.Locale;

import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;

public class PromisePayScanActivity extends AppCompatActivity {

private final static Integer MY_SCAN_REQUEST_CODE = 100;

public static final String PROMISE_PAY_SCAN_RESULT = "au.com.promisepay.scanResult";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startScan();
}

private void startScan() {
Intent scanIntent = new Intent(this, CardIOActivity.class);

// customize these values to suit your needs.
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_HIDE_CARDIO_LOGO, true); // default: false

// MY_SCAN_REQUEST_CODE is arbitrary and is only used within this activity.
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == MY_SCAN_REQUEST_CODE) {
if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {

CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);

PPCard card = new PPCard(scanResult.cardNumber,
scanResult.cardholderName,
String.format(Locale.getDefault(), "%d", scanResult.expiryMonth),
String.format(Locale.getDefault(), "%d", scanResult.expiryMonth),
scanResult.cvv);

Intent intent = new Intent();
intent.putExtra(PromisePayScanActivity.PROMISE_PAY_SCAN_RESULT, card);
setResult(Activity.RESULT_OK, intent);
}
else {
setResult(Activity.RESULT_CANCELED);
}
}

finish();
}

}

0 comments on commit 97ae36b

Please sign in to comment.