Skip to content

Commit

Permalink
Merge pull request #390 from Mangopay/feature/card-validation-v2
Browse files Browse the repository at this point in the history
implemented get card validation endpoint
  • Loading branch information
iulian03 authored Feb 21, 2024
2 parents 05b8357 + a066f34 commit 537149e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/apiMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
"card_save": ["/${apiVersion}/${clientId}/cards/${id}", "PUT"],
"card_get_preauthorizations": ["/${apiVersion}/${clientId}/cards/${id}/preauthorizations", "GET"],
"card_validate": ["/${apiVersion}/${clientId}/cards/${id}/validation", "POST"],
"get_card_validation": ["/${apiVersion}/${clientId}/cards/${cardId}/validation/${cardValidationId}", "GET"],

// pay ins URLs
"payins_card-web_create": ["/${apiVersion}/${clientId}/payins/card/web/", "POST"],
Expand Down
20 changes: 20 additions & 0 deletions lib/services/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ var Cards = Service.extend({
});

return this._api.method('card_validate', callback, options);
},

/**
* Get Card Validation
* @param cardId The ID of the card
* @param cardValidationId The ID of the CardValidation
* @param callback
* @param options
* @returns {*|Promise}
*/
getCardValidation: function(cardId, cardValidationId, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
cardId: cardId,
cardValidationId: cardValidationId
},
dataClass: CardValidation
});

return this._api.method('get_card_validation', callback, options);
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ module.exports = {
"City": "Washington",
"Region": "District of Columbia",
"PostalCode": "80400",
"Country": "US"
"Country": "FR"
}
},
Reference: "1234",
Expand Down
20 changes: 19 additions & 1 deletion test/services/CardRegistrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('Card Registrations', function () {
describe('Cards', function () {
var card;
var validatedCard;
var fetchedCardValidation;
before(function(done) {
api.Cards.get(cardRegistration.CardId, function(data, response){
card = data;
Expand Down Expand Up @@ -146,9 +147,26 @@ describe('Card Registrations', function () {
});
});

it('should be validate', function () {
it('should be validated', function () {
expect(validatedCard).to.not.be.undefined;
expect(validatedCard.Id).to.not.be.undefined;
expect(validatedCard.Type).to.equal("CARD_VALIDATION");
});
});

describe('Get Card Validation', function () {
before(function(done) {
api.Cards.getCardValidation(cardRegistration.CardId, validatedCard.Id, function(data) {
fetchedCardValidation = data;
done();
});
});

it('should fetch card validation', function () {
expect(fetchedCardValidation).to.not.be.undefined;
expect(fetchedCardValidation.Id).to.not.be.undefined;
expect(fetchedCardValidation.Id).to.equal(validatedCard.Id);
expect(fetchedCardValidation.Type).to.equal("CARD_VALIDATION");
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/services/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ describe('Users', function() {
expect(john.Id).not.to.be.undefined;
expect(john.PersonType).to.equal(PersonType.Natural);
expect(john.TermsAndConditionsAccepted).to.be.false;
expect(john.UserCategory).to.equal('UNKNOWN');
expect(john.UserCategory).to.equal('OWNER');
});

it('Create Legal', function() {
expect(matrix.Id).not.to.be.undefined;
expect(matrix.PersonType).to.equal(PersonType.Legal);
expect(matrix.TermsAndConditionsAccepted).to.be.false;
expect(matrix.UserCategory).to.equal('UNKNOWN');
expect(matrix.UserCategory).to.equal('OWNER');
});

it('Create Natural Payer', function(){
Expand Down
7 changes: 7 additions & 0 deletions typings/mangopay2-nodejs-sdk-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@ api.Cards.validate(
const d = data; // $ExpectType CardValidationData
});

api.Cards.getCardValidation(
"cardId",
"cardValidationId"
).then(data => {
const d = data; // $ExpectType CardValidationData
});

/* CardRegistrations */

api.CardRegistrations.create({
Expand Down
5 changes: 4 additions & 1 deletion typings/models/event.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export namespace event {
| "DEPOSIT_PREAUTHORIZATION_PAYMENT_EXPIRED"
| "DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCEL_REQUEST"
| "DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCELED"
| "DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED";
| "DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED"
| "CARD_VALIDATION_CREATED"
| "CARD_VALIDATION_SUCCEEDED"
| "CARD_VALIDATION_FAILED";

interface EventData {
/**
Expand Down
14 changes: 14 additions & 0 deletions typings/services/Cards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ export class Cards {
cardValidation.CreateCardValidation,
cardValidation.CardValidationData
>;

/**
* Validate a card
* @param cardId
* @param cardValidationId
* @param callback
* @param options
* @returns {*|Promise}
*/
getCardValidation: TwoArgsMethodOverload<
string,
string,
cardValidation.CardValidationData
>;
}

0 comments on commit 537149e

Please sign in to comment.