Class: PaysecureApiDocumentationLive::PayinApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/paysecure_api_documentation_live/apis/payin_api.rb

Overview

PayinApi

Constant Summary

Constants inherited from BaseApi

BaseApi::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from PaysecureApiDocumentationLive::BaseApi

Instance Method Details

#create_purchase(body) ⇒ ApiResponse

Payin APIs

Integration Steps: To integrate Virtual Account payments with Paysecure, follow these steps:

  1. Enable Virtual Account in Paysecure: Sign up with Paysecure and ensure the Virtual Account payment method is enabled for your merchant account. Get your API keys for authentication (test and live).

  2. Configure Webhooks: Set up Paysecure webhooks (e.g. transaction.paid, transaction.failed) so your system is notified of payment status changes.

  3. Implement PayIn (Customer Payments): In your checkout flow, allow the customer to choose Virtual Account and then call Paysecure’s PayIn API (e.g. POST /purchases ) with parameters such as amount, currency and paymentMethod=VIRTUAL-ACCOUNT. To generate a Purchase, you are required to provide the Brand ID (in the request body) and API key (in the header). Both can be located in the Dashboard section of your merchant account login. description here

Parameters:

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/paysecure_api_documentation_live/apis/payin_api.rb', line 33

def create_purchase(body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/api/v1/purchases',
                                 Server::SERVER_3)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body)
                            .is_required(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(PurchaseSucess.method(:from_hash))
                .is_api_response(true))
    .execute
end

#create_purchase1(body) ⇒ ApiResponse

To Initiate a payment, the very first call to make is /purchases with the required data in the request body. To generate a Purchase, you are required to provide the Brand ID (in the request body) and API key (in the header) Both can be located in the Dashboard section of your merchant account login. The request body structure is shown on the request body of the example request shown here. The following (see table below) are the mandatory parameters that are required to create a purchase request.

Mandatory parameters in the request body:

Parameter Notes
client.email An Identifier for a user
client.city
client.country ISO-3166 Country Code. It must be upper case.
This
should be "IN" for India
client.stateCode Example “AL”, “XZ”.. Must be in upper case.
client.street_address
client.zip_code
client.full_name
purchase.currency ISO 4217 code for currency you want to send the
transaction in.
purchase.products.name
purchase.products.price Price in decimal format.
example 1:

INR 5 , should be sent as 10.00
brand_id Obtain from Dashboard section of your merchant account login.

| | success_redirect | URL to send the user if the transactions is successful | | failure_redirect | URL to send the user if the transactions is UNSUCCESSFUL |

Optional Parameters

expireInMin

This parameter, when passed in the PayIn request, sets the time window within which a customer should make the Interac payment through their bank's app. If a customer doesn't complete the payment within the configured time window, the status of the payment will be marked as 'EXPIRED' in Paysecure. However, in certain cases, a payment made outside of this window could still be successful i.e. customer's account may be debited which would result in inconsistencies among Paysecure's, merchant's and customer's status of the transaction. To avoid such cases it is advised to set the expiry time limit appropriately and advise the customers to make payment within this window. However, if there is an inconsistency between the status at Paysecure and at customer's Bank, the merchant and Paysecure will reconcile the amounts during the settlement.

merchantRef

The merchantRef parameter, although not mandatory, is strongly advised for merchants to specify. Its inclusion offers two significant advantages for the merchant:

  1. Prevention of Duplicate Requests: When a merchantRef is utilized, it acts as a unique identifier. This means that if a second purchase request is made using the same merchantRef (reference number), the system will recognize it and prevent duplicate transactions from occurring. This prevents unintended or duplicate purchases.

  2. Facilitation of Transaction Retrieval: In situations where the response from the initial purchase request times out or the 'purchaseId' isn't received, having the merchantRef allows the merchant to retrieve detailed transaction information. This ensures they can track and access the specific purchase details related to that reference, even if the immediate response was not received.

However, if the merchant does not specify the 'merchantRef' parameter, the platform will automatically assign and use an internal 'purchaseId' as a reference for that transaction.

paymentMethod

The paymentMethod parameter identifies which payment solution merchant wants to use to perform a transaction. If parameter is provided, than Paysecure will perform direct payment with the selected payment method instead of loading Paysecure URL.

Possible Error Messages

Error Messages Description
Invalid format of Date_of_Birth[allowed format: yyyy-mm-dd]
Enter Valid Email
Please submit Valid Alpha2 Country Code Ex:(AF,IN) in \"country\"
parameter
Please pass Valid State Code
Please pass valid street address in \"street_address\" parameter
Please pass valid city name in \"city\" parameter
Please pass valid postal Code name in \"zip_code\" parameter
You are not Allowed for Live Transaction
Minimum amount is not set for this merchant
success_redirect/failure_redirect/brand_id is missing
brand_id cannot be null
success_redirect cannot be null
failure_redirect cannot be null
Invalid failure_redirect: minimum 10 characters
purchase.products.price cannot be null
purchase.products[0].name/purchase.products[0].price are missing

| | Your charges setting is incomplete .Plese Contact to Administrator. | | | Currency "curr_name" is Not Allowed | | | Transaction amount must be equal or greater to minimum trans amount | | | Allowed Limit for this card for particular time period has been consumed | | Note: For certain use cases, in addition to long format purchase Id, Paysecure also provides a 7 digit unique code for each purchase starting with digit 4, eg 4000001 “purchaseIdShortCode”: “4000013" description here

Parameters:

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/paysecure_api_documentation_live/apis/payin_api.rb', line 202

def create_purchase1(body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/api/v1/purchases',
                                 Server::SERVER_3)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body)
                            .is_required(true))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
                .is_response_void(true)
                .is_api_response(true))
    .execute
end

#get_status(purchase_id) ⇒ ApiResponse

This API tells you about all the details of a purchase (PayIn), including its history Note: With respect to bank transfers, the purchase request is synonymous with the PayIn request.

Mandatory

you need to pass the PurchaseID in the API URL

Possible Value of Status

Status Notes
paid Transaction Successful
payment_in_process Payment is under Processing
expired Purchase has Expired.
error Transaction has Failed.

Response Examples

In the response examples you can see instances of both Paid and Error Status purchases.

Error Details

If there are any issues on the Purchase you can get more details from the transaction_data.attempts.error attribute of the response object

Errors

If there are any errors then it'll be in the format of :

{
    "message": "descriptive error message",
    "code": "error_code"
}

Please see the Status Code section for further details. here

Parameters:

  • purchase_id (String)

    Required parameter: TODO: type description

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/paysecure_api_documentation_live/apis/payin_api.rb', line 81

def get_status(purchase_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/api/v1/purchases/{purchaseId}',
                                 Server::SERVER_3)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .template_param(new_parameter(purchase_id, key: 'purchaseId')
                                .is_required(true)
                                .should_encode(true)))
    .response(new_response_handler
                .deserializer(APIHelper.method(:deserialize_primitive_types))
                .deserialize_into(proc do |response| response&.to_s end)
                .is_api_response(true)
                .is_primitive_response(true))
    .execute
end

#get_status1(purchase_id) ⇒ ApiResponse

This API tells you about all the details of a purchase (PayIn), including its history Note: With respect to bank transfers, the purchase request is synonymous with the PayIn request.

Mandatory

you need to pass the PurchaseID in the API URL

Possible Value of Status

Status Notes
paid Transaction Successful
payment_in_process Payment is under Processing
expired Purchase has Expired.
error Transaction has Failed.

Response Examples

In the response examples you can see instances of both Paid and Error Status purchases.

Error Details

If there are any issues on the Purchase you can get more details from the transaction_data.attempts.error attribute of the response object

Errors

If there are any errors then it'll be in the format of :

{
    "message": "descriptive error message",
    "code": "error_code"
}

Please see the Status Code section for further details. here

Parameters:

  • purchase_id (String)

    Required parameter: TODO: type description

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/paysecure_api_documentation_live/apis/payin_api.rb', line 248

def get_status1(purchase_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/api/v1/purchases/{purchaseId}',
                                 Server::SERVER_3)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .template_param(new_parameter(purchase_id, key: 'purchaseId')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(PurchasesSuccess5.method(:from_hash))
                .is_api_response(true))
    .execute
end