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

Fix request when using avs as verification method #28

Merged
merged 2 commits into from
Apr 8, 2020
Merged
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
44 changes: 26 additions & 18 deletions pages/debug/cards/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
label="Verification Method"
/>

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

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

Expand Down Expand Up @@ -87,7 +91,7 @@
</template>

<script lang="ts">
import { Component, Vue, Watch } from 'nuxt-property-decorator'
import { Component, Vue } from 'nuxt-property-decorator'
import { mapGetters } from 'vuex'
import uuidv4 from 'uuid/v4'
import openPGP from '@/lib/openpgp'
Expand Down Expand Up @@ -117,18 +121,7 @@ import ExpiryInput from '@/components/ExpiryInput.vue'
}
})
export default class CreateCardClass extends Vue {
@Watch('formData.verificationMethod', { immediate: true })
onChildChanged(val: string) {
if (val === 'none') {
this.cvvRequired = false
}
if (val === 'cvv') {
this.cvvRequired = true
}
}

// data
cvvRequired = true
formData = {
cardNumber: '',
cvv: '',
Expand Down Expand Up @@ -170,16 +163,31 @@ export default class CreateCardClass extends Vue {
prefillForm(index: number) {
this.formData = exampleCards[index].formData
}

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

async makeApiCall() {
this.loading = true

const { cardNumber, cvv, ...data } = this.formData
const cardDetails = {
number: cardNumber.trim().replace(/\D/g, ''),
cvv
}
const { expiry, verificationMethod, ...billingDetails } = data

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

if (verificationMethod === 'cvv') {
cardDetails = {
...cardDetails,
cvv
}
}

const payload: CreateCardPayload = {
idempotencyKey: uuidv4(),
expMonth: parseInt(expiry.month),
Expand All @@ -194,7 +202,7 @@ export default class CreateCardClass extends Vue {
}

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