Skip to content

Commit

Permalink
Merge pull request #394 from Mangopay/feature/payment-method-metadata
Browse files Browse the repository at this point in the history
[Feature] Payment Method Metadata
  • Loading branch information
iulian03 authored Feb 21, 2024
2 parents 537149e + c35b870 commit a8aedae
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/apiMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module.exports = {
"payins_ideal-web_create": ["/${apiVersion}/${clientId}/payins/payment-methods/ideal", "POST"],
"payins_giropay-web_create": ["/${apiVersion}/${clientId}/payins/payment-methods/giropay", "POST"],

"payment_method_metadata_get": ["/${apiVersion}/${clientId}/payment-methods/metadata", "POST"],

"payouts_bankwire_create": ["/${apiVersion}/${clientId}/payouts/bankwire/", "POST"],
"payouts_bankwire_get": ["/${apiVersion}/${clientId}/payouts/bankwire/${id}", "GET"],
"payouts_get": ["/${apiVersion}/${clientId}/payouts/${id}", "GET"],
Expand Down
16 changes: 16 additions & 0 deletions lib/models/BinData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var EntityBase = require('./EntityBase');

var BinData = EntityBase.extend({
defaults: {
/**
* The subtype of the card product. Examples include: CLASSIC, GOLD, PLATINUM, PREPAID, etc.
*/
Subtype: null,
/**
* The card brand. Examples include: AMERICAN EXPRESS, DISCOVER, JCB, MASTERCARD, VISA, etc.
*/
Brand: null
}
});

module.exports = BinData;
46 changes: 46 additions & 0 deletions lib/models/PaymentMethodMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var EntityBase = require('./EntityBase');

var PaymentMethodMetadata = EntityBase.extend({
defaults: {
/**
* The type of metadata. Allowed values: BIN, GOOGLE_PAY
*/
Type: null,
/**
* The bank identification number (BIN). (Format: 6 or 8 digits)
*/
Bin: null,
/**
* The tokenized payment data provided by the third-party payment method.
*/
Token: null,
/**
* In the case of Google Pay, the format of the Token.
* PAN_ONLY – The card is registered in the Google account and requires 3DS authentication.
* CRYPTOGRAM_3DS – The card is enrolled in the customer’s Google Wallet and authentication is handled by the Android device.
*/
TokenFormat: null,
/**
* The type of the card. Allowed / Returned / Default values: CREDIT, DEBIT, CHARGE CARD
*/
CardType: null,
/**
* The country where the card was issued. Format: ISO-3166 alpha-2 two-letter country code
*/
IssuerCountryCode: null,
/**
* The name of the card issuer.
*/
IssuingBank: null,
/**
* Whether the card is held in a personal or commercial capacity.
*/
CommercialIndicator: null,
/**
* Additional data about the card based on the BIN. In the case of co-branded card products, two objects are returned.
*/
BinData: null
}
});

module.exports = PaymentMethodMetadata;
18 changes: 18 additions & 0 deletions lib/services/PayIns.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const PayInPaymentDetailsBlik = require("../models/PayInPaymentDetailsBlik");
const PayInPaymentDetailsKlarna = require("../models/PayInPaymentDetailsKlarna");
const PayInPaymentDetailsIdeal = require("../models/PayInPaymentDetailsIdeal");
const PayInPaymentDetailsGiropay = require("../models/PayInPaymentDetailsGiropay");
const PaymentMethodMetadata = require('../models/PaymentMethodMetadata');


var PayIns = Service.extend({
/**
Expand Down Expand Up @@ -233,6 +235,22 @@ var PayIns = Service.extend({
return this._api.method('payins_googlepay-direct_create_v2', callback, options);
},

/**
*
* @param metadata POST body which should contain the 'Type' and: 'Bin' (if the type is BIN) or 'Token' (if the type is GOOGLE_PAY)
* @param callback Callback function
* @param options Request options
* @returns PaymentMethodMetadata
*/
getPaymentMethodMetadata: function(metadata, callback, options) {
options = this._api._getOptions(callback, options, {
data: metadata,
dataClass: PaymentMethodMetadata
});

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

getPaymentKey: function(payIn) {
if (payIn.PaymentType) {
return payIn.PaymentType.toLowerCase().replace('_', '');
Expand Down
28 changes: 28 additions & 0 deletions test/services/PayIns.js
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,34 @@ describe('PayIns', function () {
});
});

describe('Payment Method Metadata', function () {
var metadata;
var payIn;

before(function (done) {
helpers.getNewPayInCardDirect(api, john, function (createdPayIn) {
payIn = createdPayIn
var metadataPost = {
Type: "BIN",
Bin: payIn.CardInfo.BIN
}

api.PayIns.getPaymentMethodMetadata(metadataPost, function (data) {
metadata = data;
done();
});
});
});

describe('Fetch Metadata', function () {
it('should fetch the payment method metadata', function () {
expect(metadata.Type).to.equal('BIN')
expect(metadata.Bin).to.equal(payIn.CardInfo.BIN);
});
});

});

// describe('Card PreAuthorized Deposit', function () {
// var payIn;
//
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 @@ -953,6 +953,13 @@ api.PayIns.createRecurringPayInRegistrationMIT({
const d = data; // $ExpectType RecurringPayInData
});

api.PayIns.getPaymentMethodMetadata({
Type: "BIN",
Bin: "1234"
}).then(data => {
const d = data; // $ExpectType PaymentMethodMetadata
});

/* Clients */
api.Clients.get().then(data => {
const d = data; // $ExpectType ClientData
Expand Down
67 changes: 67 additions & 0 deletions typings/models/payIn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1919,4 +1919,71 @@ export namespace payIn {
*/
Tag?: string;
}

interface BinData {
/**
* The subtype of the card product. Examples include: CLASSIC, GOLD, PLATINUM, PREPAID, etc.
*/
Subtype: string;
/**
* The card brand. Examples include: AMERICAN EXPRESS, DISCOVER, JCB, MASTERCARD, VISA, etc.
*/
Brand: string;
}

interface PaymentMethodMetadata {
/**
* The type of metadata. Allowed values: BIN, GOOGLE_PAY
*/
Type: string;
/**
* The bank identification number (BIN). (Format: 6 or 8 digits)
*/
Bin: string;
/**
* The tokenized payment data provided by the third-party payment method.
*/
Token: string;
/**
* In the case of Google Pay, the format of the Token.
* PAN_ONLY – The card is registered in the Google account and requires 3DS authentication.
* CRYPTOGRAM_3DS – The card is enrolled in the customer’s Google Wallet and authentication is handled by the Android device.
*/
TokenFormat: string;
/**
* The type of the card. Allowed / Returned / Default values: CREDIT, DEBIT, CHARGE CARD
*/
CardType: string;
/**
* The country where the card was issued. Format: ISO-3166 alpha-2 two-letter country code
*/
IssuerCountryCode: string;
/**
* The name of the card issuer.
*/
IssuingBank: string;
/**
* Whether the card is held in a personal or commercial capacity.
*/
CommercialIndicator: string;
/**
* Additional data about the card based on the BIN. In the case of co-branded card products, two objects are returned.
*/
BinData: BinData[];
}

interface PaymentMethodMetadataRequest {
/**
* The type of metadata. Allowed values: BIN, GOOGLE_PAY
*/
Type: string;
/**
* The bank identification number (BIN). (Format: 6 or 8 digits)
*/
Bin?: string;
/**
* The tokenized payment data provided by the third-party payment method.
*/
Token?: string;
}
}
6 changes: 6 additions & 0 deletions typings/services/PayIns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ export class PayIns {
*/
createGooglePay:
MethodOverload<payIn.CreateGooglePayDirectPayIn, payIn.GooglePayDirectPayInData>;

/**
* Get Payment Method Metadata
* The body should contain the 'Type' and: 'Bin' (if the type is BIN) or 'Token' (if the type is GOOGLE_PAY)
*/
getPaymentMethodMetadata: MethodOverload<payIn.PaymentMethodMetadataRequest, payIn.PaymentMethodMetadata>;
}

0 comments on commit a8aedae

Please sign in to comment.