diff --git a/src/api/payment-setups/payment-setups.js b/src/api/payment-setups/payment-setups.js index 42eb7af7..33819aa6 100644 --- a/src/api/payment-setups/payment-setups.js +++ b/src/api/payment-setups/payment-setups.js @@ -60,6 +60,24 @@ export default class PaymentSetups { * not an array despite the plural name), insurance (object, added 2026-09-08: type [string], company [string], * price [{ amount: number, currency: string (3-letter ISO) }]). * + * Tamara (per the `Tamara` spec): + * - payment_methods.tamara: optional Tamara, the Tamara payment method's details and configuration. + * The key is `tamara`. Fields you send: + * - initialization: The initialization state of the payment method. When you create a Payment Setup, + * this defaults to disabled. [Optional]. Enum: "disabled" "enabled". Default "disabled". + * - risk_assessment: Risk signals about the customer, forwarded to Tamara with the payment. + * [Optional]. Object: + * - premium_customer: Specifies whether the customer is a premium customer. [Optional]. boolean. + * - risk_score: The customer's risk score. [Optional]. integer. + * - order_count_last24h: The number of orders the customer has made in the last 24 hours. + * [Optional]. integer. + * - linked_device_count: The number of devices linked to the customer. [Optional]. integer. + * Fields the response returns (readOnly, do not send them): + * - status: The payment method status. [Optional]. readOnly. + * Enum: "unavailable" "action_required" "ready" "initialization_required" "invalid". + * - flags: The list of error codes or indicators that highlight missing or invalid information. + * [Optional]. readOnly. Array of string. + * * Cash App Pay and customer (per the `PaymentSetup` specs): * - payment_methods.cashapp: optional CashApp, the Cash App payment method's details and configuration. * The key is `cashapp`, one lowercase word (not `cash_app`, not `cashApp`). Fields you send: @@ -161,6 +179,21 @@ export default class PaymentSetups { * refundable, delivery_recipient, host; PaymentSetupAirline.ancillaries, delivery_recipient, * insurance, refundable, total_number_of_passengers, travel_type, trip_type. * + * Tamara (per the `Tamara` spec): + * - payment_methods.tamara: optional Tamara, the Tamara payment method's details and configuration. + * The key is `tamara`. Fields you send: + * - initialization: The initialization state of the payment method. When you create a Payment Setup, + * this defaults to disabled. [Optional]. Enum: "disabled" "enabled". Default "disabled". + * - risk_assessment: Risk signals about the customer, forwarded to Tamara with the payment. + * [Optional]. Object: + * - premium_customer: Specifies whether the customer is a premium customer. [Optional]. boolean. + * - risk_score: The customer's risk score. [Optional]. integer. + * - order_count_last24h: The number of orders the customer has made in the last 24 hours. + * [Optional]. integer. + * - linked_device_count: The number of devices linked to the customer. [Optional]. integer. + * The response also returns the readOnly status and flags. See `createAPaymentSetup` for their + * full description. + * * Cash App Pay and customer (per the `PaymentSetup` specs): * - payment_methods.cashapp: optional CashApp, the Cash App payment method's details and configuration. * The key is `cashapp`, one lowercase word (not `cash_app`, not `cashApp`). Fields you send: @@ -284,6 +317,17 @@ export default class PaymentSetups { * - customer_since: The date and time the customer's Cash App account was created. [Optional]. * Format: date-time. Returned as a string; the provider's format varies. * + * Tamara (per the `Tamara` spec), under payment_methods.tamara (key `tamara`): + * - status: The payment method status. [Optional]. readOnly. + * Enum: "unavailable" "action_required" "ready" "initialization_required" "invalid". + * - flags: The list of error codes or indicators that highlight missing or invalid information. + * [Optional]. readOnly. Array of string. + * - initialization: The initialization state of the payment method. [Optional]. + * Enum: "disabled" "enabled". Default "disabled". + * - risk_assessment: Risk signals about the customer, forwarded to Tamara with the payment. + * [Optional]. Part of the `Tamara` schema, but the sandbox does not return it on get. Its four + * fields are described on `createAPaymentSetup`. + * * The response's customer carries id, country (min 2 characters, max 2 characters), email, name, * tax_number, phone, device (locale, fingerprint, ipv4, ipv6, client, os) and merchant_account, * as described on `createAPaymentSetup`. @@ -332,13 +376,16 @@ export default class PaymentSetups { * subsequent response omits it. See `getAPaymentSetup` for its 13 fields and the 8 address fields. * - status, flags, initialization and customer_profile_sharing, as described on `getAPaymentSetup`. * + * Tamara (per the `Tamara` spec): the response's payment_methods.tamara carries status, flags, + * initialization and risk_assessment, as described on `getAPaymentSetup`. + * * The response's customer carries id, country (min 2 characters, max 2 characters), email, name, * tax_number, phone, device (locale, fingerprint, ipv4, ipv6, client, os) and merchant_account, * as described on `createAPaymentSetup`. * * @memberof PaymentSetups * @param {string} id - The unique identifier of the Payment Setup. - * @param {string} payment_method_name - The name of the payment method to process the payment with (e.g. "tabby", "klarna", "card", "cashapp"). + * @param {string} payment_method_name - The name of the payment method to process the payment with (e.g. "tabby", "klarna", "card", "cashapp", "tamara"). * @returns {Promise} A promise to the Confirm a Payment Setup response */ async confirmAPaymentSetup(id, payment_method_name) { diff --git a/test/payment-setups/payment-setups-it.js b/test/payment-setups/payment-setups-it.js index 99b78ed9..0644c779 100644 --- a/test/payment-setups/payment-setups-it.js +++ b/test/payment-setups/payment-setups-it.js @@ -231,6 +231,39 @@ describe('Integration::Payment-Setups', () => { expect(cashapp.customer_profile_sharing).to.equal(true); expect(cashapp.status).to.be.oneOf(["unavailable", "action_required", "ready", "initialization_required", "invalid"]); }); + + it('should create a Tamara payment setup with risk_assessment and read the tamara payment method', async function () { + const riskAssessment = { + premium_customer: false, + risk_score: 42, + order_count_last24h: 0, + linked_device_count: 2 + }; + const response = await cko.paymentSetups.createAPaymentSetup({ + processing_channel_id: processingChannelId, + amount: 1000, + currency: "SAR", + reference: `TEST-REF-TAMARA-${Date.now()}`, + payment_methods: { + tamara: { + initialization: "enabled", + risk_assessment: riskAssessment + } + } + }); + + if (!(response.available_payment_methods || []).includes("tamara")) { + this.test.title += ' (skipped: Tamara is not enabled on the sandbox processing channel)'; + this.skip(); + } + + const fetched = await cko.paymentSetups.getAPaymentSetup(response.id); + const tamara = fetched.payment_methods.tamara; + expect(tamara).to.be.an('object'); + expect(tamara.initialization).to.equal("enabled"); + // The sandbox accepts risk_assessment on create but does not return it on get. + expect(tamara.status).to.be.oneOf(["unavailable", "action_required", "ready", "initialization_required", "invalid"]); + }); }); describe('Error handling', () => { diff --git a/test/payment-setups/payment-setups-unit.js b/test/payment-setups/payment-setups-unit.js index 715186d4..57231ff7 100644 --- a/test/payment-setups/payment-setups-unit.js +++ b/test/payment-setups/payment-setups-unit.js @@ -3572,4 +3572,143 @@ describe('Unit::Payment-Setups', () => { expect(result.customer.merchant_account.last_payment_amount).to.equal(55.99); }); }); + + describe('Tamara initialization and risk_assessment', () => { + const host = 'https://123456789.api.sandbox.checkout.com'; + const setupId = 'psu_wmakpe4nrza3rv2vhtwzoszja'; + + const tamaraRequest = { + processing_channel_id: 'pc_aaaaaaaaaaaaaaaaaaaaaaaaaa', + amount: 1000, + currency: 'SAR', + payment_methods: { + tamara: { + initialization: 'enabled', + risk_assessment: { + premium_customer: false, + risk_score: 42, + order_count_last24h: 0, + linked_device_count: 2 + } + } + } + }; + + const setupResponse = { + id: setupId, + processing_channel_id: 'pc_aaaaaaaaaaaaaaaaaaaaaaaaaa', + amount: 1000, + currency: 'SAR', + payment_methods: { + tamara: { + status: 'ready', + flags: [], + ...tamaraRequest.payment_methods.tamara + } + } + }; + + const expectTamaraWireKeys = (received) => { + const wire = JSON.stringify(received); + expect(wire).to.include('"tamara":{"initialization":"enabled","risk_assessment":{'); + expect(wire).to.include('"premium_customer":false'); + expect(wire).to.include('"risk_score":42'); + expect(wire).to.include('"order_count_last24h":0'); + expect(wire).to.include('"linked_device_count":2'); + expect(wire).to.not.include('riskAssessment'); + expect(wire).to.not.include('orderCountLast24h'); + }; + + it('should send payment_methods.tamara with initialization and risk_assessment unchanged on create', async () => { + // Arrange + let received; + const scope = nock(host) + .post('/payments/setups', (body) => { + received = body; + return true; + }) + .reply(200, setupResponse); + + const cko = new Checkout('sk_test_xxx', { subdomain: '123456789' }); + + // Act + const result = await cko.paymentSetups.createAPaymentSetup(tamaraRequest); + + // Assert + expect(scope.isDone()).to.be.true; + expect(received).to.deep.equal(tamaraRequest); + expectTamaraWireKeys(received); + expect(result).to.deep.equal(setupResponse); + }); + + it('should send payment_methods.tamara with initialization and risk_assessment unchanged on update', async () => { + // Arrange + let received; + const scope = nock(host) + .put(`/payments/setups/${setupId}`, (body) => { + received = body; + return true; + }) + .reply(200, setupResponse); + + const cko = new Checkout('sk_test_xxx', { subdomain: '123456789' }); + + // Act + const result = await cko.paymentSetups.updateAPaymentSetup(setupId, tamaraRequest); + + // Assert + expect(scope.isDone()).to.be.true; + expect(received).to.deep.equal(tamaraRequest); + expectTamaraWireKeys(received); + expect(result).to.deep.equal(setupResponse); + }); + + it('should read tamara status, flags, initialization and risk_assessment from get', async () => { + // Arrange + const getResponse = { + ...setupResponse, + payment_methods: { + tamara: { ...setupResponse.payment_methods.tamara, status: 'action_required', flags: ['example_flag'] } + } + }; + const scope = nock(host) + .get(`/payments/setups/${setupId}`) + .reply(200, getResponse); + + const cko = new Checkout('sk_test_xxx', { subdomain: '123456789' }); + + // Act + const result = await cko.paymentSetups.getAPaymentSetup(setupId); + + // Assert + expect(scope.isDone()).to.be.true; + expect(result).to.deep.equal(getResponse); + const tamara = result.payment_methods.tamara; + expect(Object.keys(tamara)).to.have.lengthOf(4); + expect(tamara.status).to.equal('action_required'); + expect(tamara.flags).to.deep.equal(['example_flag']); + expect(tamara.initialization).to.equal('enabled'); + expect(Object.keys(tamara.risk_assessment)).to.have.lengthOf(4); + expect(tamara.risk_assessment.premium_customer).to.equal(false); + expect(tamara.risk_assessment.risk_score).to.equal(42); + expect(tamara.risk_assessment.order_count_last24h).to.equal(0); + expect(tamara.risk_assessment.linked_device_count).to.equal(2); + }); + + it('should confirm with "tamara" on payments/setups/{id}/confirm/tamara and read the tamara response', async () => { + // Arrange + const scope = nock(host) + .post(`/payments/setups/${setupId}/confirm/tamara`) + .reply(200, setupResponse); + + const cko = new Checkout('sk_test_xxx', { subdomain: '123456789' }); + + // Act + const result = await cko.paymentSetups.confirmAPaymentSetup(setupId, 'tamara'); + + // Assert + expect(scope.isDone()).to.be.true; + expect(result.payment_methods.tamara).to.deep.equal(setupResponse.payment_methods.tamara); + }); + }); }); diff --git a/types/dist/api/payment-setups/payment-setups.d.ts b/types/dist/api/payment-setups/payment-setups.d.ts index 969a0ce9..54dff5af 100644 --- a/types/dist/api/payment-setups/payment-setups.d.ts +++ b/types/dist/api/payment-setups/payment-setups.d.ts @@ -158,9 +158,34 @@ export type CashApp = { action?: CashAppAction; }; -/** The payment methods of a Payment Setup. Only cashapp is typed here; other methods pass through. */ +/** Risk signals about the customer, forwarded to Tamara with the payment (Tamara.risk_assessment). */ +export type TamaraRiskAssessment = { + /** Specifies whether the customer is a premium customer. */ + premium_customer?: boolean; + /** The customer's risk score. Integer. */ + risk_score?: number; + /** The number of orders the customer has made in the last 24 hours. Integer. */ + order_count_last24h?: number; + /** The number of devices linked to the customer. Integer. */ + linked_device_count?: number; +}; + +/** The Tamara payment method's details and configuration (Tamara). Sent under payment_methods.tamara. */ +export type Tamara = { + /** The payment method status. Response only. */ + status?: PaymentSetupPaymentMethodStatus; + /** The list of error codes or indicators that highlight missing or invalid information. Response only. */ + flags?: string[]; + /** The initialization state of the payment method. Default "disabled". */ + initialization?: PaymentSetupPaymentMethodInitialization; + /** Risk signals about the customer, forwarded to Tamara with the payment. */ + risk_assessment?: TamaraRiskAssessment; +}; + +/** The payment methods of a Payment Setup. Only cashapp and tamara are typed here; other methods pass through. */ export type PaymentSetupPaymentMethods = { cashapp?: CashApp; + tamara?: Tamara; [paymentMethod: string]: unknown; };