Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of customField to chargeCard request parameters #42

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Initial update to include custom fields in charge
  • Loading branch information
Olayinka Okewale committed Nov 4, 2019
commit 5255865a8f2a43e5461e1a2fb018ba8ec13ea5a8
24 changes: 24 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import RNPaystack from "..";

const PUBLIC_KEY = "pk_test_63847c1ea97fdd25178ca0297bbdb71542e1a9bb";
RNPaystack.init({ publicKey: PUBLIC_KEY});

it("Expects custom fields to be added", async () => {

try {
const response = await RNPaystack.chargeCard({
cardNumber: '4123450131001381',
expiryMonth: '10',
expiryYear: '17',
cvc: '883',
email: '[email protected]',
amountInKobo: 150000,
subAccount: 'ACCT_pz61jjjsslnx1d9',
});

console.log("Paystack Response => ", response);
} catch (err) {
console.log("An error occurred => ", err);
}

})
17 changes: 17 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(5.6.1))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ private void validateFullTransaction() {
charge.setReference(chargeOptions.getString("reference"));
}

// **NEW: Added this for metadata/custom fields
if (hasKey("customField")) {
// charge.setReference(chargeOptions.get)
ReadableArray customFields = chargeOptions.getArray("customField");
if (!customFields.isNull()) {
int customFieldListSize = customFields.size();
for (int i = 0; i < customFieldListSize; i++) {
ReadableMap customField = customFields.getMap(i);
String displayName = customField.getString("display_name");
String value = customField.getString("value");

// Now set paystack custom field.
charge.putCustomField(displayName, value);
}
}
}

}

private void createTransaction() {
Expand Down
15 changes: 14 additions & 1 deletion ios/RNPaystack.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,20 @@ - (BOOL)cardParamsAreValid:(NSString *)cardNumber withMonth:(NSString *)expMonth

if (params[@"reference"] != nil) {
transactionParams.reference = params[@"reference"];
}
}

// **NEW: Adding Custom Fields to Transaction
if (params[@"customField"] != nil) {
do {
for (NSDictionary *customField in params[@"customField"]) {
if (customField[@"value"] != nil && customField[@"display_name"] != nil) {
try transactionParams.setCustomFieldValue(customField[@"value"], displayedAs: customField[@"display_name"]);
}
}
} catch {
print(error);
}
}

if ([self isCardValid:cardParams]) {

Expand Down
Loading