diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 0000000..c9cf9af --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,59 @@ +# Afterpay PrestaShop Module Changelog + +### Release Name: Version 1.0.0 +#### Release date: 05 Mar 2018 +#### Platform: PrestaShop 1.6 + +### Supported Editions and Versions: +- PrestaShop 1.6.1.17 and later +- Afterpay-PrestaShop1.6 module v1.0.0 has been verified against a new instance of PrestaShop 1.6.1.17 +- https://github.com/PrestaShop/PrestaShop/releases/tag/1.6.1.17 + +### Supported Markets: +- Australia (AUD currency) + +### Highlights +Version 1.0.0 of the Afterpay-PrestaShop1.6 module introduces: +- Afterpay transaction processing (orders and refunds) – Australia. +- Transaction Integrity Check. +- Afterpay asset display on PrestaShop website. +- Afterpay configuration in PrestaShop Back Office. +- Afterpay module logging. + +#### Afterpay transaction processing (orders and refunds) - Australia +- Access to the Afterpay Payment Gateway via Afterpay Merchant API V1. +- Following a successful Afterpay payment capture, the below records are created in PrestaShop Back Office: + * PrestaShop Order record with status of 'Payment accepted' + * PrestaShop Invoice document linked to Order record +- PrestaShop order refunds (full value) trigger a call to the Afterpay API to process the refund. +- PrestaShop order refunds (partial value) are not supported in this version (1.0.0). +- Afterpay Merchant Portal provides the functionality to perform order refunds (partial or full value). + +#### Transaction Integrity Check +- To verify the integrity of each transaction, a Transaction Integrity Check has been implemented. +- The Transaction Integrity Check compares the below values at time of checkout against the value present prior to payment capture: + * Afterpay Token ID + * PrestaShop Quote total amount. +- In the instance of a discrepancy between these values, the transaction is cancelled and no payment capture attempts will be made. + +#### Afterpay asset display on PrestaShop website +- Afterpay installment detail displayed on PrestaShop product pages. +- Afterpay is included as a Payment Method on PrestaShop checkout page 'Payment' step. +- Afterpay installment detail on the Payment Submission page. +- Afterpay Lightbox modal available on PrestaShop product pages. + +#### Afterpay configuration in Prestashop Back Office +- Afterpay module configuration available under: + * PrestaShop Back Office > Modules > Modules & Services > Installed Modules. +- Afterpay configuration includes: + * Enable / Disable module. + * Afterpay Merchant ID. + * Afterpay Merchant Key. + * API Mode. + +#### Afterpay configuration in Prestashop Back Office +- Afterpay module introduces transaction and validation logging into the PrestaShop Back Office log. +- Afterpay logging includes: + * Afterpay transaction result - Approved. + * Afterpay transaction result - Declined. + * Validation of Merchant ID & Merchant Key combination. \ No newline at end of file diff --git a/afterpay.zip b/afterpay.zip new file mode 100644 index 0000000..3e92607 Binary files /dev/null and b/afterpay.zip differ diff --git a/afterpay/AfterpaySDK/CHANGELOG.MD b/afterpay/AfterpaySDK/CHANGELOG.MD new file mode 100644 index 0000000..e69de29 diff --git a/afterpay/AfterpaySDK/README.MD b/afterpay/AfterpaySDK/README.MD new file mode 100644 index 0000000..122f075 --- /dev/null +++ b/afterpay/AfterpaySDK/README.MD @@ -0,0 +1,48 @@ +# Afterpay SDK for PHP + + +__Welcome to Afterpay PHP SDK V1.0__. This repository contains Afterpay PHP SDK Code, documentation and samples to use merchant APi V1 + + +## SDK Documentation + +[ Our Afterpay-PHP-SDK Page ](https://tngith-sup.tafmo.net/Touch/paylater-php.git) includes all the documentation related to PHP SDK. Everything from Documentation, Sample Codes, to Releases. Here are few quick links to get you there faster. + +* [ Afterpay-PHP-SDK Home Page ](https://tngith-sup.tafmo.net/Touch/paylater-php.git) +* [ Samples ](https://tngith-sup.tafmo.net/Touch/paylater-php.git) +* [ Installation ](https://tngith-sup.tafmo.net/Touch/paylater-php.git) +* [ Make your First SDK Call](https://tngith-sup.tafmo.net/Touch/paylater-php.git) +* [ Afterpay Developer Docs] (https://tngith-sup.tafmo.net/Touch/paylater-php.git) + +## Latest Updates + +- SDK v1.0 allows you to use Afterpay Merchant API V1 endpoints. +- Starting from configuration API call, Order, Payment and Refund API calls are very easy to make. +- It includes sample code for all API calls to make it easy to use. + + +## Prerequisites + + - PHP 7.1 + - PHPUnit 6.0 + - [curl](http://php.net/manual/en/book.curl.php) & [json](http://php.net/manual/en/book.json.php) extensions must be enabled + + + +## Installation and Activation + +This section outlines the steps to install the Afterpay PHP SDK. + +If you are upgrading to a new version of the Afterpay SDK, it is always a good practice to backup your existing SDK folder before you commence the installation steps. + +1. Download a ZIP archive of this repository by clicking the "Clone or download" dropdown button, then "Download ZIP". +2. Go to AfterpayConfig.php file in Afterpay/Core folder to set all API constants. Mainly need to change MERCHANT_ID and MERCHANT_SECRET_KEY. +3. Change the API end points based on production or sandbox enviornment. +3. Follow SampleCode directory to see how to call Config, Create Order, Payment Capture and Refund API's. +4. Use SampleCode/SamplePreAuth to retrieves a list of payment configuration that includes payment types and valid payment ranges. +5. Use SampleCode/SampleCreateOrder to create an order that is used to initiate the afterpay payment process. +6. Use SampleCode/SampleGetOrder to retrieves an individual order by token. +7. Use SampleCode/SampleCapturePayment to perform a direct payment capture and is the equivalent of capturing a credit card. +8. Use SampleCode/SampleProcessRefund to perform a full or partial refund. + + diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Address.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Address.php new file mode 100644 index 0000000..86e83f4 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Address.php @@ -0,0 +1,247 @@ +setName($address['name']); + $this->setLine1($address['line1']); + $this->setLine2($address['line2']); + $this->setPostcode($address['postcode']); + $this->setState($address['state']); + $this->setSuburb($address['suburb']); + $this->setCountryCode($address['countryCode']); + $this->setPhoneNumber($address['phoneNumber']); + + } + /** + * Name of the customer at this address. + * + * @param string $name + * + * @return $this + */ + protected function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * Name of the customer at this address. + * + * @return string + */ + protected function getName() + { + return $this->name; + } + /** + * Line 1 of the Address (eg. number, street, etc). + * + * @param string $line1 + * + * @return $this + */ + protected function setLine1($line1) + { + $this->line1 = $line1; + return $this; + } + /** + * Line 1 of the Address (eg. number, street, etc). + * + * @return string + */ + protected function getLine1() + { + return $this->line1; + } + /** + * Line 2 of the Address (eg. suite, apt #, etc.). + * + * @param string $line2 + * + * @return $this + */ + protected function setLine2($line2) + { + $this->line2 = $line2; + return $this; + } + /** + * Line 2 of the Address (eg. suite, apt #, etc.). + * + * @return string + */ + protected function getLine2() + { + return $this->line2; + } + /** + * Post Code. + * + * @param string $postcode + * + * @return $this + */ + protected function setPostcode($postcode) + { + $this->postcode = $postcode; + return $this; + } + /** + * Post Code. + * + * @return string + */ + protected function getPostcode() + { + return $this->postcode; + } + /** + * State Code. + * + * @param string $state + * + * @return $this + */ + protected function setState($state) + { + $this->state = $state; + return $this; + } + /** + * State Code. + * + * @return string + */ + protected function getState() + { + return $this->state; + } + /** + * Suburb. + * + * @param string $suburb + * + * @return $this + */ + protected function setSuburb($suburb) + { + $this->suburb = $suburb; + return $this; + } + /** + * Suburb. + * + * @return string + */ + protected function getSuburb() + { + return $this->suburb; + } + /** + * Country Code. + * + * @param string $countryCode + * + * @return $this + */ + protected function setCountryCode($countryCode) + { + $this->countryCode = $countryCode; + return $this; + } + /** + * Country Code. + * + * @return string + */ + protected function getCountryCode() + { + return $this->countryCode; + } + /** + * Customer phone number + * + * @param string $phoneNumber + * + * @return $this + */ + protected function setPhoneNumber($phoneNumber) + { + $this->phoneNumber = $phoneNumber; + return $this; + } + + /** + * Customer phone number + * + * @return string + */ + protected function getPhoneNumber() + { + return $this->phoneNumber; + } +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Amount.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Amount.php new file mode 100644 index 0000000..9079006 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Amount.php @@ -0,0 +1,99 @@ +setAmount($amount); + $this->setCurrency($currency); + } + /* + * Currency code + * + * @param string $currency. 3-letter currency code. Only "AUD" is supported + * + * @return $this + */ + protected function setCurrency($currency) + { + $this->currency = $currency; + return $this; + } + /* + * Currency code + * + * @return $this + */ + protected function getCurrency() + { + return $this->currency; + } + /* + * Order Amount + * + * @param string $amount. + * + * @return $this + */ + protected function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + /* + * Order Amount + * + * @return $this + */ + protected function getAmount() + { + return $this->amount; + } + /** + * Check if all property values are assigned and correct + * Need to validate amount and currency + * + * Throw Exception if validation fails + * @return null + */ + protected function validatePrice() + { + foreach ($this as $key => $value) + { + PriceValidator::validate($key,$value); + } + return null; + } + +} + diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Authorization.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Authorization.php new file mode 100644 index 0000000..f7d236a --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Authorization.php @@ -0,0 +1,32 @@ +callAuthorizationApi(); + return $preAuthApiResponse; + + } +} diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/BillingAddress.php b/afterpay/AfterpaySDK/code/Afterpay/Api/BillingAddress.php new file mode 100644 index 0000000..448cc15 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/BillingAddress.php @@ -0,0 +1,42 @@ + $value) + { + StringValidator::validate($key,$value); + } + return null; + } + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/CapturePayment.php b/afterpay/AfterpaySDK/code/Afterpay/Api/CapturePayment.php new file mode 100644 index 0000000..d144510 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/CapturePayment.php @@ -0,0 +1,48 @@ +call = new Call( $input ); + } + + /* Process Capture Payment + * + * @param Array Create Order Response + * @param String Merchant Reference Id + * + * @return Capture Payment API Response + */ + public function processCapturePayment($apiResponse,$merchantReference = NULL) + { + $paymentObj = array('token' => $apiResponse['orderToken'],'merchantReference' => $merchantReference); + + $paymentApiResponse = $this->call->callCapturePaymentApi($paymentObj); + return $paymentApiResponse; + } +} diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Consumer.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Consumer.php new file mode 100644 index 0000000..5fdc376 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Consumer.php @@ -0,0 +1,153 @@ +setPhoneNumber($consumer['phoneNumber']); + $this->setEmail($consumer['email']); + $this->setGivenNames($consumer['givenName']); + $this->setSurname($consumer['surName']); + } + /** + * Email address representing the consumer. + * + * @param string $email + * + * @return $this + */ + protected function setEmail($email) + { + $this->email = $email; + return $this; + } + /** + * Email address representing the consumer. + * + * @return string + */ + protected function getEmail() + { + return $this->email; + } + /** + * Given name of the consumer. + * + * @param string $givenNames + * + * @return $this + */ + protected function setGivenNames($givenNames) + { + $this->givenNames = $givenNames; + return $this; + } + + /** + * Given name of the consumer. + * + * @return string + */ + protected function getGivenNames() + { + return $this->givenNames; + } + /** + * Surname of the consumer. + * + * @param string $surname + * + * @return $this + */ + protected function setSurname($surname) + { + $this->surname = $surname; + return $this; + } + + /** + * Surname name of the consumer. + * + * @return string + */ + protected function getSurname() + { + return $this->surname; + } + /** + * Phone number representing the consumer. + * + * @param string $phoneNumber + * + * @return $this + */ + protected function setPhoneNumber($phoneNumber) + { + $this->phoneNumber = $phoneNumber; + return $this; + } + /** + * Consumer Phone Number + * + * @return string + */ + protected function getPhoneNumber() + { + return $this->phoneNumber; + } + /** + * + * Validate email and surname. + * + * Throw Exception when validation fails + * + * @return null + */ + public function validateConsumer() + { + foreach ($this as $key => $value) + { + StringValidator::validate($key,$value); + } + return null; + } +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/CreateOrder.php b/afterpay/AfterpaySDK/code/Afterpay/Api/CreateOrder.php new file mode 100644 index 0000000..0495151 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/CreateOrder.php @@ -0,0 +1,61 @@ +call = new Call( $input ); + } + + /** + * Call Create order API + * + * Throw Exception if error occurs + * If token generated, redirect to customer login screen + * + */ + public function processOrder($transaction) + { + //Call API execute function. + $orderApiResponse = $this->call->callCreateOrderApi($transaction); + + //If Token creation is successful, redirect user to Afterpay Lightbox. + if(!$orderApiResponse) + { + throw new AfterpayConfigurationException("Something went wrong in connection"); + }else{ + $redirectURL = $this->call->callRedirect($orderApiResponse); + header('Location: '.$redirectURL); + } + exit; + + } + +} diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Discount.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Discount.php new file mode 100644 index 0000000..0a53db8 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Discount.php @@ -0,0 +1,86 @@ +setDisplayName($name); + $this->setAmount($price); + } + /** + * Display name for the Discount + * + * @param string $displayName + * + * @return $this + */ + public function setDisplayName($displayName) + { + $this->displayName = $displayName; + return $this; + } + /** + * Display name for the Discount + * + * @return string + */ + public function getDisplayName() + { + return $this->displayName; + } + /** + * Discount Amount + * + * @param \Afterpay\Api\Amount $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + /** + * Discount Amount + * + * @return \Afterpay\Api\Amount + */ + public function getAmount() + { + return $this->amount; + } + /** + * + * Validate displayName + * Throw Exception if fails + * + * @return null + */ + public function validateDiscounts() + { + foreach ($this as $key => $value) + { + StringValidator::validate($key,$value); + } + return null; + } + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Item.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Item.php new file mode 100644 index 0000000..70cd441 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Item.php @@ -0,0 +1,157 @@ +setName($name); + $this->setSku($sku); + $this->setQuantity($quantity); + $this->setPrice($priceObj); + + } + /** + * Stock keeping unit corresponding (SKU) to item. + * + * @param string $sku + * + * @return $this + */ + protected function setSku($sku) + { + $this->sku = $sku; + return $this; + } + /** + * Stock keeping unit corresponding (SKU) to item. + * + * @return string + */ + protected function getSku() + { + return $this->sku; + } + /** + * Item name. + * + * @param string $name + * + * @return $this + */ + protected function setName($name) + { + $this->name = $name; + return $this; + } + /** + * Item name. + * + * @return string + */ + protected function getName() + { + return $this->name; + } + /** + * Number of a particular item. + * + * @param string $quantity + * + * @return $this + */ + protected function setQuantity($quantity) + { + $this->quantity = $quantity; + return $this; + } + /** + * Number of a particular item. + * + * @return string + */ + protected function getQuantity() + { + return $this->quantity; + } + /** + * Item cost + * + * @param \Afterpay\Api\Amount $price + * + * @return $this + */ + protected function setPrice($price) + { + $this->price = $price; + return $this; + } + /** + * Item cost + * + * @return \Afterpay\Api\Amount + */ + protected function getPrice() + { + return $this->price; + } + /** + * + * Validate name and quantity + * + * Throw Exception if fails + * + * @return null + */ + public function validateItem() + { + foreach ($this as $key => $value) + { + StringValidator::validate($key,$value); + } + return null; + } + + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/ProcessRefund.php b/afterpay/AfterpaySDK/code/Afterpay/Api/ProcessRefund.php new file mode 100644 index 0000000..3c1727f --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/ProcessRefund.php @@ -0,0 +1,57 @@ +call = new Call( $input ); + } + + public function processOrderRefund($paymentId,$amount) + { + $refundApiResponse = $this->call->callCreateRefundApi($paymentId, array("amount" => $amount) ); + return $refundApiResponse; + } + /** + * Amount being collected. + * + * @param \Afterpay\Api\Amount $refundAmount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + /** + * Amount being collected. + * + * @return \Afterpay\Api\Amount + */ + public function getAmount() + { + return $this->amount; + } +} diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/RedirectUrls.php b/afterpay/AfterpaySDK/code/Afterpay/Api/RedirectUrls.php new file mode 100644 index 0000000..da4650e --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/RedirectUrls.php @@ -0,0 +1,97 @@ +setRedirectConfirmUrl($confirmUrl); + $this->setRedirectCancelUrl($cancelUrl); + + } + /** + * Url where the consumer would be redirected to after approving the payment. + * + * @param string redirectConfirmUrl + * @throws \InvalidArgumentException + * @return $this + */ + protected function setRedirectConfirmUrl($redirectConfirmUrl) + { + $this->redirectConfirmUrl = $redirectConfirmUrl; + return $this; + } + /* Url where the consumer would be redirected to after approving the payment. + * + * @return string + */ + protected function getRedirectConfirmUrl() + { + return $this->redirectConfirmUrl; + } + /** + * Url where the consumer would be redirected to after canceling the payment. + * + * @param string $redirectCancelUrl + * @throws \InvalidArgumentException + * @return $this + */ + protected function setRedirectCancelUrl($redirectCancelUrl) + { + $this->redirectCancelUrl = $redirectCancelUrl; + return $this; + } + /** + * Url where the consumer would be redirected to after canceling the payment. + * + * @return string + */ + protected function getRedirectCancelUrl() + { + return $this->redirectCancelUrl; + } + /** + * Validate confirm URL and Cancel URL + * Throw Exception if fails + * + * @return null + */ + public function validateRedirectUrl() + { + foreach ($this as $key => $value) + { + StringValidator::validate($key,$value); + } + return null; + } + +} diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/ShippingAddress.php b/afterpay/AfterpaySDK/code/Afterpay/Api/ShippingAddress.php new file mode 100644 index 0000000..8b77615 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/ShippingAddress.php @@ -0,0 +1,41 @@ + $value) + { + StringValidator::validate($key,$value); + } + return null; + } + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/ShippingCourier.php b/afterpay/AfterpaySDK/code/Afterpay/Api/ShippingCourier.php new file mode 100644 index 0000000..8daf8d4 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/ShippingCourier.php @@ -0,0 +1,116 @@ +setName($name); + $this->setPriority($priority); + } + /** + * Date by when it should be shipped + * + * @param string $shippedAt + * + * @return $this + */ + protected function setShippedAt($shippedAt) + { + $this->shippedAt = $shippedAt; + return $this; + } + /** + * Date by when it should be shipped + * + * @return string + */ + protected function getShippedAt() + { + return $this->ShippedAt; + } + /** + * Name of the courier service + * + * @param string $name + * + * @return $this + */ + protected function setName($name) + { + $this->name = $name; + return $this; + } + /** + * Name of the courier service + * + * @return string + */ + protected function getName() + { + return $this->name; + } + /** + * Tracking Id of Courier Service + * + * @param string $tracking + * + * @return $this + */ + protected function setTracking($tracking) + { + $this->tracking = $tracking; + return $this; + } + /** + * Tracking Id of Courier Service + * + * @return string + */ + protected function getTracking() + { + return $this->tracking; + } + /** + * Priority of Courier Service + * + * @param string $priority + * + * @return $this + */ + protected function setPriority($priority) + { + $this->priority = $priority; + return $this; + } + /** + * Priority of Courier Service + * @return string + */ + protected function getPriority() + { + return $this->priority; + } +} diff --git a/afterpay/AfterpaySDK/code/Afterpay/Api/Transaction.php b/afterpay/AfterpaySDK/code/Afterpay/Api/Transaction.php new file mode 100644 index 0000000..e622ac6 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Api/Transaction.php @@ -0,0 +1,244 @@ +totalAmount = $totalAmount; + return $this; + } + /** + * Amount being collected. + * + * @return \Afterpay\Api\Amount + */ + public function getTotalAmount() + { + return $this->totalAmount; + } + /** + * Consumer details + * + * @param \Afterpay\Api\Consumer $consumer + * + * @return $this + */ + public function setConsumer($consumer) + { + $this->consumer = $consumer; + return $this; + } + /** + * Consumer details + * + * @return \Afterpay\Api\Consumer + */ + public function getConsumer() + { + return $this->consumer; + } + /** + * Consumer billing details + * + * @param \Afterpay\Api\BillingAddress $billing + * + * @return $this + */ + public function setBilling($billing) + { + $this->billing = $billing; + return $this; + } + /** + * Consumer billing details + * + * @return \Afterpay\Api\BillingAddress + */ + public function getBilling() + { + return $this->billing; + } + /** + * Consumer shipping details + * + * @param \Afterpay\Api\ShippingAddress $shipping + * + * @return $this + */ + public function setShipping($shipping) + { + $this->shipping = $shipping; + return $this; + } + /** + * Consumer shipping details + * + * @return \Afterpay\Api\ShippingAddress + */ + public function getShipping() + { + return $this->shipping; + } + /** + * Courier details + * + * @param \Afterpay\Api\ShippingCourier $courier + * + * @return $this + */ + public function setCourier($courier) + { + $this->courier = $courier; + return $this; + } + /** + * Courier details + * + * @return \Afterpay\Api\ShippingCourier + */ + public function getCourier() + { + return $this->courier; + } + /** + * List of order items + * + * @param \Afterpay\Api\Item $items + * + * @return $this + */ + public function setItems($items) + { + $this->items = $items; + return $this; + } + + /** + * List of order items + * + * @return \Afterpay\Api\Item + */ + public function getItems() + { + return $this->items; + } + /** + * List of discounts + * + * @param \Afterpay\Api\Discount $discounts + * + * @return $this + */ + public function setDiscounts($discounts) + { + $this->discounts = $discounts; + return $this; + } + /** + * List of discounts + * + * @return \Afterpay\Api\Discount + */ + public function getDiscounts() + { + return $this->discounts; + } + /** + * Tax Amount being collected. + * + * @param \Afterpay\Api\Amount $taxAmount + * + * @return $this + */ + public function setTaxAmount($taxAmount) + { + $this->taxAmount = $taxAmount; + return $this; + } + /** + * Tax Amount being collected. + * + * @return \Afterpay\Api\Amount + */ + public function getTaxAmount() + { + return $this->taxAmount; + } + /** + * Shipping Amount being collected. + * + * @param \Afterpay\Api\Amount $shippingAmount + * + * @return $this + */ + public function setShippingAmount($shippingAmount) + { + $this->shippingAmount = $shippingAmount; + return $this; + } + /** + * Tax Amount being collected. + * + * @return \Afterpay\Api\Amount + */ + public function getShippingAmount() + { + return $this->shippingAmount; + } + /** + * Get Merchant Redirect URL's + * + * @param \Afterpay\Api\RedirectUrls $merchant + * + * @return $this + */ + public function setMerchantUrl($merchant) + { + $this->merchant = $merchant; + return $this; + } + /** + * Tax Amount being collected. + * + * @return \Afterpay\Api\RedirectUrls + */ + public function getMerchantUrl() + { + return $this->merchant; + } + /** + * Get Merchant reference Id merchantReference + * + * @return $this + */ + public function setMerchantReference($merchantReference) + { + $this->merchantReference = $merchantReference; + return $this; + } + /** + * Tax Amount being collected. + * + * @return string + */ + public function getMerchantReference() + { + return $this->merchantReference; + } + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Core/AfterpayConfig.php b/afterpay/AfterpaySDK/code/Afterpay/Core/AfterpayConfig.php new file mode 100644 index 0000000..1673381 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Core/AfterpayConfig.php @@ -0,0 +1,403 @@ +validateConfigFile($filename); + + //If Config.ini is valid and all values are set properly. + if ($validateConfigResponse) + { + //Set Config params, if mode is sandbox or production. + $ini_array = parse_ini_file($filename, true); + $this->setConfigParams($ini_array); + } + else + { + echo "Please check if config.ini exists and all values are set properly. Please make sure mode should be either sandbox or production"; + exit; + } + + $this->setEnvironment($ini_array['Service']['mode']); + } + else { + + if( !empty($input['mode']) ) { + $this->setMode($input['mode']); + } + + if( !empty($input['merchantId']) ) { + $this->setMerchantId($input['merchantId']); + } + + if( !empty($input['merchantSecret']) ) { + $this->setMerchantSecret($input['merchantSecret']); + } + + if( !empty($input['mode']) ) { + $this->setEnvironment($input['mode']); + } + + if( !empty($input['sdkName']) ) { + $this->setSDKName($input['sdkName']); + } + + if( !empty($input['sdkVersion']) ) { + $this->setSDKVersion($input['sdkVersion']); + } + } + } + + /* + * Validate config.ini array and values + * params config.ini file name $fileName + * Returns boolean + */ + protected function validateConfigFile($fileName) + { + //Check if config.ini file exists in the root directory + if (!file_exists($fileName)) + { + return false; + } + //Parse config.ini file to set configuration variables. + $ini_array = parse_ini_file($fileName, true); + + //Check if Service mode exists. Can be either sandbox or production. + if(!array_key_exists("Service",$ini_array)) + { + return false; + } + //Check if Service is not sandbox or production + if($ini_array['Service']['mode'] != "sandbox" && $ini_array['Service']['mode'] != "production") + { + return false; + } + //Check if Account Key exists + if(!array_key_exists("Account",$ini_array)) + { + return false; + } + //Check if Merchant Id is blank + if($ini_array['Account']['MerchantId'] == '') + { + return false; + } + //Check if Merchant Secret is blank + if($ini_array['Account']['MerchantSecret'] == '') + { + return false; + } + //If all validations are correct, return true + return true; + } + + /** + * Set Afterpay URL's based on the selected mode (sandbox or production) + */ + protected function setConfigParams($configArray) + { + //Set Merchant Id, Secret Key and Callback Url + $this->setMerchantId($configArray['Account']['MerchantId']); + $this->setMerchantSecret($configArray['Account']['MerchantSecret']); + $this->setSDKName('Afterpay-PHP-SDK'); + $this->setSDKVersion('1.0.1'); + $this->setCallbackUrl($configArray['Account']['CallbackUrl']); + } + + /** + * + */ + protected function setEnvironment($mode) + { + //Set Merchant Id, Secret Key and Callback Url + if($mode == 'sandbox') + { + $this->setConfigUrl('https://api-sandbox.afterpay.com/v1/configuration'); + $this->setOrderUrl('https://api-sandbox.afterpay.com/v1/orders'); + $this->setCheckoutUrl('https://portal-sandbox.afterpay.com/checkout?token='); + $this->setPaymentUrl('https://api-sandbox.afterpay.com/v1/payments/capture'); + $this->setRefundUrl('https://api-sandbox.afterpay.com/v1/payments'); + + } + else if($mode == 'production') + { + $this->setConfigUrl('https://api.afterpay.com/v1/configuration'); + $this->setOrderUrl('https://api.afterpay.com/v1/orders'); + $this->setCheckoutUrl('https://portal.afterpay.com/checkout?token='); + $this->setPaymentUrl('https://api.afterpay.com/v1/payments/capture'); + $this->setRefundUrl('https://api.afterpay.com/v1/payments'); + + } + + return $this; + } + + /** + * Name of the SDK + * + * @param string $sdkName + * + * @return $this + */ + protected function setSDKName($sdkName) + { + $this->sdkName = $sdkName; + return $this; + } + + /** + * Name of the SDK + * + * @return string + */ + public function getSDKName() + { + return $this->sdkName; + } + /** + * Version of the SDK + * + * @param string $sdkName + * + * @return $this + */ + protected function setSDKVersion($sdkVersion) + { + $this->sdkVersion = $sdkVersion; + return $this; + } + /** + * Version of the SDK + * + * @return string + */ + public function getSDKVersion() + { + return $this->sdkVersion; + } + /** + * Merchant Id (Sandbox or Production) + * + * @param string $merchantId + * + * @return $this + */ + protected function setMerchantId($merchantId) + { + $this->merchantId = $merchantId; + return $this; + } + /** + * Merchant Id + * + * @return string + */ + public function getMerchantId() + { + return $this->merchantId; + } + /** + * Merchant Secret Key (Sandbox or Production) + * + * @param string $merchantKey + * + * @return $this + */ + protected function setMerchantSecret($merchantSecret) + { + $this->merchantSecret = $merchantSecret; + return $this; + } + /** + * Merchant Secret Key + * + * @return string + */ + public function getMerchantSecret() + { + return $this->merchantSecret; + } + /** + * Config URL (Sandbox or Production) + * + * @param string $configUrl + * + * @return $this + */ + protected function setConfigUrl($configUrl) + { + $this->configUrl = $configUrl; + return $this; + } + /** + * Config URL + * + * @return string + */ + public function getConfigUrl() + { + return $this->configUrl; + } + /** + * Order URL (Sandbox or Production) + * + * @param string $orderUrl + * + * @return $this + */ + protected function setOrderUrl($orderUrl) + { + $this->orderUrl = $orderUrl; + return $this; + } + /** + * API Mode + * + * @return string + */ + public function setMode($mode) + { + $this->mode = $mode; + return $this; + } + + /** + * Order URL + * + * @return string + */ + public function getOrderUrl() + { + return $this->orderUrl; + } + /** + * Checkout URL (Sandbox or Production) + * + * @param string $checkoutUrl + * + * @return $this + */ + protected function setCheckoutUrl($checkoutUrl) + { + $this->checkoutUrl = $checkoutUrl; + return $this; + } + /** + * Checkout URL + * + * @return string + */ + public function getCheckoutUrl() + { + return $this->checkoutUrl; + } + /** + * Payment URL (Sandbox or Production) + * + * @param string $paymentUrl + * + * @return $this + */ + protected function setPaymentUrl($paymentUrl) + { + $this->paymentUrl = $paymentUrl; + return $this; + } + /** + * Payment URL + * + * @return string + */ + public function getPaymentUrl() + { + return $this->paymentUrl; + } + /** + * Refund URL (Sandbox or Production) + * + * @param string $refundUrl + * + * @return $this + */ + protected function setRefundUrl($refundUrl) + { + $this->refundUrl = $refundUrl; + return $this; + } + /** + * Refund URL + * + * @return string + */ + public function getRefundUrl() + { + return $this->refundUrl; + } + + /** + * API Mode + * + * @return string + */ + public function getMode() + { + return $this->mode; + } + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Core/Call.php b/afterpay/AfterpaySDK/code/Afterpay/Core/Call.php new file mode 100644 index 0000000..676281d --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Core/Call.php @@ -0,0 +1,220 @@ +apiConfigObj = new AfterpayConfig( $input ); + $this->merchantId = $this->apiConfigObj->getMerchantId(); + $this->merchantSecretKey = $this->apiConfigObj->getMerchantSecret(); + } + + /** + * Function to call Config API + * @return Array Api Response + * + */ + public function callAuthorizationApi() + { + + $curlURL = $this->apiConfigObj->getConfigUrl(); + $curlResponse = $this->execute($curlURL,'GET'); + return $curlResponse; + } + + /** + * Function to call Create Order API + * @return Array Api Response + * + */ + public function callCreateOrderApi($orderObject) + { + $curlURL = $this->apiConfigObj->getOrderUrl(); + $curlResponse = $this->execute($curlURL,'POST',$orderObject); + return $curlResponse; + } + + /** + * Function to call Get Order API + * @param Order Token + * @return Array Api Response + * + */ + public function callGetOrderApi($orderToken) + { + $curlURL = $this->apiConfigObj->getOrderUrl(); + + //Pass Afterpay Order Token + $curlURL = $curlURL."/".$orderToken; + $curlResponse = $this->execute($curlURL,'GET'); + return $curlResponse; + } + + /** + * Function to call Capture Payment API + * @return Array Api Response + * + */ + public function callCapturePaymentApi($paymentObject) + { + $curlURL = $this->apiConfigObj->getPaymentUrl(); + $curlResponse = $this->execute($curlURL,'POST',$paymentObject); + return $curlResponse; + } + + /** + * Function to call process create refund + * @return Array Api Response + * + */ + public function callCreateRefundApi($paymentId,$refundObj) + { + + $curlURL = $this->apiConfigObj->getRefundUrl(); + + $curlURL = $curlURL."/".$paymentId."/refund"; + + $curlResponse = $this->execute($curlURL,'POST',$refundObj); + return $curlResponse; + } + + /** + * Execute API Request + * @param string $curlURL + * @param string $curlMethod + * @param Object $dataObject + * @throws AfterpayConfigurationException + * + * @return array + */ + + Protected function execute($curlURL,$curlMethod,$dataObject ='') + { + //Check if CURL module exists. + if (!function_exists("curl_init")) { + throw new AfterpayConfigurationException("Curl module is not available on this system"); + } + try { + //Curl Implementation + + // create a new cURL resource + $ch = curl_init(); + + //Call fucntion to create CURL Headers + + $curlHeaders = $this->createHeaders(); + + //Call CURL URL + curl_setopt($ch, CURLOPT_URL, $curlURL); + curl_setopt($ch, CURLOPT_TIMEOUT,80); // Set timeout to 80s + curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders); //Pass CURL HEADERS + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //Do not output response on screen + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $curlMethod); + if($dataObject != ''){ + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataObject, JSON_UNESCAPED_SLASHES)); + } + + // grab URL and pass it to the browser + $curlResponse = curl_exec($ch); + $curlResponse = json_decode($curlResponse); + + if( empty($curlResponse) ) { + throw new AfterpayConfigurationException("Invalid Response from Afterpay API"); + } + + // close cURL resource, and free up system resources + curl_close($ch); + + return $curlResponse; + } + catch (Exception $e) { + throw new AfterpayConfigurationException("Something went wrong in Afterpay API Connection"); + + } + + } + + /** + * Create CURL Headers + * @throws AfterpayConfigurationException + * + * @return array + */ + + Private function createHeaders($customHeaders = "") + { + $headers = array( + 'Content-Type:application/json', + 'Authorization: Basic '. base64_encode($this->merchantId.':'.$this->merchantSecretKey), + 'User-Agent: '.$this->apiConfigObj->getSDKName().' ; '.$this->apiConfigObj->getSDKVersion() .'; PHP: '.phpversion().';'.$customHeaders + ); + return $headers; + } + + /** + * Redirect to Afterpay Portal + * + * @param Object CreateOrder API Response + * @throws AfterpayConfigurationException + * + * @return string Redirect URL + */ + + Public function callRedirect($orderApiResponse) + { + //Check if Order Token exists + if ( empty($orderApiResponse->token) || !$orderApiResponse->token ) { + if( !empty($orderApiResponse->message) ) { + throw new AfterpayConfigurationException( $orderApiResponse->message . ": " . $orderApiResponse->errorCode. " (" . $orderApiResponse->errorId . ") " ); + } + else { + throw new AfterpayConfigurationException( "Connection Error" ); + } + } + $redirectURL = $this->apiConfigObj->getCheckoutUrl(); + //echo $redirectURL; echo $this->apiConfigObj->getCallbackUrl();exit; + $redirectURL = $redirectURL.$orderApiResponse->token.'&redirected=1'; + + return $redirectURL; + } + +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Exception/AfterpayConfigurationException.php b/afterpay/AfterpaySDK/code/Afterpay/Exception/AfterpayConfigurationException.php new file mode 100644 index 0000000..b82a85e --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Exception/AfterpayConfigurationException.php @@ -0,0 +1,24 @@ +totalAmount->amount == $currentCartTotal) + { + return true; + } + else + { + return false; + } + } +} \ No newline at end of file diff --git a/afterpay/AfterpaySDK/code/Afterpay/Validation/StringValidator.php b/afterpay/AfterpaySDK/code/Afterpay/Validation/StringValidator.php new file mode 100644 index 0000000..fa55283 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Afterpay/Validation/StringValidator.php @@ -0,0 +1,82 @@ + + + + + + Class Afterpay\Api\Address + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Amount.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Amount.html new file mode 100644 index 0000000..e08f901 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Amount.html @@ -0,0 +1,122 @@ + + + + + + + Class Afterpay\Api\Amount + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Authorization.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Authorization.html new file mode 100644 index 0000000..d3a8b61 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Authorization.html @@ -0,0 +1,59 @@ + + + + + + + Class Afterpay\Api\Authorization + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.BillingAddress.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.BillingAddress.html new file mode 100644 index 0000000..59e818a --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.BillingAddress.html @@ -0,0 +1,79 @@ + + + + + + + Class Afterpay\Api\BillingAddress + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.CapturePayment.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.CapturePayment.html new file mode 100644 index 0000000..87f1357 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.CapturePayment.html @@ -0,0 +1,62 @@ + + + + + + + Class Afterpay\Api\CapturePaymant + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Consumer.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Consumer.html new file mode 100644 index 0000000..2d87cd8 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Consumer.html @@ -0,0 +1,165 @@ + + + + + + + Class Afterpay\Api\Consumer + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.CreateOrder.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.CreateOrder.html new file mode 100644 index 0000000..e4b5794 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.CreateOrder.html @@ -0,0 +1,73 @@ + + + + + + + Class Afterpay\Api\CreateOrder + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Discount.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Discount.html new file mode 100644 index 0000000..9ee1cc6 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Discount.html @@ -0,0 +1,120 @@ + + + + + + + Class Afterpay\Api\Discount + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Item.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Item.html new file mode 100644 index 0000000..ad7e070 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Item.html @@ -0,0 +1,182 @@ + + + + + + + Class Afterpay\Api\Item + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ProcessRefund.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ProcessRefund.html new file mode 100644 index 0000000..06451a7 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ProcessRefund.html @@ -0,0 +1,90 @@ + + + + + + + Class Afterpay\Api\ProcessRefund + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.RedirectUrls.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.RedirectUrls.html new file mode 100644 index 0000000..75c3606 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.RedirectUrls.html @@ -0,0 +1,117 @@ + + + + + + + Class Afterpay\Api\RedirectUrls + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ShippingAddress.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ShippingAddress.html new file mode 100644 index 0000000..88b19e6 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ShippingAddress.html @@ -0,0 +1,79 @@ + + + + + + + Class Afterpay\Api\ShippingAddress + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ShippingCourier.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ShippingCourier.html new file mode 100644 index 0000000..3caf60f --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.ShippingCourier.html @@ -0,0 +1,165 @@ + + + + + + + Class Afterpay\Api\ShippingCourier + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Transaction.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Transaction.html new file mode 100644 index 0000000..7188f9d --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Api.Transaction.html @@ -0,0 +1,365 @@ + + + + + + + Class Afterpay\Api\Transaction + + + + + + + +
+ + + + diff --git a/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Core.AfterpayConfig.html b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Core.AfterpayConfig.html new file mode 100644 index 0000000..bff7f08 --- /dev/null +++ b/afterpay/AfterpaySDK/code/Docs/class-Afterpay.Core.AfterpayConfig.html @@ -0,0 +1,70 @@ + + + + + + + Class Afterpay\Core\AfterpayConfig + + + + + + + +
+ +