The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Stancer::Payment - Stancer Perl library

VERSION

version 1.0.3

SYNOPSIS

Quick summary of what the module does.

Perhaps a little code snippet.

    use Stancer::Payment;

    my $payment = Stancer::Payment->new();
    ...

ATTRIBUTES

amount

Read/Write integer, must be at least 50.

Amount to pay.

auth

Read/Write instance of Stancer::Auth.

May accept a boolean if you use our payment page or a HTTPS url as an alias for `Stancer::Auth::return_url`.

capture

Read/Write boolean.

Do we need to capture the payment ?

card

Read/Write instance of Stancer::Card.

Target card for the payment.

country

Read-only string.

Card country.

currency

Read/Write string, must be one of "AUD", "CAD", "CHF", "DKK", "EUR", "GBP", "JPY", "NOK", "PLN", "SEK" or "USD".

Payment currency.

customer

Read/Write instance of Stancer::Customer.

Customer handling the payment.

date_bank

Read-only instance of DateTime.

Value date.

description

Read/Write string, 3 to 64 characters.

Description

device

Read/Write instance of Stancer::Device.

Information about device fulfuling the payment.

Stancer::Device needs IP address and port to work, it will automatically used environment variables as created by Apache or nginx (aka SERVER_ADDR and SERVER_PORT).

If variables are not available or if you are using a proxy, you must give IP and port at object instanciation.

    $payment->device(ip => $ip, port => $port);

method

Read-only string, should be "card" or "sepa".

Payment method used.

methods_allowed

Read/Write arrayref of string.

List of methods allowed to be used on payment page.

You can pass a string or an arrayref of string, we will always return an arrayref of string.

order_id

Read/Write string, 1 to 36 characters.

External order id.

refundable_amount

Read-only integer.

Paid amount available for a refund.

refunds

Read-only array of Stancer::Refund instance.

List of refund made on the payment.

response

Read-only 2 or 4 characters string.

API response code.

response_author

Read-only string.

API response author.

return_url

Read/Write string.

URL used to return to your store when using the payment page.

sepa

Read/Write instance of Stancer::Sepa.

Target sepa account for the payment.

status

Read/Write string.

Payment status.

unique_id

Read/Write string, 1 to 36 characters.

External unique id.

If a unique_id is provided, it will used to deduplicate payment.

This should be used only with an identifier unique in your system. You should use an auto-increment or a UUID made in your environment.

METHODS

Stancer::Payment->new() : self

Stancer::Payment->new($token) : self

Stancer::Payment->new(%args) : self

Stancer::Payment->new(\%args) : self

This method accept an optional string, it will be used as an entity ID for API calls.

    # Get an empty new payment
    my $new = Stancer::Payment->new();

    # Get an existing payment
    my $exist = Stancer::Payment->new($token);

$payment->del() : void

This method is not allowed in this context and will always throw an error.

You can delete a payment, but you can refund it.

$payment->is_success() : boolean

$payment->is_not_success() : boolean

$payment->is_error() : boolean

$payment->is_not_error() : boolean

Indicates if payment is a success or not.

Stancer::Payment->list(%terms) : PaymentIterator

Stancer::Payment->list(\%terms) : PaymentIterator

List all payments.

%terms must be an hash or a reference to an hash (\%terms) with at least one of the following key :

created

Must be an unix timestamp, a DateTime or a DateTime::Span object which will filter payments created after this value. If a DateTime::Span is passed, created_until will be ignored and replaced with DateTime::Span->end.

created_until

Must be an unix timestamp or a DateTime object which will filter payments created before this value. If a DateTime::Span is passed to created, this value will be ignored.

limit

Must be an integer between 1 and 100 and will limit the number of objects to be returned. API defaults is to return 10 elements.

order_id

Will filter payments corresponding to the order_id you specified in your initial payment request. Must be a string.

start

Must be an integer and will be used as a pagination cursor, starts at 0.

unique_id

Will filter payments corresponding to the unique_id you specified in your initial payment request. Must be a string.

$payment->payment_page_url()

$payment->payment_page_url( %params )

$payment->payment_page_url( \%params )

External URL for Stancer payment page.

Maybe used as an iframe or a redirection page if you needed it.

%terms must be an hash or a reference to an hash (\%terms) with at least one of the following key :

lang

To force the language of the page.

The page uses browser language as default language. If no language available matches the asked one, the page will be shown in english.

Stancer::Payment->pay($amount, $currency, $card)

Stancer::Payment->pay($amount, $currency, $sepa)

Quick way to make a simple payment.

$payment->refund() : self

$payment->refund($amount) : self

Refund a payment, or part of it.

$amount, if provided, must be at least 50. If not present, all paid amount we be refund.

USAGE

Logging

We use the Log::Any framework for logging events. You may tell where it should log using any available Log::Any::Adapter module.

For example, to log everything to a file you just have to add a line to your script, like this: #! /usr/bin/env perl use Log::Any::Adapter (File => '/var/log/payment.log'); use Stancer::Payment;

You must import Log::Any::Adapter before our libraries, to initialize the logger instance before use.

You can choose your log level on import directly: use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info');

Read the Log::Any documentation to know what other options you have.

SECURITY

  • Never, never, NEVER register a card or a bank account number in your database.

  • Always uses HTTPS in card/SEPA in communication.

  • Our API will never give you a complete card/SEPA number, only the last four digits. If you need to keep track, use these last four digit.

BUGS

Please report any bugs or feature requests on the bugtracker website https://gitlab.com/wearestancer/library/lib-perl/-/issues or by email to bug-stancer@rt.cpan.org.

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Joel Da Silva <jdasilva@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2018-2024 by Stancer / Iliad78.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)