CyberSource SDK v1.0.4 CyberSourceSDK.Client View Source
This Client module handle all HTTPS requests to the CyberSource server. It takes some parameters and convert to HTTPS requests.
It support the following payments:
- Android Pay
- Apple Pay
It supports the following requests:
- Authorization
- Capture
- Refund
Link to this section Summary
Functions
Create an authorization payment
Capture authorization on user credit card
Returns a specification to start this module under a supervisor.
When your request for a credit is successful, the issuing bank for the credit card takes money out of your merchant bank account and returns it to the customer. It usually takes two to four days for your acquiring bank to transfer funds from your merchant bank account.
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
Make a request to pay with Android Pay
Make a request to pay with Apple Pay
Remove authorization on user credit card
A void cancels a capture or credit request that you submitted to CyberSource. A transaction can be voided only when CyberSource has not already submitted the capture or credit request to your processor. CyberSource usually submits capture and credit requests to your processor once a day, so your window for successfully voiding a capture or credit request is small. CyberSource declines your void request when the capture or credit request has already been sent to the processor
Link to this section Functions
authorize(price, merchant_reference_code, card_type, encrypted_payment, bill_to \\ [], worker \\ :merchant) View Source
Create an authorization payment
For a normal account, bill_to is mandatory. If you ask CyberSource for a relaxed AVS check, bill_to can be optional.
Parameters
- price: Float that represents the price to be charged to the user.
- merchant_reference_code: String that represents the order. Normally you should pass an unique identifier like
order_id
. - card_type: String with the name of card type, like VISA, MASTERCARD, etc.
- encrypted_payment: String that must be in Base64 received by Apple/Android payment system.
- bill_to: Structure generated by
CyberSourceSDK.bill_to()
. (Optional) - worker: Atom with name of the structure in configurations to be use. (Optional)
Example
Without bill_to
and worker
parameters
authorize(32.0, "1234", "VISA", "oJ8IOx6SA9HNncxzpS9akm32n+DSAJH==")
With bill_to
parameter
bill_to = CyberSourceSDK.bill_to("John", "Doe", "Marylane Street", "34", "New York", "Hong Kong", "john@example.com")
authorize(32.0, "1234", "VISA", "oJ8IOx6SA9HNncxzpS9akm32n+DSAJH==", bill_to)
capture(order_id, request_params, items \\ [], worker \\ :merchant) View Source
Capture authorization on user credit card
Parameters
- order_id: Unique number to identify the purchase.
- request_params: Base64 of a JSON with
request_id
andrequest_token
from authorization request. - items: An array of map containing the following values:
id
,unit_price
andquantity
. Example:%{id: id, unit_price: unit_price, quantity: quantity}
- worker: Merchant atom to use (setup in configurations).
Result
On successful return the result will be:
{:ok, object}
child_spec(init_arg) View Source
Returns a specification to start this module under a supervisor.
See Supervisor
.
credit(order_id, amount, reason, request_params, worker \\ :merchant) View Source
When your request for a credit is successful, the issuing bank for the credit card takes money out of your merchant bank account and returns it to the customer. It usually takes two to four days for your acquiring bank to transfer funds from your merchant bank account.
get_configuration_params(worker) View Source
get_payment_params(order_id, price, encrypted_token, card_type) View Source
init(args) View Source
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
init_arg
is the argument term (second argument) passed to start_link/3
.
Returning {:ok, state}
will cause start_link/3
to return
{:ok, pid}
and the process to enter its loop.
Returning {:ok, state, timeout}
is similar to {:ok, state}
except handle_info(:timeout, state)
will be called after timeout
milliseconds if no messages are received within the timeout.
Returning {:ok, state, :hibernate}
is similar to {:ok, state}
except the process is hibernated before entering the loop. See
c:handle_call/3
for more information on hibernation.
Returning {:ok, state, {:continue, continue}}
is similar to
{:ok, state}
except that immediately after entering the loop
the c:handle_continue/2
callback will be invoked with the value
continue
as first argument.
Returning :ignore
will cause start_link/3
to return :ignore
and
the process will exit normally without entering the loop or calling
c:terminate/2
. If used when part of a supervision tree the parent
supervisor will not fail to start nor immediately try to restart the
GenServer
. The remainder of the supervision tree will be started
and so the GenServer
should not be required by other processes.
It can be started later with Supervisor.restart_child/2
as the child
specification is saved in the parent supervisor. The main use cases for
this are:
- The
GenServer
is disabled by configuration but might be enabled later. - An error occurred and it will be handled by a different mechanism than the
Supervisor
. Likely this approach involves callingSupervisor.restart_child/2
after a delay to attempt a restart.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without
entering the loop or calling c:terminate/2
.
Callback implementation for GenServer.init/1
.
parse_response(xml) View Source
pay_with_android_pay(price, merchant_reference_code, card_type, encrypted_payment, bill_to \\ [], worker \\ :merchant) View Source
Make a request to pay with Android Pay
Returns {:ok, response_object}
, {:error, :card_type_not_found
or
{:error, response_code}
pay_with_apple_pay(price, merchant_reference_code, card_type, encrypted_payment, bill_to \\ [], worker \\ :merchant) View Source
Make a request to pay with Apple Pay
Returns {:ok, response_object}
, {:error, :card_type_not_found
or
{:error, response_code}
refund(order_id, amount, request_params, items \\ [], worker \\ :merchant) View Source
Remove authorization on user credit card
Parameters
- order_id: Unique number to identify the purchase.
- amount: Price (value) to refund.
- request_params: Base64 of a JSON with
request_id
andrequest_token
from authorization request. - items: An array of map containing the following values:
id
,unit_price
andquantity
. Example:%{id: id, unit_price: unit_price, quantity: quantity}
- worker: Merchant atom to use (setup in configurations)
Example
refund("1234", 23435465442432, items)
start_link() View Source
void(order_id, request_params, worker \\ :merchant) View Source
A void cancels a capture or credit request that you submitted to CyberSource. A transaction can be voided only when CyberSource has not already submitted the capture or credit request to your processor. CyberSource usually submits capture and credit requests to your processor once a day, so your window for successfully voiding a capture or credit request is small. CyberSource declines your void request when the capture or credit request has already been sent to the processor