UNPKG

@hipay/hipay-enterprise-sdk-nodejs

Version:

The HiPay Enterprise SDK for NodeJS is a library for developers who want to integrate HiPay Enterprise payment methods to any NodeJS platform.

117 lines (104 loc) 6.65 kB
'use strict'; const TransactionRequest = require('./TransactionRequest'); const InvalidArgumentException = require('../../Error/InvalidArgumentException'); const AbstractPaymentMethod = require('./PaymentMethod/AbstractPaymentMethod'); const BrowserInfo = require('./Model/ThreeDSTwo/BrowserInfo'); class OrderRequest extends TransactionRequest { /** * @inheritDoc * * Creates an OrderRequest ready to use with the SDK * @param {Object} values * * --- Inherited from TransactionRequest * @param {Object} [values.customData] Request's custom data * @param {Object} [values.source] Request's source data * @param {'AUTO'|'SAPI'|'CONS'|'PAGE'|'TPE'|'RTRY'|'MANU'|'PREF'|'REVI'|'CMS'|'SSDK'|'CSDK'} [values.source.source] Technical source of this call * @param {String} [values.source.integration_version] Integration version (version of the CMS module for example) * @param {String} [values.source.brand] Source Brand (CMS name or Site name) * @param {String} [values.source.brand_version] Version of the brand (version of your site) * @param {Object} [values.basket] Request's basket data * @param {String} values.orderid Order unique id * @param {'Sale'|'Authorization'} [values.operation] Transaction type: Sale indicates that the transaction is automatically submitted for capture. Authorization indicates that this transaction is sent for authorization only. * @param {String} values.description The order short description * @param {String} [values.longDescription] Additional description for the order * @param {String} values.currency Base currency for the order. This three-character currency code complies with ISO 4217. * @param {Number} values.amount Total order amount * @param {Number} [values.shipping = 0] Order shipping fee. Defaults to 0. * @param {Number} [values.tax = 0] Order tax fee. Defaults to 0. * @param {Number} [values.taxRate = 0] Order tax rate. Defaults to 0. * @param {String} [values.cid] Customer id, defined by the merchant * @param {String} [values.ipaddr] IP Adress of the customer * @param {String} [values.acceptUrl] URL to redirect the customer after payment success * @param {String} [values.declineUrl] URL to redirect the customer after payment decline * @param {String} [values.pendingUrl] URL to redirect the customer after payment pending * @param {String} [values.exceptionUrl] URL to redirect the customer after system error * @param {String} [values.cancelUrl] URL to redirect the customer after cancellation by the customer * @param {String} [values.notifyUrl] URL to send the notifications to * @param {String} [values.httpAccept] This should contain the exact content of the HTTP ACCEPT header sent from the customer's browser. * @param {String} [values.httpUserAgent] This should contain the exact content of the HTTP User-Agent header sent from the customer's browser. * @param {String} [values.deviceFingerprint] This element should contain the value of the device fingerprint generated by the HiPay Front JS SDK. * @param {String} [values.language] Locale code of your customer. This will be used to display the next pages in the correct language. * @param {CustomerBillingInfoRequest} [values.customerBillingInfo] Billing information of the customer * @param {CustomerShippingInfoRequest} [values.customerShippingInfo] Shipping information of the customer * @param {DeliveryShippingInfoRequest} [values.deliveryInformation] Delivery information of this order * @param {PreviousAuthInfo} [values.previousAuthInfo] Previous Authentication info, for 3DS validation purposes * @param {MerchantRiskStatement} [values.merchantRiskStatement] Merchant risk information, for 3DS validation purposes * @param {AccountInfo} [values.accountInfo] Customer's account information, for 3DS validation purposes * @param {Number} [values.deviceChannel] Device Channel. See the Device Channel Enumeration * @param {RecurringInfo} [values.recurringInfo] Reccurent order information, for 3DS validation purposes * @param {Number} [values.requestId] The request ID * @param {String} [values.softDescriptor] Billing descriptor. * * @param {String} values.paymentProduct Payment product for the order * @param {BrowserInfo} [values.browserInfo] Browser information as sent by the HiPay Front JS SDK, for 3DS validation purposes * @param {Number} [values.salesChannel = 1] Sales Channel. See the Sales Channel Enumeration * @param {AbstractPaymentMethod} [values.paymentMethod] Payment data for this order * @param {Object} [values.providerData] Parameter to use for specific provider data like PayPal. * @param {Number} [values.oneClick] This parameter indicates whether the payment should be a one-click payment. `1`: Initiate a one-click payment use case */ constructor(values) { super(values); if (Object.hasOwn(values, 'paymentProduct')) { this.paymentProduct = values.paymentProduct; } else { throw new InvalidArgumentException('Order Request must have a Payment Product'); } if (Object.hasOwn(values, 'paymentMethod')) { if (!(values.paymentMethod instanceof AbstractPaymentMethod)) { throw new InvalidArgumentException('paymentMethod must be instance of AbstractPaymentMethod'); } this.paymentMethod = values.paymentMethod; } if (Object.hasOwn(values, 'browserInfo')) { if (values.browserInfo instanceof BrowserInfo) { this.browserInfo = values.browserInfo; } else { this.browserInfo = new BrowserInfo(values.browserInfo); } } if (Object.hasOwn(values, 'salesChannel')) { this.salesChannel = values.salesChannel; } if (Object.hasOwn(values, 'providerData')) { if (typeof values.providerData === 'object') { this.providerData = JSON.stringify(values.providerData); } else { this.providerData = values.providerData; } } if (Object.hasOwn(values, 'oneClick')) { this.oneClick = values.oneClick; } } initValues() { super.initValues(); this.paymentProduct = null; this.paymentMethod = null; this.browserInfo = null; this.salesChannel = null; this.providerData = null; this.oneClick = null; } } module.exports = OrderRequest;