Promo library

Overview

This Java library provides methods for calculating monthly payment amounts for a given cart total or product price.

Default

Calculate payment amount with defaults. This is the standard method for calculating the monthly payment amount.

AffirmPromoResults calculate(Double loanAmount)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.

PageType

Calculate payment amount with PageType.

AffirmPromoResults calculate(Double loanAmount,
                             PageType pageType)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
pageType
required
PageTypeUsed to pass in the page type Enum defined in the Calculator class

Promo ID

Calculate payment amount with Promo ID.

AffirmPromoResults calculate(Double loanAmount,
                             String promoName)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.

Promo ID and PageType

Calculate payment amount with Promo ID and PageType.

AffirmPromoResults calculate(Double loanAmount,
                             String promoName,
                             PageType pageType)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.
pageType
required
PageTypeUsed to pass in the page type Enum defined in the Calculator class

Promo ID and Supplier Name

Calculate payment amount with Promo ID and Supplier Name

AffirmPromoResults calculate(Double loanAmount,
                             String promoName,
                             String supplierName)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.
supplierName
optional
stringThe supplier name to use when generating the calculation results.

Promo ID, Supplier Name and PageType

Calculate payment amount with Promo ID, Supplier Name and PageType.

AffirmPromoResults calculate(Double loanAmount,
                             String promoName,
                             String supplierName,
                             PageType pageType)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.
supplierName
optional
stringThe supplier name to use when generating the calculation results.
pageType
required
PageTypeUsed to pass in the page type Enum defined in the Calculator class

Date

Calculate payment amount on a specific Date.

AffirmPromoResults calculate(Double loanAmount,
                             Date captureDate)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
captureDate
optional
DateThe date we should assume when determining the applicable financing program. If a timezone is set, it will be respected during APR calculation.

Date with PageType

Calculate payment amount on a specific Date, with PageType.

AffirmPromoResults calculate(Double loanAmount,
                             Date captureDate,
                             PageType pageType)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
captureDate
optional
DateThe date we should assume when determining the applicable financing program. If a timezone is set, it will be respected during APR calculation.
pageType
required
PageTypeUsed to pass in the page type Enum defined in the Calculator class

Promo ID on a specific Date

Calculate payment amount with Promo ID on a specific Date.

AffirmPromoResults calculate(Double loanAmount,
                             Date captureDate,
                             String promoName)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
captureDate
optional
DateThe date we should assume when determining the applicable financing program. If a timezone is set, it will be respected during APR calculation.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.

Promo ID on a specific Date with PageType

Calculate payment amount with Promo ID on a specific Date with PageType.

AffirmPromoResults calculate(Double loanAmount,
                             Date captureDate,
                             String promoName,
                             PageType pageType)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
captureDate
optional
DateThe date we should assume when determining the applicable financing program. If a timezone is set, it will be respected during APR calculation.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.
pageType
required
PageTypeUsed to pass in the page type Enum defined in the Calculator class

Promo ID and Supplier Name on a specific Date

Calculate payment amount with Promo ID and Supplier Name on a specific Date

AffirmPromoResults calculate(Double loanAmount,
                             Date captureDate,
                             String promoName,
                             String supplierName)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
captureDate
optional
DateThe date we should assume when determining the applicable financing program. If a timezone is set, it will be respected during APR calculation.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.
supplierName
optional
stringThe supplier name to use when generating the calculation results.

Promo ID and Supplier Name on a specific Date and PageType

Calculate payment amount with Promo ID and Supplier Name on a specific Date and PageType

AffirmPromoResults calculate(Double loanAmount,
                             Date captureDate,
                             String promoName,
                             String supplierName,
                             PageType pageType)
loanAmount
required
doubleThe product or cart total in $xx.xx format. Should always be a positive number.
captureDateDateThe date we should assume when determining the applicable financing program. If a timezone is set, it will be respected during APR calculation.
promoName
optional
stringThe promo ID to use. This will affect the financing program and text templates used.
supplierName
optional
stringThe supplier name to use when generating the calculation results.
pageType
required
PageTypeUsed to pass in the page type Enum defined in the Calculator class

AffirmPromoResults Response

This object will be returned from the calculate methods documented above. You can map these fields to the text template you're using to render the Affirm monthly payment methods.

{
    successful = successful;
    error = AffirmPromoResults.AffirmPromoCalculatorError
    message = message;
    apr = apr;
    loanAmount = loanAmount;
    monthlyPayment = monthlyPayment;
    monthlyPaymentExact = monthlyPaymentExact;
    date = date;
    url = url;
}
successfulbooleanResult of calculation True / False
messagestringIn error cases a message will be provided explaining the reason for failure
aprdoubleResulting APR of calculation
errorenumAffirmPromoCalculationError reason for error
loanAmountdoubleThe original loan amount
*monthlyPayment**doubleThe monthly payment amount to display currently rounded and ending in XX.00 ( Zeros ) to be trimmed and displayed as an integer.
monthlyPaymentExactdoubleThe monthly payment amount without rounding up.
dateDateThe date this calculation was generated.
urlstringURL to use for the educational modal iFrame.

AffirmPromoCalculator.PageType Enum

Optional: Calculate method param used to tailor educational modal content to be context specific about either a single set of terms, or a collection.

{
    BANNER,
    CART,
    CATEGORY,
    HOMEPAGE,
    LANDING,
    PAYMENT,
    PRODUCT,
    SEARCH
}

AffirmPromoResults.AffirmPromoCalculatorError Enum

When AffirmPromoResults.error is set to an enum value, the message field can be interrogated for more details on the error.

{
    INVALID_LOAN_AMOUNT
}