From df0fd7fd2434cae7e283ddffad9974f37343b166 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 21 Feb 2024 10:09:46 +0200 Subject: [PATCH 1/3] implemented PaymentMethodMetadata endpoint --- lib/apiMethods.js | 2 ++ lib/models/BinData.js | 16 ++++++++++ lib/models/PaymentMethodMetadata.js | 46 +++++++++++++++++++++++++++++ lib/services/PayIns.js | 18 +++++++++++ test/services/PayIns.js | 28 ++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 lib/models/BinData.js create mode 100644 lib/models/PaymentMethodMetadata.js diff --git a/lib/apiMethods.js b/lib/apiMethods.js index a7066e8..4e7e878 100644 --- a/lib/apiMethods.js +++ b/lib/apiMethods.js @@ -54,6 +54,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"], diff --git a/lib/models/BinData.js b/lib/models/BinData.js new file mode 100644 index 0000000..611c336 --- /dev/null +++ b/lib/models/BinData.js @@ -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; diff --git a/lib/models/PaymentMethodMetadata.js b/lib/models/PaymentMethodMetadata.js new file mode 100644 index 0000000..2ee8b7a --- /dev/null +++ b/lib/models/PaymentMethodMetadata.js @@ -0,0 +1,46 @@ +var EntityBase = require('./EntityBase'); + +var BinData = 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 = BinData; diff --git a/lib/services/PayIns.js b/lib/services/PayIns.js index e7e2f8f..f735d03 100644 --- a/lib/services/PayIns.js +++ b/lib/services/PayIns.js @@ -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({ /** @@ -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('_', ''); diff --git a/test/services/PayIns.js b/test/services/PayIns.js index 906781b..76a9a05 100644 --- a/test/services/PayIns.js +++ b/test/services/PayIns.js @@ -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; // From 7579ed69c7fbe865de12a9ecd9d3bf2222040dc2 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 21 Feb 2024 10:41:50 +0200 Subject: [PATCH 2/3] added typings --- lib/services/PayIns.js | 2 +- typings/mangopay2-nodejs-sdk-tests.ts | 7 +++ typings/models/payIn.d.ts | 67 +++++++++++++++++++++++++++ typings/services/PayIns.d.ts | 6 +++ 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/lib/services/PayIns.js b/lib/services/PayIns.js index f735d03..d1da4c8 100644 --- a/lib/services/PayIns.js +++ b/lib/services/PayIns.js @@ -237,7 +237,7 @@ var PayIns = Service.extend({ /** * - * @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 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 diff --git a/typings/mangopay2-nodejs-sdk-tests.ts b/typings/mangopay2-nodejs-sdk-tests.ts index 5e81424..6cae23c 100644 --- a/typings/mangopay2-nodejs-sdk-tests.ts +++ b/typings/mangopay2-nodejs-sdk-tests.ts @@ -946,6 +946,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 diff --git a/typings/models/payIn.d.ts b/typings/models/payIn.d.ts index 4f2245f..c977be1 100644 --- a/typings/models/payIn.d.ts +++ b/typings/models/payIn.d.ts @@ -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; + } } diff --git a/typings/services/PayIns.d.ts b/typings/services/PayIns.d.ts index 633f128..7e588bc 100644 --- a/typings/services/PayIns.d.ts +++ b/typings/services/PayIns.d.ts @@ -99,4 +99,10 @@ export class PayIns { */ createGooglePay: MethodOverload; + + /** + * 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; } From c35b8707d76a9af0f2175c00f72a7d1f065a17fb Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 21 Feb 2024 11:02:22 +0200 Subject: [PATCH 3/3] small change --- lib/models/PaymentMethodMetadata.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/models/PaymentMethodMetadata.js b/lib/models/PaymentMethodMetadata.js index 2ee8b7a..4b34083 100644 --- a/lib/models/PaymentMethodMetadata.js +++ b/lib/models/PaymentMethodMetadata.js @@ -1,6 +1,6 @@ var EntityBase = require('./EntityBase'); -var BinData = EntityBase.extend({ +var PaymentMethodMetadata = EntityBase.extend({ defaults: { /** * The type of metadata. Allowed values: BIN, GOOGLE_PAY @@ -43,4 +43,4 @@ var BinData = EntityBase.extend({ } }); -module.exports = BinData; +module.exports = PaymentMethodMetadata;