diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4278f32..73eec85 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -13,6 +13,13 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index fd96ddb..0131e93 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -55,7 +55,7 @@ - + diff --git a/.idea/modules.xml b/.idea/modules.xml index 4458e64..587a25c 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,9 @@ - + \ No newline at end of file diff --git a/Paystack.iml b/Paystack.iml deleted file mode 100644 index 696f563..0000000 --- a/Paystack.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/example/build.gradle b/example/build.gradle index 78a5406..0dbe985 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -3,12 +3,12 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.0" + buildToolsVersion "23.0.2" defaultConfig { applicationId "co.paystack.example" minSdkVersion 9 - targetSdkVersion 21 + targetSdkVersion 23 versionCode 1 versionName "1.0" } @@ -30,18 +30,19 @@ dependencies { testCompile 'junit:junit:4.12' testCompile "org.assertj:assertj-core:1.7.0" - testCompile 'org.robolectric:robolectric:3.0' + testCompile 'org.robolectric:robolectric:3.1-SNAPSHOT' testCompile 'org.mockito:mockito-core:1.9.5' - //compile 'co.paystack.android:paystack:1.0.2' - //compile 'co.paystack:paystack:1.0.1' - //compile project(':paystack') + compile project(':paystack') } repositories { maven { url 'https://dl.bintray.com/paystack/maven/' } + maven { + url "https://oss.sonatype.org/content/repositories/snapshots" + } } dependencies { diff --git a/example/example.iml b/example/example.iml index 4cfc739..22fbbc2 100644 --- a/example/example.iml +++ b/example/example.iml @@ -1,5 +1,5 @@ - + @@ -67,62 +67,61 @@ - - + - - - - + + - - - - - + - + - - + + + + + + + - - + + - - - - + + + + + + - + - - - + + \ No newline at end of file diff --git a/example/src/androidTest/java/co/paystack/example/ApplicationTest.java b/example/src/androidTest/java/co/paystack/example/ApplicationTest.java index ac44514..6b95e85 100644 --- a/example/src/androidTest/java/co/paystack/example/ApplicationTest.java +++ b/example/src/androidTest/java/co/paystack/example/ApplicationTest.java @@ -7,7 +7,7 @@ * Testing Fundamentals */ public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } + public ApplicationTest() { + super(Application.class); + } } \ No newline at end of file diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 4df4046..f6b7ca6 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -1,28 +1,28 @@ - + + android:theme="@style/AppTheme"> + android:value="pk_test"/> + android:label="@string/app_name"> - + - + diff --git a/example/src/main/java/co/paystack/example/App.java b/example/src/main/java/co/paystack/example/App.java index 969004c..68a8af4 100644 --- a/example/src/main/java/co/paystack/example/App.java +++ b/example/src/main/java/co/paystack/example/App.java @@ -4,33 +4,35 @@ import android.content.Context; /** - * Created by Segun Famisa {segunfamisa@gmail.com} on 9/22/15. + * The Example App + * + * This class allows us capture the application context and capture the app instance */ public class App extends Application { - private static Context sContext; + private static Context sContext; - private static App sInstance; + private static App sInstance; - @Override - public void onCreate() { - super.onCreate(); - - sInstance = this; - sContext = getApplicationContext(); - - setAppContext(sContext); - } - - public static Context getAppContext(){ + public static Context getAppContext() { // if(sContext == null){ // return getApplica; // } - return sContext; - } + return sContext; + } + + private void setAppContext(Context context) { + sContext = context; + } + + @Override + public void onCreate() { + super.onCreate(); + + sInstance = this; + sContext = getApplicationContext(); - private void setAppContext(Context context){ - sContext = context; - } + setAppContext(sContext); + } } diff --git a/example/src/main/java/co/paystack/example/MainActivity.java b/example/src/main/java/co/paystack/example/MainActivity.java index 5cfb20d..c813741 100644 --- a/example/src/main/java/co/paystack/example/MainActivity.java +++ b/example/src/main/java/co/paystack/example/MainActivity.java @@ -18,190 +18,188 @@ public class MainActivity extends AppCompatActivity { - //private static final String PUBLISHABLE_KEY = "your publishable key"; + //private static final String PUBLISHABLE_KEY = "your publishable key"; - EditText mEditCardNum; - EditText mEditCVC; - EditText mEditExpiryMonth; - EditText mEditExpiryYear; - Button mButtonCreateToken; + EditText mEditCardNum; + EditText mEditCVC; + EditText mEditExpiryMonth; + EditText mEditExpiryYear; + Button mButtonCreateToken; - TextView mTextCard; - TextView mTextToken; + TextView mTextCard; + TextView mTextToken; - Token token; - Card card; + Token token; + Card card; - ProgressDialog dialog; + ProgressDialog dialog; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); - mEditCardNum = (EditText)findViewById(R.id.edit_card_number); - mEditCVC = (EditText)findViewById(R.id.edit_cvc); - mEditExpiryMonth = (EditText)findViewById(R.id.edit_expiry_month); - mEditExpiryYear = (EditText)findViewById(R.id.edit_expiry_year); + mEditCardNum = (EditText) findViewById(R.id.edit_card_number); + mEditCVC = (EditText) findViewById(R.id.edit_cvc); + mEditExpiryMonth = (EditText) findViewById(R.id.edit_expiry_month); + mEditExpiryYear = (EditText) findViewById(R.id.edit_expiry_year); - mButtonCreateToken = (Button)findViewById(R.id.button_create_token); + mButtonCreateToken = (Button) findViewById(R.id.button_create_token); - mTextCard = (TextView)findViewById(R.id.textview_card); - mTextToken = (TextView)findViewById(R.id.textview_token); + mTextCard = (TextView) findViewById(R.id.textview_card); + mTextToken = (TextView) findViewById(R.id.textview_token); - dialog = new ProgressDialog(this); + dialog = new ProgressDialog(this); - //initialize sdk - PaystackSdk.initialize(getApplicationContext()); + //initialize sdk + PaystackSdk.initialize(getApplicationContext()); - //set click listener - mButtonCreateToken.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + //set click listener + mButtonCreateToken.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { - //validate form - validateForm(); + //validate form + validateForm(); - //check card validity - if(card.isValid()){ - dialog.setMessage("Request token please wait"); - dialog.setCancelable(true); - dialog.setCanceledOnTouchOutside(true); + //check card validity + if (card.isValid()) { + dialog.setMessage("Request token please wait"); + dialog.setCancelable(true); + dialog.setCanceledOnTouchOutside(true); - dialog.show(); + dialog.show(); - createToken(card); - } - } - }); + createToken(card); + } + } + }); + } + + /** + * Method to validate the form, and set errors on the edittexts. + */ + private void validateForm() { + //validate fields + String cardNum = mEditCardNum.getText().toString().trim(); + + if (isEmpty(cardNum)) { + mEditCardNum.setError("Empty card number"); + return; } - /** - * Method to validate the form, and set errors on the edittexts. - */ - private void validateForm(){ - //validate fields - String cardNum = mEditCardNum.getText().toString().trim(); + //build card object with ONLY the number, update the other fields later + card = new Card.Builder(cardNum, 0, 0, "").build(); + if (!card.validNumber()) { + mEditCardNum.setError("Invalid card number"); + return; + } - if(isEmpty(cardNum)){ - mEditCardNum.setError("Empty card number"); - return; - } + //validate cvc + String cvc = mEditCVC.getText().toString().trim(); + if (isEmpty(cvc)) { + mEditCVC.setError("Empty cvc"); + return; + } + //update the cvc field of the card + card.setCvc(cvc); - //build card object with ONLY the number, update the other fields later - card = new Card.Builder(cardNum, 0, 0, "").build(); - if(!card.validNumber()){ - mEditCardNum.setError("Invalid card number"); - return; - } + //check that it's valid + if (!card.validCVC()) { + mEditCVC.setError("Invalid cvc"); + return; + } - //validate cvc - String cvc = mEditCVC.getText().toString().trim(); - if(isEmpty(cvc)){ - mEditCVC.setError("Empty cvc"); - return; - } - //update the cvc field of the card - card.setCvc(cvc); + //validate expiry month; + String sMonth = mEditExpiryMonth.getText().toString().trim(); + int month = -1; + try { + month = Integer.parseInt(sMonth); + } catch (Exception ignored) { + } - //check that it's valid - if(!card.validCVC()){ - mEditCVC.setError("Invalid cvc"); - return; - } + if (month < 1) { + mEditExpiryMonth.setError("Invalid month"); + return; + } - //validate expiry month; - String sMonth = mEditExpiryMonth.getText().toString().trim(); - int month = -1; - try{ - month = Integer.parseInt(sMonth); - } - catch (Exception e){} + card.setExpiryMonth(month); - if(month < 1){ - mEditExpiryMonth.setError("Invalid month"); - return; - } + String sYear = mEditExpiryYear.getText().toString().trim(); + int year = -1; + try { + year = Integer.parseInt(sYear); + } catch (Exception ignored) { + } - card.setExpiryMonth(month); + if (year < 1) { + mEditExpiryYear.setError("invalid year"); + return; + } - String sYear = mEditExpiryYear.getText().toString().trim(); - int year = -1; - try{ - year = Integer.parseInt(sYear); - } - catch(Exception e){} + card.setExpiryYear(year); - if(year < 1){ - mEditExpiryYear.setError("invalid year"); - return; - } + //validate expiry + if (!card.validExpiryDate()) { + mEditExpiryMonth.setError("Invalid expiry"); + mEditExpiryYear.setError("Invalid expiry"); + } + } - card.setExpiryYear(year); + private void createToken(Card card) { + //then create token using PaystackSdk class + PaystackSdk.createToken(card, new Paystack.TokenCallback() { + @Override + public void onCreate(Token token) { - //validate expiry - if(!card.validExpiryDate()){ - mEditExpiryMonth.setError("Invalid expiry"); - mEditExpiryYear.setError("Invalid expiry"); - return; + //here you retrieve the token, and send to your server for charging. + if (dialog.isShowing()) { + dialog.dismiss(); } - } - private void createToken(Card card){ - //then create token using PaystackSdk class - PaystackSdk.createToken(card, new Paystack.TokenCallback() { - @Override - public void onCreate(Token token) { - - //here you retrieve the token, and send to your server for charging. - if(dialog.isShowing()){ - dialog.dismiss(); - } - - Toast.makeText(MainActivity.this, token.token, Toast.LENGTH_LONG).show(); - MainActivity.this.token = token; - updateTextViews(token); - } - - @Override - public void onError(Exception error) { - if(dialog.isShowing()){ - dialog.dismiss(); - } - Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show(); - updateTextViews(null); - } - }); - } + Toast.makeText(MainActivity.this, token.token, Toast.LENGTH_LONG).show(); + MainActivity.this.token = token; + updateTextViews(token); + } - private void updateTextViews(Token token){ - if(token != null){ - mTextCard.setText("Card last 4 digits: " + token.last4); - mTextToken.setText("Token: " + token.token); - } - else{ - mTextCard.setText("Unable to get token"); - mTextToken.setText("Token was null"); + @Override + public void onError(Exception error) { + if (dialog.isShowing()) { + dialog.dismiss(); } + Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show(); + updateTextViews(null); + } + }); + } + + private void updateTextViews(Token token) { + if (token != null) { + mTextCard.setText(String.format("Card last 4 digits: %s", token.last4)); + mTextToken.setText(String.format("Token: %s", token.token)); + } else { + mTextCard.setText(R.string.token_not_gotten); + mTextToken.setText(R.string.token_null_message); } + } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } - private boolean isEmpty(String s){ - return s == null || s.length() < 1; - } + private boolean isEmpty(String s) { + return s == null || s.length() < 1; + } } diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index 1c234de..d2ed4d3 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -1,11 +1,13 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity"> + + + android:hint="@string/cvv" + android:inputType="number" + android:maxLength="4" + android:minEms="4"/> + android:hint="@string/mm" + android:inputType="number" + android:maxEms="3" + android:maxLength="2"/> + android:hint="@string/yyyy" + android:inputType="number" + android:maxEms="4" + android:maxLength="4"/>