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

Removing verification field in create card and make payment #41

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion components/CreateCardForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export default class CreateCardFormClass extends Vue {
idempotencyKey: uuidv4(),
expMonth: parseInt(expiry.month),
expYear: 2000 + parseInt(expiry.year),
verification: 'cvv',
keyId: '',
encryptedData: '',
billingDetails,
Expand Down
21 changes: 7 additions & 14 deletions lib/cardTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0001@circle.com',
verification: 'cvv'
email: 'customer-0001@circle.com'
}
},
{
Expand All @@ -37,8 +36,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0002@circle.com',
verification: 'cvv'
email: 'customer-0002@circle.com'
}
},
{
Expand All @@ -58,8 +56,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0003@circle.com',
verification: 'cvv'
email: 'customer-0003@circle.com'
}
},
{
Expand All @@ -79,8 +76,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0004@circle.com',
verification: 'cvv'
email: 'customer-0004@circle.com'
}
},
{
Expand All @@ -100,8 +96,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0005@circle.com',
verification: 'cvv'
email: 'customer-0005@circle.com'
}
},
{
Expand All @@ -121,8 +116,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0006@circle.com',
verification: 'cvv'
email: 'customer-0006@circle.com'
}
},
{
Expand All @@ -142,8 +136,7 @@ export const exampleCards = [
city: 'Test City',
postalCode: '11111',
phoneNumber: '+12025550180',
email: 'customer-0007@circle.com',
verification: 'cvv'
email: 'customer-0007@circle.com'
}
}
]
1 change: 0 additions & 1 deletion lib/cardsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface CreateCardPayload {
}
expMonth: number
expYear: number
verification: string
metadata: MetaData
}

Expand Down
45 changes: 10 additions & 35 deletions pages/debug/cards/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@
<v-form>
<v-text-field v-model="formData.cardNumber" label="Card Number" />

<v-select
v-model="formData.verification"
:items="verificationMethods"
label="Verification Method"
/>

<v-text-field
v-if="showCVVField"
v-model="formData.cvv"
label="CVV"
/>
<v-text-field v-model="formData.cvv" label="CVV" />

<v-text-field v-model="formData.expiry.month" label="Expiry Month" />

Expand Down Expand Up @@ -147,11 +137,9 @@ export default class CreateCardClass extends Vue {
line2: '',
city: '',
postalCode: '',
verification: 'cvv',
phoneNumber: '',
email: ''
}
verificationMethods = ['none', 'cvv']
rules = {
isNumber: (v: string) =>
v === '' || !isNaN(parseInt(v)) || 'Please enter valid number',
Expand All @@ -176,35 +164,24 @@ export default class CreateCardClass extends Vue {
this.formData = exampleCards[index].formData
}

get showCVVField() {
return this.formData.verification === 'cvv'
}

async makeApiCall() {
this.loading = true

const { email, phoneNumber, cardNumber, cvv, ...data } = this.formData
const { expiry, verification, ...billingDetails } = data
const { expiry, ...billingDetails } = data

let cardDetails: {
const cardDetails: {
number: string
cvv?: string
} = {
number: cardNumber.trim().replace(/\D/g, '')
}

if (verification === 'cvv') {
cardDetails = {
...cardDetails,
cvv
}
number: cardNumber.trim().replace(/\D/g, ''),
cvv
}

const payload: CreateCardPayload = {
idempotencyKey: uuidv4(),
expMonth: parseInt(expiry.month),
expYear: 2000 + parseInt(expiry.year),
verification,
keyId: '',
encryptedData: '',
billingDetails,
Expand All @@ -217,14 +194,12 @@ export default class CreateCardClass extends Vue {
}

try {
if (verification === 'cvv' || verification === 'avs') {
const publicKey = await this.$cardsApi.getPCIPublicKey()
const encryptedData = await openPGP.encrypt(cardDetails, publicKey)
const { encryptedMessage, keyId } = encryptedData
const publicKey = await this.$cardsApi.getPCIPublicKey()
const encryptedData = await openPGP.encrypt(cardDetails, publicKey)
const { encryptedMessage, keyId } = encryptedData

payload.keyId = keyId
payload.encryptedData = encryptedMessage
}
payload.keyId = keyId
payload.encryptedData = encryptedMessage

await this.$cardsApi.createCard(payload)
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion pages/flow/charge/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ export default class ChargeFlowClass extends Vue {
idempotencyKey: uuidv4(),
expMonth: parseInt(this.formData.cardData.expiry.month),
expYear: 2000 + parseInt(this.formData.cardData.expiry.year),
verification: 'none',
keyId: '',
encryptedData: '',
billingDetails: {
Expand Down