-
Notifications
You must be signed in to change notification settings - Fork 20
Payment
Shabab Haider Siddique edited this page May 25, 2021
·
5 revisions
class Payment
extends ResultObject
Payment object contains all relevant information about a single payment. API method for Payment\Create will generate a Payment obj.
| Name | Modifier & Type | Description |
|---|---|---|
| id | private string | Unique ID of payment |
| amount | private float | Amount charged |
| currency | private string | Three letter ISO currency code |
| created | private string | Payment creation time as defined in RFC 3339 Section 5.6. UTC timezone. |
| type | private string | Can be either "authorization" or "purchase" |
| live | private boolean | True if payment made in live mode. False if test mode. |
| settle | private boolean optional | |
| status | private string | Can be either "pending" , "approved" or "declined" |
| error | private string | Returned only if status is declined. Provide human readable information on cause of fail. |
| orderId | private string | Must be between 2 and 50 character. Provided by merchant. |
| description | private string | Maximum 255 characters |
| country | private string | Country of customer. ISO 3166-2 alpha-2 country code. |
| paymentMethod | private string | Can be either "card" or "recurring" |
| paymentInstrument | private PaymentInstrumentInterface | Instrument describing payment method |
| authorizeData | private string | Used to provide authenticate on older versions. This parameter is deprecated. |
| authorizationInformation | private AuthorizationInformation | authorization object returned in case additional payment authorization is needed (i.e. payment status is pending) |
| threeDS2AuthorizationInformation | private ThreeDS2AuthorizationInformation | Will contain authorization information in case payment pending under 3ds v2 authorization |
| Name | Return Type | Description |
|---|---|---|
| getId() | public string | Returns payment ID |
| getAmount() | public double | Returns Amount |
| getCurrency() | public double | Returns currency of payment |
| getCreated() | public string | Gets created date of payment |
| getType() | public string | Gets type of payment |
| getLive() | public boolean | Return true if payment is live. False if test |
| getSettle() | public boolean | True purchase, False authorization |
| getStatus() | public string | Return status of payment. (Can be either "pending" , "approved" or "declined" ) |
| getError() | public string | Human readable error if any |
| getOrderId() | public string | |
| getDescription() | public string | |
| getCountry() | public string | |
| getPaymentMethod() | public string | |
| getPaymentInstrument() | public PaymentInstrumentInterface | |
| getAuthorizeData() | public string | Deprecated. shound not be used. Use getAuthorizationInformation instead |
| getAuthorizationInformation() | public AuthorizationInformation | Gets AuthorizationInformation |
| getThreeds2Data() | public ThreeDS2AuthorizationInformation | Gets ThreeDS2AuthorizationInformation |
| isThreedsV1() | public boolean | Return true if the payment is 3D secure v1 authorization |
| isThreedsV2() | public boolean | Return true if the payment is 3D secure v2 authorization |
| isPending() | public boolean | Return true if payment is pending and authorization is needed |
| isApproved() | public boolean | Return true if payment approved |
| isDeclined() | public boolean | Return true if payment rejected |
Below example creates a Client and executes the Payment/Create method
Create client
<?php
use Cardinity\Client;
use Cardinity\Method\Payment;
use Cardinity\Exception;
$client = Client::create([
'consumerKey' => 'YOUR_CONSUMER_KEY',
'consumerSecret' => 'YOUR_CONSUMER_SECRET',
]);Create the payment object
$method = new Payment\Create([
'amount' => 50.00,
'currency' => 'EUR',
'settle' => false,
'description' => 'some description',
'order_id' => '12345678',
'country' => 'LT',
'payment_method' => Payment\Create::CARD,
'payment_instrument' => [
'pan' => '4111111111111111',
'exp_year' => 2021,
'exp_month' => 12,
'cvc' => '456',
'holder' => 'Mike Dough'
],
'threeds2_data' => [
"notification_url" => "your_url_for_handling_callback",
"browser_info" => [
"accept_header" => "text/html",
"browser_language" => "en-US",
"screen_width" => 600,
"screen_height" => 400,
'challenge_window_size' => "600x400",
"user_agent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0",
"color_depth" => 24,
"time_zone" => -60
],
],
]);In case payment could not be processed exception will be thrown. See Error Codes section for detailed list. There are other exceptions. For a full list and example of capturing all available here Exception.
try {
/** @type Cardinity\Method\Payment\Payment */
$payment = $client->call($method);
$status = $payment->getStatus();
if ($status == 'approved') {
// Payment is approved
} elseif ($status == 'pending') {
// Process 3d secure steps
}
} catch (Cardinity\Exception\InvalidAttributeValue $exception) {
foreach ($exception->getViolations() as $key => $violation) {
array_push($errors, $violation->getPropertyPath() . ' ' . $violation->getMessage());
}
} catch (Cardinity\Exception\ValidationFailed $exception) {
foreach ($exception->getErrors() as $key => $error) {
array_push($errors, $error['message']);
}
} catch (Cardinity\Exception\Declined $exception) {
foreach ($exception->getErrors() as $key => $error) {
array_push($errors, $error['message']);
}
} catch (Cardinity\Exception\NotFound $exception) {
foreach ($exception->getErrors() as $key => $error) {
array_push($errors, $error['message']);
}
} catch (Exception $exception) {
$errors = [
$exception->getMessage()
];
}If payment is pending 3d secure authorization will be required. You can determine status of payment and authorization version both from Payment
if ($payment->getStatus() == 'pending') {
// check if passed through 3D secure version 2
if ($payment->isThreedsV2()) {
// If payment require 3ds v2 authorization response will have [ThreeDS2AuthorizationInformation](ThreeDS2AuthorizationInformation)
$creq = $payment->getThreeds2Data()->getCreq();
$paymentId = $payment->getId();
//Generate POST request using the provided data here
} elseif ($payment->isThreedsV1()) {
// If payment require 3ds v1 authorization response will have [AuthorizationInformation](AuthorizationInformation)
$url = $payment->getAuthorizationInformation()->getUrl();
$data = $payment->getAuthorizationInformation()->getData();
//Generate POST request using the provided data here
}
}