Skip to content

Commit

Permalink
implemented card validation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Sep 8, 2023
1 parent 3b53f7b commit 2c9b7ee
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/apiMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
"cards_get_by_fingerprint": ["/${apiVersion}/${clientId}/cards/fingerprints/${fingerprint}", "GET"],
"card_save": ["/${apiVersion}/${clientId}/cards/${id}", "PUT"],
"card_get_preauthorizations": ["/${apiVersion}/${clientId}/cards/${id}/preauthorizations", "GET"],
"card_validate": ["/${apiVersion}/${clientId}/cards/${id}/validate", "POST"],
"card_validate": ["/${apiVersion}/${clientId}/cards/${id}/validation", "POST"],

// pay ins URLs
"payins_card-web_create": ["/${apiVersion}/${clientId}/payins/card/web/", "POST"],
Expand Down
18 changes: 18 additions & 0 deletions lib/models/CardValidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var EntityBase = require('./EntityBase');

module.exports = EntityBase.extend({
defaults: {
AuthorId: null,
Status: null,
SecureModeReturnURL: null,
SecureModeRedirectURL: null,
SecureModeNeeded: null,
IpAddress: null,
BrowserInfo: null,
Validity: null,
Type: null,
Applied3DSVersion: null,
ResultCode: null,
ResultMessage: null
}
});
10 changes: 7 additions & 3 deletions lib/services/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var Service = require('../service');
var Card = require('../models/Card');
var Transaction = require('../models/Transaction');
var CardPreAuthorization = require('../models/CardPreAuthorization');
var CardValidation = require('../models/CardValidation');


var Cards = Service.extend({
/**
Expand Down Expand Up @@ -107,17 +109,19 @@ var Cards = Service.extend({

/**
* Validate a card
* @param cardId
* @param cardId The ID of the card
* @param cardValidation The create card validation dto
* @param callback
* @param options
* @returns {*|Promise}
*/
validate: function(cardId, callback, options) {
validate: function(cardId, cardValidation, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: cardId
},
dataClass: Card
data: cardValidation,
dataClass: CardValidation
});

return this._api.method('card_validate', callback, options);
Expand Down
43 changes: 30 additions & 13 deletions test/services/CardRegistrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,36 @@ describe('Card Registrations', function () {
});
});

// describe('Validate Card', function () {
// before(function(done) {
// api.Cards.validate(cardRegistration.CardId, function(data, response){
// validatedCard = data;
// done();
// });
// });
//
// it('should be validate', function () {
// expect(validatedCard).to.not.be.undefined;
// expect(validatedCard.Id).to.not.be.undefined;
// });
// });
describe('Validate Card', function () {
before(function(done) {
var cardValidation = {
AuthorId: cardRegistration.UserId,
SecureModeReturnURL: "http://example.com",
IpAddress: "2001:0620:0000:0000:0211:24FF:FE80:C12C",
BrowserInfo: {
AcceptHeader: "text/html, application/xhtml+xml, application/xml;q=0.9, /;q=0.8",
ColorDepth: 4,
JavaEnabled: true,
JavascriptEnabled: true,
Language: 'FR-FR',
ScreenHeight: 1800,
ScreenWidth: 400,
TimeZoneOffset: "+60",
UserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
}
};

api.Cards.validate(cardRegistration.CardId, cardValidation, function (data) {
validatedCard = data;
done();
});
});

it('should be validate', function () {
expect(validatedCard).to.not.be.undefined;
expect(validatedCard.Id).to.not.be.undefined;
});
});

describe('Check Card Existing', function () {
it('should be retrieved', function () {
Expand Down
11 changes: 11 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { shipping } from "./models/shipping";
import { countryAuthorization } from "./models/countryAuthorization";
import { Regulatory } from "./services/Regulatory";
import { Deposits } from "./services/Deposits";
import { cardValidation } from "./models/cardValidation";

export = MangoPay;

Expand Down Expand Up @@ -393,6 +394,16 @@ declare namespace MangoPay {
interface CardRegistration extends cardRegistration.CardRegistrationData {
}

class CardValidation extends EntityBase<cardValidation.CardValidationData> {
constructor(
data:
| cardValidation.CreateCardValidation
);
}

interface CardValidation extends cardValidation.CardValidationData {
}

class Card extends EntityBase<card.CardData> {
constructor(data: card.CardData);
}
Expand Down
22 changes: 20 additions & 2 deletions typings/mangopay2-nodejs-sdk-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,26 @@ api.Cards.getTransactions("card-id").then(data => {
const d = data; // $ExpectType TransactionData[]
});

api.Cards.validate("id").then(data => {
const d = data; // $ExpectType CardData
api.Cards.validate(
"id",
{
AuthorId: "placeholder",
IpAddress: "2001:0620:0000:0000:0211:24FF:FE80:C12C",
BrowserInfo: {
AcceptHeader: "text/html, application/xhtml+xml, application/xml;q=0.9, /;q=0.8",
ColorDepth: 4,
JavaEnabled: true,
JavascriptEnabled: true,
Language: 'FR-FR',
ScreenHeight: 1800,
ScreenWidth: 400,
TimeZoneOffset: "+60",
UserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
},
SecureModeReturnURL: "http://example.com"
}
).then(data => {
const d = data; // $ExpectType CardValidationData
});

/* CardRegistrations */
Expand Down
96 changes: 96 additions & 0 deletions typings/models/cardValidation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { card } from "./card";
import { entityBase } from "./entityBase";
import { transaction } from "./transaction";
import { base } from "../base";
import { payIn } from "./payIn";

export namespace cardValidation {
interface CardValidationData extends entityBase.EntityBaseData {
/**
* The unique identifier of the user at the source of the transaction.
*/
AuthorId: string;

/**
* The status of the transaction.
*/
Status: transaction.TransactionStatus;

/**
* The URL to which users are automatically returned after 3DS2 if it is triggered (i.e., if the SecureModeNeeded parameter is set to true).
*/
SecureModeReturnURL: string;

/**
* The URL to which users are to be redirected to proceed to 3DS2 validation.
*/
SecureModeRedirectURL: string;

/**
* Whether or not the SecureMode was used.
*/
SecureModeNeeded: boolean;

/**
* The IP address of the end user initiating the transaction, in IPV4 or IPV6 format.
*/
IpAddress: string;

/**
* Information about the browser used by the end user (author) to perform the payment.
*/
BrowserInfo: base.BrowserInfoData;

/**
* Whether the card is valid or not.
*/
Validity: card.CardValidity;

/**
* The type of transaction. In the specific case of the Card Validation object, this value indicates a transaction made to perform a strong customer authentication without debiting the card.
*/
Type: transaction.TransactionType;

/**
* The 3DS protocol version applied to the transaction.
*/
Applied3DSVersion: payIn._3DSVersion;

/**
* The code indicating the result of the operation. This information is mostly used to handle errors or for filtering purposes.
*/
ResultCode: string;

/**
* The explanation of the result code.
*/
ResultMessage: string;
}

interface CreateCardValidation {
/**
* The unique identifier of the user at the source of the transaction.
*/
AuthorId: string;

/**
* The URL to which users are automatically returned after 3DS2 if it is triggered (i.e., if the SecureModeNeeded parameter is set to true).
*/
SecureModeReturnURL: string;

/**
* The IP address of the end user initiating the transaction, in IPV4 or IPV6 format.
*/
IpAddress: string;

/**
* Information about the browser used by the end user (author) to perform the payment.
*/
BrowserInfo: base.BrowserInfoData;

/**
* Custom data that you can add to this object.
*/
Tag?: string;
}
}
2 changes: 1 addition & 1 deletion typings/models/transaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export namespace transaction {

type TransactionNature = "REGULAR" | "REPUDIATION" | "REFUND" | "SETTLEMENT";

type TransactionType = "PAYIN" | "TRANSFER" | "PAYOUT";
type TransactionType = "PAYIN" | "TRANSFER" | "PAYOUT" | "CARD_VALIDATION";

type TransactionStatus = "CREATED" | "SUCCEEDED" | "FAILED";

Expand Down
10 changes: 8 additions & 2 deletions typings/services/Cards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { card } from "../models/card";
import { transaction } from "../models/transaction";
import { cardPreAuthorization } from "../models/cardPreauthorization";
import { base } from "../base";
import { cardValidation } from "../models/cardValidation";
import MethodOverload = base.MethodOverload;
import TwoArgsMethodOverload = base.TwoArgsMethodOverload;

export class Cards {
/**
Expand Down Expand Up @@ -45,10 +47,14 @@ export class Cards {
/**
* Validate a card
* @param cardId
* @param cardValidation
* @param callback
* @param options
* @returns {*|Promise}
*/
validate: MethodOverload<string,
card.CardData>;
validate: TwoArgsMethodOverload<
string,
cardValidation.CreateCardValidation,
cardValidation.CardValidationData
>;
}

0 comments on commit 2c9b7ee

Please sign in to comment.