From cfe0e3a8a8c2a524a3e0f6e7109a5f54a0b74797 Mon Sep 17 00:00:00 2001 From: santiago-delpuerto-cko Date: Tue, 12 Sep 2017 16:09:34 +0100 Subject: [PATCH] Support for Billing Address in Charges with Card Token + Update Lib version --- README.md | 2 +- .../ApiServices/Charges/ChargesMapper.php | 21 +++++++++++++++++++ .../Charges/RequestModels/BaseCharge.php | 14 +++++++++++++ .../packages/CheckoutApi/Client/Constant.php | 2 +- composer.json | 2 +- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b07cf5c..6d85143 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Or require the Checkout.com package inside the composer.json of your project: ``` "require": { "php": ">=5.2.4", - "checkout/checkout-php-api": "1.2.9" + "checkout/checkout-php-api": "1.2.10" }, ``` __Manually__ diff --git a/com/checkout/ApiServices/Charges/ChargesMapper.php b/com/checkout/ApiServices/Charges/ChargesMapper.php index a702d70..652971e 100644 --- a/com/checkout/ApiServices/Charges/ChargesMapper.php +++ b/com/checkout/ApiServices/Charges/ChargesMapper.php @@ -156,6 +156,27 @@ public function requestPayloadConverter($requestModel = null ) $requestPayload['shippingDetails'] = $shippingAddressConfig; } + + if (method_exists($requestModel, 'getBillingDetails') && $billingAddress = $requestModel->getBillingDetails()) { + $billingAddressConfig = array( + 'addressLine1' => $billingAddress->getAddressLine1(), + 'addressLine2' => $billingAddress->getAddressLine2(), + 'postcode' => $billingAddress->getPostcode(), + 'country' => $billingAddress->getCountry(), + 'city' => $billingAddress->getCity(), + 'state' => $billingAddress->getState(), + ); + + if ($billingAddress->getPhone() != null) { + $billingAddressConfig = array_merge_recursive($billingAddressConfig, array( + 'phone' => $billingAddress->getPhone()->getPhoneDetails() + ) + ); + } + + $requestPayload['billingDetails'] = $billingAddressConfig; + } + if(method_exists($requestModel,'getProducts') && $productsItem = $requestModel->getProducts()) { foreach ( $productsItem as $i => $item ) { diff --git a/com/checkout/ApiServices/Charges/RequestModels/BaseCharge.php b/com/checkout/ApiServices/Charges/RequestModels/BaseCharge.php index 1929dfe..2e372ea 100644 --- a/com/checkout/ApiServices/Charges/RequestModels/BaseCharge.php +++ b/com/checkout/ApiServices/Charges/RequestModels/BaseCharge.php @@ -17,6 +17,7 @@ class BaseCharge extends BaseChargeInfo protected $_chargeMode; protected $_riskCheck; protected $_attemptN3D; + protected $_billingDetails; /** * @return mixed @@ -233,4 +234,17 @@ public function getAttemptN3D() { return $this->_attemptN3D; } + + /** + * @param mixed billingDetails + */ + public function setBillingDetails( $billingDetails) + { + $this->_billingDetails= $billingDetails; + } + + public function getBillingDetails() + { + return $this->_billingDetails; + } } \ No newline at end of file diff --git a/com/checkout/packages/CheckoutApi/Client/Constant.php b/com/checkout/packages/CheckoutApi/Client/Constant.php index 4559743..6021902 100644 --- a/com/checkout/packages/CheckoutApi/Client/Constant.php +++ b/com/checkout/packages/CheckoutApi/Client/Constant.php @@ -24,5 +24,5 @@ final class CheckoutApi_Client_Constant const VERSION = 'v2'; const STATUS_CAPTURE = 'Captured'; const STATUS_REFUND = 'Refunded'; - const LIB_VERSION = 'v1.2.9'; + const LIB_VERSION = 'v1.2.10'; } diff --git a/composer.json b/composer.json index 2ea6645..d28b735 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "checkout/checkout-php-api", "description": "Checkout PHP API Library", "homepage": "https://github.com/checkout/checkout-php-library", - "version": "1.2.9", + "version": "1.2.10", "type": "library", "license": "MIT", "keywords": ["checkout.com","payment","gateway","online payment","checkoutcom","GW3","CKO"],