42-cent-base
Interface to implement by 42-cent adaptor. See documentation for more information.
Global
BaseGateway
Structural interface, actual implementations must implement
BaseGateway.submitTransaction(order, creditCard, prospect, other)
authorize and capture a transaction.
all values must be Strings
Parameters
order: Object, the fields related to the order
- amount
- the amount of the transaction
creditCard: CreditCard | Object, object holding credit card information
- creditCardNumber
- the credit card number used for the transaction - a string with card number digit, no blank, no dash, etc
- expirationMonth - two digit string : 01 -> 12
- The month of credit card expiration date
- expirationYear
- The year of credit card expiration date - four or two digits string 2016 or 16
- cvv
- the credit card cvv number
prospect: Prospect | Object, the fields related to the prospect
- customerFirstName
- first name of the customer (also used for the billing)
- customerLastName(also used for the billing)
- last name of the customer
- customerEmail(also used for the billing)
- email of the customer
- billingAddress
- the billing address
- billingCity
- the billing city
- billingState
- the billing state
- billingZip
- billing zip code
- billingCountry
- the billing country
- shippingFirstName
- the shipping first name
- shippingLastName
- the shipping last name
- shippingAddress
- the shipping address
- shippingCity
- the shipping city
- shippingState
- the shipping state
- shippingZip
- shipping zip code
- shippingCountry
- the shipping country
other: Object, other field specific to a gateway sdk implementation. refer to specific sdk for more details
Returns: Promise, - the promise will have these different fields
if resolved
- transactionId
- A unique identifier of the transaction.
- authCode
- authorization code from the banking institution
- _original
-
- the original response from the specific sdk implementation
-
if rejected
if the rejection occurs because of the gateway the reason will be an instance of {@link GatewayError} holding the following information
- message
- The error message from the gateway
- _original
- The original response from the specific sdk implementation
otherwise it will be an instance of standard javascript Error
BaseGateway.authorizeTransaction(order, creditCard, prospect, other)
authorize only a transaction
same parameters than {@link BaseGateway#submitTransaction}
Parameters
order: authorize only a transaction
same parameters than {@link BaseGateway#submitTransaction}
creditCard: authorize only a transaction
same parameters than {@link BaseGateway#submitTransaction}
prospect: authorize only a transaction
same parameters than {@link BaseGateway#submitTransaction}
other: authorize only a transaction
same parameters than {@link BaseGateway#submitTransaction}
BaseGateway.getSettledBatchList(from, to)
get a batch list of settled transaction within the window of time
Parameters
from: String | Date, Lower limit. If String, it must be a valid date string: a string which will result in a valid Javascript Date object if passed as argument of the Date constructor
to: String | Date, Upper limit (or today if not provided). If String, it must be a valid date string: a string which will result in a valid Javascript Date object if passed as argument of the Date constructor
Returns: Promise, - The promise should resolve with the following fields
- batchList
- An array of batch where a batch will have the following fields
- batchId
- The id the batch is referenced by in the gateway internal system
- settlementDate
- A string for the settlement date time (UTC)
- chargeAmount
- the total amount from the charged transactions during the window of time
- chargeCount
- the total count of charged transactions during the window of time
- refundAmount
- the total amount from the refunded transactions during the window of time
- refundCount
- the total count of refund transactions during the window of time
- voidCount
- the total count of voided transactions during the window of time
- declineCount
- the total count of voided transactions during the window of time
- errorCount
- the total count of voided transactions during the window of time
BaseGateway.refundTransaction(transactionId, options)
-----------------------------
Refund (or credit) an already settled transaction
Parameters
transactionId: String, the reference to the transaction to refund (used by the underlying payment gateway system)
options: Object, a set of optional fields
- amount
- the amount to be refunded (partial refund)
Returns: Promise, - the result promise will have the following fields
if resolved
- _original
- the original response from the payment gateway
if rejected
if the rejection occurs because of the gateway the reason will be an instance of {@link GatewayError} holding the following information
- message
- The error message from the gateway
- _original
- The original response from the specific sdk implementation
otherwise it will be an instance of standard javascript Error
BaseGateway.voidTransaction(transactionId, options)
void a (non settled) transaction
Parameters
transactionId: String, the reference to the transaction to void (used by the underlying payment gateway system)
options: Object, a set of optional fields
Returns: Promise, - the result promise will have the following fields
if resolved
- _original
- the original response from the payment gateway
if rejected
if the rejection occurs because of the gateway the reason will be an instance of {@link GatewayError} holding the following information
- message
- The error message from the gateway
- _original
- The original response from the specific sdk implementation
otherwise it will be an instance of standard javascript Error
BaseGateway.createSubscription(creditCard, prospect, subscriptionPlan, other)
create a recurring payment
Parameters
creditCard: CreditCard | Object, the credit card associated to the payment
prospect: Prospect | Object, the prospect/customer linked to the subscription
subscriptionPlan: SubscriptionPlan | Object, a subscription plan
Note that the tuple [periodUnit , periodLength] must result in a period supported by the gateway implementation otherwise periodUnit should take priority
other: Object, a set of options to be used by specific implementations
Returns: Promise, - the result promise will have the following fields
if resolved
- subscriptionId
- a reference id to the subscription
- _original
- the original response from the payment gateway
BaseGateway.createCustomerProfile(payment, billing, shipping, other)
-----------------------------
create a customer profile in gateway system, useful to charge a customer without having to use his payment info
Parameters
payment: CreditCard | Object, payment info to associate with the customer
billing: Object, billing info to associate with the customer
shipping: Object, shipping info to associate with the customer
other: Object, optional info related to a specific gateway implementation
Returns: Promise, - the resolve promise will have the following fields
if resolved
- profileId
- a reference id to the customer profile
- _original
- the original response from the payment gateway
BaseGateway.getCustomerProfile(profileId)
-----------------------------
get a customer profile
Parameters
profileId: String, the id related to the customer profile in the gateway system
Returns: Promise, -
if resolved the promise will have the same field than a Prospect instance plus a field payment
holding a CreditCard
BaseGateway.chargeCustomer(order, prospect, other)
submit a transaction (auth+capture) from a customer profile.
Parameters
order: Object, order information
prospect: Prospect, the prospect profile to charge, note that the prospect must have the field profileId set
other: Object, optional info related to a specific gateway implementation
Returns: Promise, cf BaseGateway#submitTransaction
license
42-cent-base module is under MIT license:
Copyright (C) 2014 Laurent Renard.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.