File manager - Edit - /home/premiey/www/wp-includes/images/media/omnipay.tar
Back
mollie/phpunit.xml.dist 0000666 00000001230 15165413756 0011215 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false"> <testsuites> <testsuite name="Omnipay Test Suite"> <directory>./tests/</directory> </testsuite> </testsuites> <filter> <whitelist> <directory>./src</directory> </whitelist> </filter> </phpunit> mollie/README.md 0000666 00000014527 15165413756 0007336 0 ustar 00 # Omnipay: Mollie **Mollie driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-mollie) [](https://packagist.org/packages/omnipay/mollie) [](https://packagist.org/packages/omnipay/mollie) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP. This package implements Mollie support for Omnipay. ## Installation Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/mollie` with Composer: ``` composer require league/omnipay omnipay/mollie ``` ## Basic Usage The following gateways are provided by this package: * Mollie For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. ### Basic purchase example ```php $gateway = \Omnipay\Omnipay::create('Mollie'); $gateway->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); $response = $gateway->purchase( [ "amount" => "10.00", "currency" => "EUR", "description" => "My first Payment", "returnUrl" => "https://webshop.example.org/mollie-return.php" ] )->send(); // Process response if ($response->isSuccessful()) { // Payment was successful print_r($response); } elseif ($response->isRedirect()) { // Redirect to offsite payment gateway $response->redirect(); } else { // Payment failed echo $response->getMessage(); } ``` ### Example using the Order API 1. Create the order and pass the order items in the parameters. ```php $response = $gateway->createOrder( [ 'amount' => '1027.99', 'currency' => 'EUR', 'orderNumber' => '1337', 'lines' => [ [ 'type' => 'physical', 'sku' => '5702016116977', 'name' => 'LEGO 42083 Bugatti Chiron', 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', 'quantity' => 2, 'vatRate' => '21.00', 'unitPrice' => '399.00', 'totalAmount' => '698.00', 'discountAmount' => '100.00', 'vatAmount' => '121.14', ], [ 'type' => 'physical', 'sku' => '5702015594028', 'name' => 'LEGO 42056 Porsche 911 GT3 RS', 'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', 'quantity' => 1, 'vatRate' => '21.00', 'unitPrice' => '329.99', 'totalAmount' => '329.99', 'vatAmount' => '57.27', ] ], 'card' => [ 'company' => 'Mollie B.V.', 'email' => 'norris@chucknorrisfacts.net', 'birthday' => '1958-01-31', 'billingTitle' => 'Dhr', 'billingFirstName' => 'Piet', 'billingLastName' => 'Mondriaan', 'billingAddress1' => 'Keizersgracht 313', 'billingCity' => 'Amsterdam', 'billingPostcode' => '1234AB', 'billingState' => 'Noord-Holland', 'billingCountry' => 'NL', 'billingPhone' => '+31208202070', 'shippingTitle' => 'Mr', 'shippingFirstName' => 'Chuck', 'shippingLastName' => 'Norris', 'shippingAddress1' => 'Prinsengracht 313', 'shippingAddress2' => '4th floor', 'shippingCity' => 'Haarlem', 'shippingPostcode' => '5678AB', 'shippingState' => 'Noord-Holland', 'shippingCountry' => 'NL', ], 'metadata' => [ 'order_id' => '1337', 'description' => 'Lego cars', ], 'locale' => 'nl_NL', 'returnUrl' => 'https://example.org/redirect', 'notifyUrl' => 'https://example.org/webhook', 'paymentMethod' => 'klarnapaylater', 'billingEmail' => 'piet@mondriaan.com', ] )->send(); // Process response if ($response->isSuccessful()) { // Payment was successful print_r($response); } elseif ($response->isRedirect()) { // Redirect to offsite payment gateway $response->redirect(); } else { // Payment failed echo $response->getMessage(); } ``` 2. On return/notify, complete the order. This will not always be completed, because for Klarna the shipments needs to be created first. ```php $response = $gateway->completeOrder( [ "transactionReference" => "ord_xxxx", ] )->send(); ``` 3. When shipping the items, create the shipment for this order. You can leave the `items` emtpy to ship all items. ```php $response = $gateway->createShipment( [ "transactionReference" => "ord_xxx", 'items' => [ [ 'id' => 'odl_xxx', 'quantity' => 1, ] ] ] )->send(); ``` 4. As long as the order is `created`, `authorized` or `shipping`, it may be cancelled (voided) ```php $response = $gateway->void(["transactionReference" => "ord_xxx"])->send(); ``` ## Support If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-mollie/issues), or better yet, fork the library and submit a pull request. mollie/composer.json 0000666 00000002726 15165413756 0010577 0 ustar 00 { "name": "omnipay/mollie", "type": "library", "description": "Mollie driver for the Omnipay payment processing library", "keywords": [ "gateway", "merchant", "mollie", "omnipay", "pay", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-mollie", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Barry vd. Heuvel", "email": "barryvdh@gmail.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-mollie/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Mollie\\" : "src/" } }, "autoload-dev": { "psr-4": { "Omnipay\\Mollie\\Test\\": "tests/" } }, "require": { "omnipay/common": "^3.0.1" }, "require-dev": { "omnipay/tests": "^3.1", "squizlabs/php_codesniffer": "^3", "phpro/grumphp": "^0.14", "phpmd/phpmd": "^2", "overtrue/phplint": "^1", "jakub-onderka/php-parallel-lint": "^1" }, "extra": { "branch-alias": { "dev-master": "5.1.x-dev" } }, "scripts": { "test": "phpunit", "check-style": "phpcs -p --standard=PSR2 src/", "fix-style": "phpcbf -p --standard=PSR2 src/" }, "prefer-stable": true } mollie/grumphp.yml 0000666 00000001106 15165413756 0010251 0 ustar 00 parameters: git_dir: . bin_dir: vendor/bin tasks: phpunit: config_file: ~ testsuite: ~ group: [] always_execute: false phpcs: standard: PSR2 warning_severity: ~ ignore_patterns: - tests/ triggered_by: [php] phpmd: exclude: [] ruleset: ['cleancode', 'codesize', 'naming'] triggered_by: ['php'] phplint: exclude: [] triggered_by: ['php', 'phtml', 'php3', 'php4', 'php5'] mollie/src/Item.php 0000666 00000012772 15165413756 0010255 0 ustar 00 <?php namespace Omnipay\Mollie; class Item extends \Omnipay\Common\Item { /** * Check if a Amount object is used, store the value * * @param $key * @param $value * @return $this */ protected function setParameter($key, $value) { if (is_array($value) && isset($value['value'])) { $value = $value['value']; } $this->parameters->set($key, $value); return $this; } public function getId() { return $this->getParameter('id'); } public function setId($value) { return $this->setParameter('id', $value); } public function getUnitPrice() { return $this->getParameter('unitPrice'); } public function setUnitPrice($value) { return $this->setParameter('unitPrice', $value); } public function getDiscountAmount() { return $this->getParameter('discountAmount'); } public function setDiscountAmount($value) { return $this->setParameter('discountAmount', $value); } public function getTotalAmount() { return $this->getParameter('totalAmount'); } public function setTotalAmount($value) { return $this->setParameter('totalAmount', $value); } public function getVatRate() { return $this->getParameter('vatRate'); } public function setVatRate($value) { return $this->setParameter('vatRate', $value); } public function getVatAmount() { return $this->getParameter('vatAmount'); } public function setVatAmount($value) { return $this->setParameter('vatAmount', $value); } public function getSku() { return $this->getParameter('sku'); } public function setSku($value) { return $this->setParameter('sku', $value); } public function getType() { return $this->getParameter('type'); } public function setType($value) { return $this->setParameter('type', $value); } public function getProductUrl() { return $this->getParameter('productUrl'); } public function setProductUrl($value) { return $this->setParameter('productUrl', $value); } public function getImageUrl() { return $this->getParameter('imageUrl'); } public function setImageUrl($value) { return $this->setParameter('imageUrl', $value); } public function getResource() { return $this->getParameter('resource'); } public function setResource($value) { return $this->setParameter('resource', $value); } public function getStatus() { return $this->getParameter('status'); } public function setStatus($value) { return $this->setParameter('status', $value); } public function getIsCancelable() { return $this->getParameter('isCancelable'); } public function setIsCancelable($value) { return $this->setParameter('isCancelable', $value); } public function getOrderId() { return $this->getParameter('orderId'); } public function setOrderId($value) { return $this->setParameter('orderId', $value); } public function getQuantityShipped() { return $this->getParameter('quantityShipped'); } public function setQuantityShipped($value) { return $this->setParameter('quantityShipped', $value); } public function getAmountShipped() { return $this->getParameter('amountShipped'); } public function setAmountShipped($value) { return $this->setParameter('amountShipped', $value); } public function getQuantityRefunded() { return $this->getParameter('quantityRefunded'); } public function setQuantityRefunded($value) { return $this->setParameter('quantityRefunded', $value); } public function getAmountRefunded() { return $this->getParameter('amountRefunded'); } public function setAmountRefunded($value) { return $this->setParameter('amountRefunded', $value); } public function getQuantityCanceled() { return $this->getParameter('quantityCanceled'); } public function setQuantityCanceled($value) { return $this->setParameter('quantityCanceled', $value); } public function getAmountCanceled() { return $this->getParameter('amountCanceled'); } public function setAmountCanceled($value) { return $this->setParameter('amountCanceled', $value); } public function getShippableQuantity() { return $this->getParameter('shippableQuantity'); } public function setShippableQuantity($value) { return $this->setParameter('shippableQuantity', $value); } public function getRefundableQuantity() { return $this->getParameter('refundableQuantity'); } public function setRefundableQuantity($value) { return $this->setParameter('refundableQuantity', $value); } public function getCancelableQuantity() { return $this->getParameter('cancelableQuantity'); } public function setCancelableQuantity($value) { return $this->setParameter('cancelableQuantity', $value); } public function getCreatedAt() { return $this->getParameter('createdAt'); } public function setCreatedAt($value) { return $this->setParameter('createdAt', $value); } } mollie/src/Message/Response/RefundResponse.php 0000666 00000001101 15165413756 0015463 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/refunds-api/create-refund */ class RefundResponse extends AbstractMollieResponse { /** * @return null|string */ public function getTransactionReference() { return $this->data['paymentId']; } /** * @return string */ public function getTransactionId() { return $this->data['id']; } /** * @return bool */ public function isSuccessful() { return isset($this->data['id']); } } mollie/src/Message/Response/PurchaseResponse.php 0000666 00000000670 15165413756 0016024 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/payments-api/create-payment */ class PurchaseResponse extends FetchTransactionResponse { /** * When you do a `purchase` the request is never successful because * you need to redirect off-site to complete the purchase. * * {@inheritdoc} */ public function isSuccessful() { return false; } } mollie/src/Message/Response/CreateOrderResponse.php 0000666 00000000656 15165413756 0016455 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/orders-api/create-order */ class CreateOrderResponse extends FetchOrderResponse { /** * When you do a `order` the request is never successful because * you need to redirect off-site to complete the purchase. * * {@inheritdoc} */ public function isSuccessful() { return false; } } mollie/src/Message/Response/FetchOrderResponse.php 0000666 00000001247 15165413756 0016300 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; use Omnipay\Common\ItemBag; use Omnipay\Mollie\Item; /** * @see https://docs.mollie.com/reference/v2/payments-api/get-order */ class FetchOrderResponse extends FetchTransactionResponse { public function getLines() { if (isset($this->data['lines'])) { return $this->data['lines']; } return null; } public function getItems() { if (isset($this->data['lines'])) { $items = []; foreach ($this->data['lines'] as $line) { $items[] = new Item($line); } return new ItemBag($items); } } } mollie/src/Message/Response/FetchPaymentMethodsResponse.php 0000666 00000001521 15165413756 0020161 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; use Omnipay\Common\Message\FetchPaymentMethodsResponseInterface; use Omnipay\Common\PaymentMethod; /** * @see https://docs.mollie.com/reference/v2/methods-api/list-methods */ class FetchPaymentMethodsResponse extends AbstractMollieResponse implements FetchPaymentMethodsResponseInterface { /** * Return available payment methods as an associative array. * * @return PaymentMethod[] */ public function getPaymentMethods() { if (isset($this->data['_embedded']["methods"]) === false) { return []; } $paymentMethods = []; foreach ($this->data['_embedded']["methods"] as $method) { $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); } return $paymentMethods; } } mollie/src/Message/Response/CompleteOrderResponse.php 0000666 00000000746 15165413756 0017022 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/payments-api/get-payment */ class CompleteOrderResponse extends FetchOrderResponse { /** * {@inheritdoc} */ public function isSuccessful() { return parent::isSuccessful() && $this->isPaid(); } /** * The order status is never a redirect * * {@inheritdoc} */ public function isRedirect() { return false; } } mollie/src/Message/Response/CompletePurchaseResponse.php 0000666 00000000523 15165413756 0017512 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/payments-api/get-payment */ class CompletePurchaseResponse extends FetchTransactionResponse { /** * {@inheritdoc} */ public function isSuccessful() { return parent::isSuccessful() && $this->isPaid(); } } mollie/src/Message/Response/UpdateCustomerResponse.php 0000666 00000000626 15165413756 0017217 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/customers-api/update-customer */ class UpdateCustomerResponse extends AbstractMollieResponse { /** * @return string|null */ public function getCustomerReference() { if (isset($this->data['id'])) { return $this->data['id']; } return null; } } mollie/src/Message/Response/FetchCustomerMandatesResponse.php 0000666 00000001237 15165413756 0020502 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/mandates-api/list-mandates */ class FetchCustomerMandatesResponse extends AbstractMollieResponse { public function getMandates() { if (isset($this->data['_embedded']['mandates'])) { return $this->data['_embedded']['mandates']; } } public function hasValidMandates() { if ($mandates = $this->getMandates()) { foreach ($mandates as $mandate) { if ($mandate['status'] == "valid") { return true; } } } return false; } } mollie/src/Message/Response/CreateCustomerResponse.php 0000666 00000000626 15165413756 0017200 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/customers-api/create-customer */ class CreateCustomerResponse extends AbstractMollieResponse { /** * @return string|null */ public function getCustomerReference() { if (isset($this->data['id'])) { return $this->data['id']; } return null; } } mollie/src/Message/Response/FetchIssuersResponse.php 0000666 00000001363 15165413756 0016661 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; use Omnipay\Common\Issuer; use Omnipay\Common\Message\FetchIssuersResponseInterface; /** * @see https://docs.mollie.com/reference/v2/methods-api/get-method */ class FetchIssuersResponse extends AbstractMollieResponse implements FetchIssuersResponseInterface { /** * Return available issuers as an associative array. * * @return Issuer[] */ public function getIssuers() { if (isset($this->data['issuers']) === false) { return []; } $issuers = []; foreach ($this->data['issuers'] as $issuer) { $issuers[] = new Issuer($issuer['id'], $issuer['name'], $this->data['id']); } return $issuers; } } mollie/src/Message/Response/CreateCustomerMandateResponse.php 0000666 00000000765 15165413756 0020476 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/mandates-api/create-mandate */ class CreateCustomerMandateResponse extends AbstractMollieResponse { /** * @return string */ public function getMandateId() { if (isset($this->data['id'])) { return $this->data['id']; } } /** * @return bool */ public function isSuccessful() { return isset($this->data['id']); } } mollie/src/Message/Response/FetchTransactionResponse.php 0000666 00000010070 15165413756 0017504 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; use Omnipay\Common\Message\RedirectResponseInterface; /** * @see https://docs.mollie.com/reference/v2/payments-api/get-payment */ class FetchTransactionResponse extends AbstractMollieResponse implements RedirectResponseInterface { /** * {@inheritdoc} */ public function getRedirectMethod() { return 'GET'; } /** * {@inheritdoc} */ public function isRedirect() { return isset($this->data['_links']['checkout']['href']); } /** * {@inheritdoc} */ public function getRedirectUrl() { if ($this->isRedirect()) { return $this->data['_links']['checkout']['href']; } return null; } /** * {@inheritdoc} */ public function getRedirectData() { return null; } /** * {@inheritdoc} */ public function isSuccessful() { return parent::isSuccessful(); } /** * @return boolean */ public function isOpen() { return isset($this->data['status']) && ('open' === $this->data['status'] || 'created' === $this->data['status']); } /** * @return boolean */ public function isCancelled() { return isset($this->data['status']) && 'canceled' === $this->data['status']; } /** * @return boolean */ public function isPaid() { return isset($this->data['status']) && 'paid' === $this->data['status']; } /** * @return boolean */ public function isAuthorized() { return isset($this->data['status']) && 'authorized' === $this->data['status']; } /** * @return boolean */ public function isPaidOut() { return isset($this->data['_links']['settlement']); } /** * @return boolean */ public function isExpired() { return isset($this->data['status']) && 'expired' === $this->data['status']; } public function isRefunded() { return isset($this->data['_links']['refunds']); } public function isPartialRefunded() { return $this->isRefunded() && isset($this->data['amountRemaining']) && $this->data['amountRemaining']['value'] > 0; } /** * @return boolean */ public function hasChargebacks() { return !empty($this->data['_links']['chargebacks']); } /** * @return string|null */ public function getTransactionReference() { if (isset($this->data['id'])) { return $this->data['id']; } return null; } /** * @return string|null */ public function getTransactionId() { if (isset($this->data['metadata']['transactionId'])) { return $this->data['metadata']['transactionId']; } return null; } /** * @return string|null */ public function getStatus() { if (isset($this->data['status'])) { return $this->data['status']; } return null; } /** * @return string|null */ public function getAmount() { if (isset($this->data['amount']) && is_array($this->data['amount'])) { /** * $this->data['amount'] = [ * "currency" => "EUR", * "value" => "50", * ] */ return $this->data['amount']['value']; } return null; } public function getCurrency() { if ($this->isSuccessful() && is_array($this->data['amount'])) { /** * $this->data['amount'] = [ * "currency" => "EUR", * "value" => "50", * ] */ return $this->data['amount']['currency']; } return null; } /** * @return array|null */ public function getMetadata() { if (isset($this->data['metadata'])) { return $this->data['metadata']; } return null; } } mollie/src/Message/Response/CreateShipmentResponse.php 0000666 00000000303 15165413756 0017156 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/shipments-api/create-shipment */ class CreateShipmentResponse extends FetchOrderResponse { } mollie/src/Message/Response/CancelOrderResponse.php 0000666 00000000631 15165413756 0016430 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/orders-api/cancel-order */ final class CancelOrderResponse extends FetchOrderResponse { /** * @return bool */ public function isSuccessful() { if (!isset($this->data['status'])) { return false; } return 'canceled' === $this->data['status']; } } mollie/src/Message/Response/FetchCustomerResponse.php 0000666 00000000622 15165413756 0017022 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/customers-api/get-customer */ class FetchCustomerResponse extends AbstractMollieResponse { /** * @return string|null */ public function getCustomerReference() { if (isset($this->data['id'])) { return $this->data['id']; } return null; } } mollie/src/Message/Response/AbstractMollieResponse.php 0000666 00000000761 15165413756 0017160 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; use Omnipay\Common\Message\AbstractResponse; class AbstractMollieResponse extends AbstractResponse { /** * @return bool */ public function isSuccessful() { if (isset($this->data['status']) && isset($this->data['detail'])) { return false; } return true; } /** * @return string */ public function getMessage() { return json_encode($this->data); } } mollie/src/Message/Response/RevokeCustomerMandateResponse.php 0000666 00000000313 15165413756 0020513 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Response; /** * @see https://docs.mollie.com/reference/v2/mandates-api/create-mandate */ class RevokeCustomerMandateResponse extends AbstractMollieResponse { } mollie/src/Message/Request/FetchOrderRequest.php 0000666 00000002704 15165413756 0015763 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Response\FetchOrderResponse; /** * Retrieve a single order object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-order * @method FetchOrderResponse send() */ class FetchOrderRequest extends AbstractMollieRequest { /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'transactionReference'); $data = []; $data['id'] = $this->getTransactionReference(); return $data; } /** * @return bool */ public function hasIncludePayments() { return (bool) $this->getParameter('includePayments'); } /** * @param array $data * @return FetchOrderResponse */ public function sendData($data) { $response = $this->sendRequest( self::GET, \sprintf( '/orders/%s%s', $data['id'], $this->hasIncludePayments() ? '?embed=payments' : '' ) ); return $this->response = new FetchOrderResponse($this, $response); } /** * @param bool $includePayments * @return self */ public function setIncludePayments($includePayments) { return $this->setParameter('includePayments', $includePayments); } } mollie/src/Message/Request/UpdateCustomerRequest.php 0000666 00000005425 15165413756 0016705 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\UpdateCustomerResponse; /** * Update an existing customer. * * @see https://docs.mollie.com/reference/v2/customers-api/update-customer * @method UpdateCustomerResponse send() */ class UpdateCustomerRequest extends AbstractMollieRequest { /** * Get the customer's reference id. * * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $value * @return AbstractRequest */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } /** * Get the customer's email address. * * @return string */ public function getEmail() { return $this->getParameter('email'); } /** * @param string $value * @return AbstractRequest */ public function setEmail($value) { return $this->setParameter('email', $value); } /** * Get the customer's locale. * * Possible values: de_DE, en_US, es_ES, fr_FR, nl_BE, fr_BE, nl_NL. * * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * Optional value. * * @param string $value * @return AbstractRequest */ public function setLocale($value) { return $this->setParameter('locale', $value); } /** * Get the customer's metadata. * * @return array */ public function getMetadata() { return $this->getParameter('metadata'); } /** * Optional value. * * @param array $value * @return AbstractRequest */ public function setMetadata($value) { return $this->setParameter('metadata', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'customerReference'); $data = []; $data['name'] = $this->getDescription(); $data['email'] = $this->getEmail(); $data['locale'] = $this->getLocale(); if ($this->getMetadata()) { $data['metadata'] = $this->getMetadata(); } return $data; } /** * @param array $data * @return UpdateCustomerResponse */ public function sendData($data) { $response = $this->sendRequest(self::POST, '/customers/' . $this->getCustomerReference(), $data); return $this->response = new UpdateCustomerResponse($this, $response); } } mollie/src/Message/Request/CreateCustomerMandateRequest.php 0000666 00000010013 15165413756 0020145 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\CreateCustomerMandateResponse; /** * Create a mandate for a specific customer. * * @see https://docs.mollie.com/reference/v2/mandates-api/create-mandate * @method CreateCustomerMandateResponse send() */ class CreateCustomerMandateRequest extends AbstractMollieRequest { /** * @return string */ public function getMethod() { return $this->getParameter('method'); } /** * @param string $method * @return AbstractRequest */ public function setMethod($method) { return $this->setParameter('method', $method); } /** * @return string */ public function getConsumerName() { return $this->getParameter('consumerName'); } /** * @param string $consumerName * @return AbstractRequest */ public function setConsumerName($consumerName) { return $this->setParameter('consumerName', $consumerName); } /** * @return string */ public function getConsumerAccount() { return $this->getParameter('consumerAccount'); } /** * @param string $consumerAccount * @return AbstractRequest */ public function setConsumerAccount($consumerAccount) { return $this->setParameter('consumerAccount', $consumerAccount); } /** * @return string */ public function getConsumerBic() { return $this->getParameter('consumerBic'); } /** * @param string $consumerBic * @return AbstractRequest */ public function setConsumerBic($consumerBic) { return $this->setParameter('consumerBic', $consumerBic); } /** * @return string */ public function getSignatureDate() { return $this->getParameter('signatureDate'); } /** * @param string $signatureDate * @return AbstractRequest */ public function setSignatureDate($signatureDate) { return $this->setParameter('signatureDate', $signatureDate); } /** * @return string */ public function getMandateReference() { return $this->getParameter('mandateReference'); } /** * @param string $mandateReference * @return AbstractRequest */ public function setMandateReference($mandateReference) { return $this->setParameter('mandateReference', $mandateReference); } /** * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $customerReference * @return AbstractRequest */ public function setCustomerReference($customerReference) { return $this->setParameter('customerReference', $customerReference); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'customerReference', 'method', 'consumerName', 'consumerAccount'); $data = array(); $data['method'] = $this->getMethod(); $data['consumerName'] = $this->getConsumerName(); $data['consumerAccount'] = $this->getConsumerAccount(); if ($this->getConsumerBic()) { $data['consumerBic'] = $this->getConsumerBic(); } if ($this->getSignatureDate()) { $data['signatureDate'] = $this->getSignatureDate(); } if ($this->getMandateReference()) { $data['mandateReference'] = $this->getMandateReference(); } return $data; } /** * @param array $data * @return CreateCustomerMandateResponse */ public function sendData($data) { $response = $this->sendRequest(self::POST, "/customers/{$this->getCustomerReference()}/mandates", $data); return $this->response = new CreateCustomerMandateResponse($this, $response); } } mollie/src/Message/Request/RevokeCustomerMandateRequest.php 0000666 00000003470 15165413756 0020206 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\RevokeCustomerMandateResponse; /** * Revoke a customer's mandate. * * @see https://docs.mollie.com/reference/v2/mandates-api/revoke-mandate * @method RevokeCustomerMandateResponse send() */ class RevokeCustomerMandateRequest extends AbstractMollieRequest { /** * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $value * @return AbstractRequest */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } /** * @return string */ public function getMandateId() { return $this->getParameter('mandateId'); } /** * @param string $value * @return AbstractRequest */ public function setMandateId($value) { return $this->setParameter('mandateId', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'customerReference', 'mandateId'); $data['customerReference'] = $this->getCustomerReference(); $data['mandateId'] = $this->getMandateId(); return $data; } /** * @param array $data * @return RevokeCustomerMandateResponse */ public function sendData($data) { $response = $this->sendRequest( self::DELETE, "/customers/{$this->getCustomerReference()}/mandates/{$this->getMandateId()}" ); return $this->response = new RevokeCustomerMandateResponse($this, $response); } } mollie/src/Message/Request/FetchCustomerRequest.php 0000666 00000002414 15165413756 0016507 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\FetchCustomerResponse; /** * Retrieve a single customer by its ID. * * @see https://docs.mollie.com/reference/v2/customers-api/get-customer * @method FetchCustomerResponse send() */ class FetchCustomerRequest extends AbstractMollieRequest { /** * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $value * @return AbstractRequest */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'customerReference'); return []; } /** * @param array $data * @return FetchCustomerResponse */ public function sendData($data) { $response = $this->sendRequest(self::GET, '/customers/' . $this->getCustomerReference(), $data); return $this->response = new FetchCustomerResponse($this, $response); } } mollie/src/Message/Request/CompleteOrderRequest.php 0000666 00000002243 15165413756 0016500 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Response\CompleteOrderResponse; /** * Retrieve a single order object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-order * @method CompleteOrderResponse send() */ class CompleteOrderRequest extends FetchOrderRequest { /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey'); $data = []; $data['id'] = $this->getTransactionReference(); if (!isset($data['id'])) { $data['id'] = $this->httpRequest->request->get('id'); } if (empty($data['id'])) { throw new InvalidRequestException("The transactionReference parameter is required"); } return $data; } /** * @param array $data * @return CompleteOrderResponse */ public function sendData($data) { $response = $this->sendRequest(self::GET, '/orders/' . $data['id']); return $this->response = new CompleteOrderResponse($this, $response); } } mollie/src/Message/Request/FetchIssuersRequest.php 0000666 00000002174 15165413756 0016346 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Response\FetchIssuersResponse; use AmeliaPsr\Http\Message\ResponseInterface; /** * Returns issuers available for the ideal payment method. * * @see https://docs.mollie.com/reference/v2/methods-api/get-method * @method FetchIssuersResponse send() */ class FetchIssuersRequest extends AbstractMollieRequest { /** * Since the Issuer endpoint got removed in the Mollie v2 api. * We now use the include parameter on the get-method endpoint. * * @var string */ protected $endpoint = '/methods/ideal?include=issuers'; /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey'); return []; } /** * @param array $data * @return ResponseInterface|FetchIssuersResponse */ public function sendData($data) { $response = $this->sendRequest(self::GET, $this->endpoint); return $this->response = new FetchIssuersResponse($this, $response); } } mollie/src/Message/Request/CreateShipmentRequest.php 0000666 00000003203 15165413756 0016644 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Response\CreateShipmentResponse; /** * Create a shipment with the Mollie API. * * @see https://docs.mollie.com/reference/v2/shipments-api/create-shipment * @method CreateShipmentResponse send() */ class CreateShipmentRequest extends AbstractMollieRequest { /** * @return array */ public function getTracking() { return $this->getParameter('tracking'); } /** * @param array $value * @return $this */ public function setTracking(array $value) { return $this->setParameter('tracking', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'transactionReference'); $data = []; $data['lines'] = []; if ($items = $this->getItems()) { foreach ($items as $item) { $data['lines'][] = array_filter([ 'id' => $item->getId(), 'quantity' => $item->getQuantity(), ]); } } if ($tracking = $this->getTracking()) { $data['tracking'] = $tracking; } return $data; } /** * @param array $data * @return CreateShipmentResponse */ public function sendData($data) { $response = $this->sendRequest(self::POST, '/orders/' . $this->getTransactionReference() . '/shipments', $data); return $this->response = new CreateShipmentResponse($this, $response); } } mollie/src/Message/Request/FetchCustomerMandatesRequest.php 0000666 00000002511 15165413756 0020162 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\FetchCustomerMandatesResponse; /** * Retrieve all mandates for the given customer. * * @see https://docs.mollie.com/reference/v2/mandates-api/list-mandates * @method FetchCustomerMandatesResponse send() */ class FetchCustomerMandatesRequest extends AbstractMollieRequest { /** * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $value * @return AbstractRequest */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'customerReference'); return array(); } /** * @param array $data * @return FetchCustomerMandatesResponse */ public function sendData($data) { $response = $this->sendRequest(self::GET, "/customers/{$this->getCustomerReference()}/mandates", $data); return $this->response = new FetchCustomerMandatesResponse($this, $response); } } mollie/src/Message/Request/CancelOrderRequest.php 0000666 00000001364 15165413756 0016120 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Mollie\Message\Response\CancelOrderResponse; /** * Cancel an order with the Mollie API. * * @see https://docs.mollie.com/reference/v2/orders-api/cancel-order * @method CancelOrderResponse send() */ final class CancelOrderRequest extends AbstractMollieRequest { /** * @inheritdoc */ public function getData() { $this->validate('apiKey', 'transactionReference'); return []; } /** * @inheritdoc */ public function sendData($data) { return $this->response = new CancelOrderResponse( $this, $this->sendRequest(self::DELETE, '/orders/'.$this->getTransactionReference(), $data) ); } } mollie/src/Message/Request/CreateCustomerRequest.php 0000666 00000004573 15165413756 0016671 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\CreateCustomerResponse; /** * Creates a simple minimal representation of a customer in the Mollie API. * * @see https://docs.mollie.com/reference/v2/customers-api/create-customer * @method CreateCustomerResponse send() */ class CreateCustomerRequest extends AbstractMollieRequest { /** * Get the customer's email address. * * @return string */ public function getEmail() { return $this->getParameter('email'); } /** * @param string $value * @return AbstractRequest */ public function setEmail($value) { return $this->setParameter('email', $value); } /** * Get the customer's locale. * * Possible values: de_DE, en_US, es_ES, fr_FR, nl_BE, fr_BE, nl_NL. * * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * Optional value. * * @param string $value * @return AbstractRequest */ public function setLocale($value) { return $this->setParameter('locale', $value); } /** * Get the customer's metadata. * * @return array */ public function getMetadata() { return $this->getParameter('metadata'); } /** * Optional value. * * @param array $value * @return AbstractRequest */ public function setMetadata($value) { return $this->setParameter('metadata', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey'); $data = []; $data['name'] = $this->getDescription(); $data['email'] = $this->getEmail(); $data['locale'] = $this->getLocale(); if ($this->getMetadata()) { $data['metadata'] = $this->getMetadata(); } return $data; } /** * @param array $data * @return CreateCustomerResponse */ public function sendData($data) { $response = $this->sendRequest(self::POST, '/customers', $data); return $this->response = new CreateCustomerResponse($this, $response); } } mollie/src/Message/Request/AbstractMollieRequest.php 0000666 00000006625 15165413756 0016651 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\ItemBag; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Gateway; use Omnipay\Mollie\Item; /** * This class holds all the common things for all of Mollie requests. * * @see https://docs.mollie.com/index */ abstract class AbstractMollieRequest extends AbstractRequest { const POST = 'POST'; const GET = 'GET'; const DELETE = 'DELETE'; /** * @var string */ protected $apiVersion = "v2"; /** * @var string */ protected $baseUrl = 'https://api.mollie.com/'; /** * @return string */ public function getApiKey() { return $this->getParameter('apiKey'); } /** * @param string $value * @return $this */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * @return array|null */ public function getVersionStrings() { return $this->getParameter('versionStrings'); } /** * @param string $value * @return $this */ public function setVersionStrings(array $values) { return $this->setParameter('versionStrings', $values); } /** * @param string $value * @return $this */ public function setTransactionId($value) { return $this->setParameter('transactionId', $value); } /** * @return string */ public function getTransactionId() { return $this->getParameter('transactionId'); } /** * Set the items in this order * * @param Item[] $items An array of items in this order * @return $this */ public function setItems($items) { $orderItems = []; foreach ($items as $item) { if (is_array($item)) { $orderItems[] = new Item($item); } elseif (! ($item instanceof Item)) { throw new \InvalidArgumentException('Item should be an instance of ' . Item::class); } } return parent::setItems($orderItems); } /** * @param string $method * @param string $endpoint * @param array $data * @return array */ protected function sendRequest($method, $endpoint, array $data = null) { $versions = [ 'Omnipay-Mollie/' . Gateway::GATEWAY_VERSION, 'PHP/' . phpversion(), ]; if ($customVersions = $this->getParameter('versionStrings')) { $versions = array_merge($versions, $customVersions); } $headers = [ 'Accept' => "application/json", 'Content-Type' => "application/json", 'Authorization' => 'Bearer ' . $this->getApiKey(), 'User-Agent' => implode(' ', $versions), ]; if (function_exists("php_uname")) { $headers['X-Mollie-Client-Info'] = php_uname(); } $response = $this->httpClient->request( $method, $this->baseUrl . $this->apiVersion . $endpoint, $headers, ($data === null || $data === []) ? null : json_encode($data) ); return json_decode($response->getBody(), true); } protected function createAmountObject($amount) { return isset($amount) ? [ 'currency' => $this->getCurrency(), 'value' => $this->formatCurrency($amount), ] : null; } } mollie/src/Message/Request/CompletePurchaseRequest.php 0000666 00000002276 15165413756 0017205 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; /** * Retrieve a single payment object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-payment * @method CompletePurchaseResponse send() */ class CompletePurchaseRequest extends FetchTransactionRequest { /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey'); $data = []; $data['id'] = $this->getTransactionReference(); if (!isset($data['id'])) { $data['id'] = $this->httpRequest->request->get('id'); } if (empty($data['id'])) { throw new InvalidRequestException("The transactionReference parameter is required"); } return $data; } /** * @param array $data * @return CompletePurchaseResponse */ public function sendData($data) { $response = $this->sendRequest(self::GET, '/payments/' . $data['id']); return $this->response = new CompletePurchaseResponse($this, $response); } } mollie/src/Message/Request/CreateOrderRequest.php 0000666 00000017327 15165413756 0016144 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\CreditCard; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\ItemBag; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Item; use Omnipay\Mollie\Message\Response\CreateOrderResponse; use Omnipay\Mollie\Message\Response\PurchaseResponse; /** * Create an order with the Mollie API. * * @see https://docs.mollie.com/reference/v2/orders-api/create-order * @method CreateOrderResponse send() */ class CreateOrderRequest extends AbstractMollieRequest { /** * Lines can contain a negative amount (discounts etc.) * * @var bool */ protected $negativeAmountAllowed = true; /** * @return array */ public function getMetadata() { return $this->getParameter('metadata'); } /** * @param array $value * @return $this */ public function setMetadata(array $value) { return $this->setParameter('metadata', $value); } /** * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * @param string $value * @return $this */ public function setLocale($value) { return $this->setParameter('locale', $value); } /** * @return string */ public function getOrderNumber() { return $this->getParameter('orderNumber'); } /** * @param string $value * @return $this */ public function setOrderNumber($value) { return $this->setParameter('orderNumber', $value); } /** * @return string */ public function getBillingEmail() { return $this->getParameter('billingEmail'); } /** * @param string $value * @return $this */ public function setBillingEmail($value) { return $this->setParameter('billingEmail', $value); } /** * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $value * @return $this */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } /** * @return string */ public function getSequenceType() { return $this->getParameter('sequenceType'); } /** * @param string $value * @return $this */ public function setSequenceType($value) { return $this->setParameter('sequenceType', $value); } /** * Alias for lines * * @param $items * @return $this */ public function setLines($items) { return $this->setItems($items); } /** * A list of items in this order * * @return Item[]|null A bag containing items in this order */ public function getItems() { return $this->getParameter('items'); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'amount', 'locale', 'card', 'items', 'currency', 'orderNumber', 'returnUrl'); $data = []; $data['amount'] = [ 'value' => $this->getAmount(), 'currency' => $this->getCurrency() ]; if ($card = $this->getCard()) { $data += $this->getCardData($card); } $data['metadata'] = $this->getMetadata(); if ($this->getTransactionId()) { $data['metadata']['transactionId'] = $this->getTransactionId(); } if ($card && $birthday = $card->getBirthday()) { $data['consumerDateOfBirth'] = $birthday; } $data['locale'] = $this->getLocale(); $data['orderNumber'] = (string) $this->getOrderNumber(); $data['redirectUrl'] = $this->getReturnUrl(); $data['webhookUrl'] = $this->getNotifyUrl(); $data['method'] = $this->getPaymentMethod(); $data['lines'] = []; if ($items = $this->getItems()) { $data['lines'] = $this->getLines($items); } $data['payment'] = []; if ($issuer = $this->getIssuer()) { $data['payment']['issuer'] = $issuer; } if ($customerReference = $this->getCustomerReference()) { $data['payment']['customerId'] = $customerReference; } if ($sequenceType = $this->getSequenceType()) { $data['payment']['sequenceType'] = $sequenceType; } return array_filter($data); } protected function getCardData(CreditCard $card) { $data = []; $data['billingAddress'] = array_filter([ 'organizationName' => $card->getCompany(), 'streetAndNumber' => $card->getAddress1(), 'streetAdditional' => $card->getAddress2(), 'city' => $card->getCity(), 'region' => $card->getState(), 'postalCode' => $card->getPostcode(), 'country' => $card->getCountry(), 'title' => $card->getTitle(), 'givenName' => $card->getFirstName(), 'familyName' => $card->getLastName(), 'email' => $this->getBillingEmail() ?: $card->getEmail(), 'phone' => $card->getPhone(), ]); if ($card->getShippingAddress1()) { $data['shippingAddress'] = array_filter([ 'organizationName' => $card->getCompany(), 'streetAndNumber' => $card->getShippingAddress1(), 'streetAdditional' => $card->getShippingAddress2(), 'city' => $card->getShippingCity(), 'region' => $card->getShippingState(), 'postalCode' => $card->getShippingPostcode(), 'country' => $card->getShippingCountry(), 'title' => $card->getShippingTitle(), 'givenName' => $card->getShippingFirstName(), 'familyName' => $card->getShippingLastName(), 'email' => $card->getEmail(), 'phone' => $card->getShippingPhone(), ]); } return $data; } protected function getLines(ItemBag $items) { $lines = []; foreach ($items as $item) { $vatRate = $item->getVatRate(); $totalAmount = $item->getTotalAmount(); $vatAmount = $item->getVatAmount(); if (null === $totalAmount) { $totalAmount = $item->getQuantity() * $item->getPrice(); } if (null === $vatAmount) { $vatAmount = round($totalAmount * ($vatRate / (100 + $vatRate)), $this->getCurrencyDecimalPlaces()); } $data = [ 'type' => $item->getType(), 'sku' => $item->getSku(), 'name' => $item->getName(), 'productUrl' => $item->getProductUrl(), 'imageUrl' => $item->getImageUrl(), 'quantity' => (int) $item->getQuantity(), 'vatRate' => $vatRate, 'unitPrice' => $this->createAmountObject($item->getUnitPrice()), 'totalAmount' => $this->createAmountObject($totalAmount), 'discountAmount' => $this->createAmountObject($item->getDiscountAmount()), 'vatAmount' => $this->createAmountObject($vatAmount), ]; // Strip null values $lines[] = array_filter($data); } return $lines; } /** * @param array $data * @return ResponseInterface|PurchaseResponse */ public function sendData($data) { $response = $this->sendRequest(self::POST, '/orders', $data); return $this->response = new CreateOrderResponse($this, $response); } } mollie/src/Message/Request/FetchPaymentMethodsRequest.php 0000666 00000006431 15165413756 0017652 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Message\Response\FetchPaymentMethodsResponse; /** * Retrieve all available payment methods. * * @see https://docs.mollie.com/reference/v2/methods-api/list-methods * @method FetchPaymentMethodsResponse send() */ class FetchPaymentMethodsRequest extends AbstractMollieRequest { /** * @param string $billingCountry * @return $this */ public function setBillingCountry($billingCountry) { return $this->setParameter('billingCountry', $billingCountry); } /** * @return string */ public function getBillingCountry() { return $this->getParameter('billingCountry'); } /** * @param string $includeWallets * @return $this */ public function setIncludeWallets($includeWallets) { return $this->setParameter('includeWallets', $includeWallets); } /** * @return string */ public function getIncludeWallets() { return $this->getParameter('includeWallets'); } /** * @param string $locale * @return $this */ public function setLocale($locale) { return $this->setParameter('locale', $locale); } /** * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * @param string $resource * @return $this */ public function setResource($resource) { return $this->setParameter('resource', $resource); } /** * @return string */ public function getResource() { return $this->getParameter('resource'); } /** * @param $sequenceType * @return $this */ public function setSequenceType($sequenceType) { return $this->setParameter('sequenceType', $sequenceType); } /** * @return string */ public function getSequenceType() { return $this->getParameter('sequenceType'); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey'); // Currency and amount are optional but both required when either one is supplied $amount = null; if ($this->getAmount() || $this->getCurrency()) { $this->validate('amount', 'currency'); $amount = [ 'value' => $this->getAmount(), 'currency' => $this->getCurrency(), ]; } return [ 'amount' => $amount, 'billingCountry' => $this->getBillingCountry(), 'locale' => $this->getLocale(), 'resource' => $this->getResource(), 'includeWallets' => $this->getIncludeWallets(), 'sequenceType' => $this->getSequenceType(), ]; } /** * @param array $data * @return ResponseInterface|FetchPaymentMethodsResponse */ public function sendData($data) { $query = http_build_query($data); $response = $this->sendRequest(self::GET, '/methods' . ($query ? '?' . $query : '')); return $this->response = new FetchPaymentMethodsResponse($this, $response); } } mollie/src/Message/Request/FetchTransactionRequest.php 0000666 00000002026 15165413756 0017172 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Message\Response\FetchTransactionResponse; /** * Retrieve a single payment object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-payment * @method FetchTransactionResponse send() */ class FetchTransactionRequest extends AbstractMollieRequest { /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'transactionReference'); $data = []; $data['id'] = $this->getTransactionReference(); return $data; } /** * @param array $data * @return ResponseInterface|FetchTransactionResponse */ public function sendData($data) { $response = $this->sendRequest(self::GET, '/payments/' . $data['id']); return $this->response = new FetchTransactionResponse($this, $response); } } mollie/src/Message/Request/RefundRequest.php 0000666 00000002704 15165413756 0015161 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use function is_string; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Message\Response\RefundResponse; /** * Most payment methods support refunds. This means you can request your payment to be refunded to the consumer. * The amount of the refund will be withheld from your next settlement. * * @see https://docs.mollie.com/reference/v2/refunds-api/create-refund * @method RefundResponse send() */ class RefundRequest extends AbstractMollieRequest { /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'transactionReference', 'amount', 'currency'); $data = []; $data['amount'] = [ "value" => $this->getAmount(), "currency" => $this->getCurrency() ]; if (is_string($this->getParameter('description'))) { $data['description'] = $this->getParameter('description'); } return $data; } /** * @param array $data * @return ResponseInterface|RefundResponse */ public function sendData($data) { $response = $this->sendRequest( self::POST, '/payments/' . $this->getTransactionReference() . '/refunds', $data ); return $this->response = new RefundResponse($this, $response); } } mollie/src/Message/Request/PurchaseRequest.php 0000666 00000010755 15165413756 0015515 0 ustar 00 <?php namespace Omnipay\Mollie\Message\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Message\Response\PurchaseResponse; /** * Create a payment with the Mollie API. * * @see https://docs.mollie.com/reference/v2/payments-api/create-payment * @method PurchaseResponse send() */ class PurchaseRequest extends AbstractMollieRequest { /** * @return array */ public function getMetadata() { return $this->getParameter('metadata'); } /** * @param array $value * @return $this */ public function setMetadata(array $value) { return $this->setParameter('metadata', $value); } /** * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * @param string $value * @return $this */ public function setLocale($value) { return $this->setParameter('locale', $value); } /** * @return string */ public function getBillingEmail() { return $this->getParameter('billingEmail'); } /** * @param string $value * @return $this */ public function setBillingEmail($value) { return $this->setParameter('billingEmail', $value); } /** * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * @param string $value * @return $this */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } /** * @return string */ public function getMandateId() { return $this->getParameter('mandateId'); } /** * @param string $value * @return $this */ public function setMandateId($value) { return $this->setParameter('mandateId', $value); } /** * @return string */ public function getSequenceType() { return $this->getParameter('sequenceType'); } /** * @param string $value * @return $this */ public function setSequenceType($value) { return $this->setParameter('sequenceType', $value); } /** * @return string */ public function getInclude() { return $this->getParameter('include'); } /** * @param string $value * @return $this */ public function setInclude($value) { return $this->setParameter('include', $value); } /** * @return array * @throws InvalidRequestException */ public function getData() { $this->validate('apiKey', 'amount', 'currency', 'description', 'returnUrl'); $data = []; $data['amount'] = [ "value" => $this->getAmount(), "currency" => $this->getCurrency() ]; $data['description'] = $this->getDescription(); $data['redirectUrl'] = $this->getReturnUrl(); $data['method'] = $this->getPaymentMethod(); $data['metadata'] = $this->getMetadata(); if ($this->getTransactionId()) { $data['metadata']['transactionId'] = $this->getTransactionId(); } if ($issuer = $this->getIssuer()) { $data['issuer'] = $issuer; } $webhookUrl = $this->getNotifyUrl(); if (null !== $webhookUrl) { $data['webhookUrl'] = $webhookUrl; } if ($locale = $this->getLocale()) { $data['locale'] = $locale; } if ($billingEmail = $this->getBillingEmail()) { $data['billingEmail'] = $billingEmail; } if ($customerReference = $this->getCustomerReference()) { $data['customerId'] = $customerReference; } if ($sequenceType = $this->getSequenceType()) { $data['sequenceType'] = $sequenceType; } if ($mandateId = $this->getMandateId()) { $data['mandateId'] = $mandateId; } return $data; } /** * @param array $data * @return ResponseInterface|PurchaseResponse */ public function sendData($data) { $endpoint = '/payments'; if ($include = $this->getInclude()) { $endpoint .= '?include=' . $include; } $response = $this->sendRequest(self::POST, $endpoint, $data); return $this->response = new PurchaseResponse($this, $response); } } mollie/src/Gateway.php 0000666 00000020044 15165413756 0010747 0 ustar 00 <?php namespace Omnipay\Mollie; use Omnipay\Common\AbstractGateway; use Omnipay\Common\Message\RequestInterface; use Omnipay\Mollie\Message\Request\CancelOrderRequest; use Omnipay\Mollie\Message\Request\CompleteOrderRequest; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Request\CreateCustomerMandateRequest; use Omnipay\Mollie\Message\Request\CreateCustomerRequest; use Omnipay\Mollie\Message\Request\CreateOrderRequest; use Omnipay\Mollie\Message\Request\CreateShipmentRequest; use Omnipay\Mollie\Message\Request\FetchCustomerMandatesRequest; use Omnipay\Mollie\Message\Request\FetchCustomerRequest; use Omnipay\Mollie\Message\Request\FetchIssuersRequest; use Omnipay\Mollie\Message\Request\FetchOrderRequest; use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; use Omnipay\Mollie\Message\Request\FetchTransactionRequest; use Omnipay\Mollie\Message\Request\PurchaseRequest; use Omnipay\Mollie\Message\Request\RefundRequest; use Omnipay\Mollie\Message\Request\RevokeCustomerMandateRequest; use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; /** * Mollie Gateway provides a wrapper for Mollie API. * Please have a look at links below to have a high-level overview and see the API specification * * @see https://www.mollie.com/en/developers * @see https://docs.mollie.com/index * * @method RequestInterface authorize(array $options = array()) * @method RequestInterface completeAuthorize(array $options = array()) * @method RequestInterface capture(array $options = array()) * @method RequestInterface createCard(array $options = array()) * @method RequestInterface updateCard(array $options = array()) * @method RequestInterface deleteCard(array $options = array()) * * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class Gateway extends AbstractGateway { /** * Version of our gateway. */ const GATEWAY_VERSION = "5.2"; /** * @return string */ public function getName() { return 'Mollie'; } /** * @return array */ public function getDefaultParameters() { return array( 'apiKey' => '', ); } /** * @return string */ public function getApiKey() { return $this->getParameter('apiKey'); } /** * @param string $value * @return $this */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * @return array|null */ public function getVersionStrings() { return $this->getParameter('versionStrings'); } /** * @param string $value * @return $this */ public function setVersionStrings(array $values) { return $this->setParameter('versionStrings', $values); } /** * @param string $value * @return $this */ public function addVersionString($value) { $versionStrings = $this->getVersionStrings() ?: []; $versionStrings[] = str_replace([" ", "\t", "\n", "\r"], '-', $value); return $this->setVersionStrings($versionStrings); } /** * @param array $parameters * @return FetchIssuersRequest */ public function fetchIssuers(array $parameters = []) { /** @var FetchIssuersRequest $request */ $request = $this->createRequest(FetchIssuersRequest::class, $parameters); return $request; } /** * @param array $parameters * @return FetchPaymentMethodsRequest */ public function fetchPaymentMethods(array $parameters = []) { /** @var FetchPaymentMethodsRequest $request */ $request = $this->createRequest(FetchPaymentMethodsRequest::class, $parameters); return $request; } /** * @param array $parameters * @return FetchTransactionRequest */ public function fetchTransaction(array $parameters = []) { /** @var FetchTransactionRequest $request */ $request = $this->createRequest(FetchTransactionRequest::class, $parameters); return $request; } /** * @param array $parameters * @return PurchaseRequest */ public function purchase(array $parameters = []) { /** @var PurchaseRequest $request */ $request = $this->createRequest(PurchaseRequest::class, $parameters); return $request; } /** * @param array $parameters * @return CompletePurchaseRequest */ public function completePurchase(array $parameters = []) { /** @var CompletePurchaseRequest $request */ $request = $this->createRequest(CompletePurchaseRequest::class, $parameters); return $request; } /** * @param array $parameters * @return RefundRequest */ public function refund(array $parameters = []) { /** @var RefundRequest $request */ $request = $this->createRequest(RefundRequest::class, $parameters); return $request; } /** * @param array $parameters * @return CreateOrderRequest */ public function createOrder(array $parameters = []) { /** @var CreateOrderRequest $request */ $request = $this->createRequest(CreateOrderRequest::class, $parameters); return $request; } /** * @param array $parameters * @return FetchOrderRequest */ public function fetchOrder(array $parameters = []) { /** @var FetchOrderRequest $request */ $request = $this->createRequest(FetchOrderRequest::class, $parameters); return $request; } /** * @param array $parameters * @return CompleteOrderRequest */ public function completeOrder(array $parameters = []) { /** @var CompleteOrderRequest $request */ $request = $this->createRequest(CompleteOrderRequest::class, $parameters); return $request; } /** * @param array $parameters * @return CreateShipmentRequest */ public function createShipment(array $parameters = []) { /** @var CreateShipmentRequest $request */ $request = $this->createRequest(CreateShipmentRequest::class, $parameters); return $request; } /** * @param array $parameters * @return CreateCustomerRequest */ public function createCustomer(array $parameters = []) { /** @var CreateCustomerRequest $request */ $request = $this->createRequest(CreateCustomerRequest::class, $parameters); return $request; } /** * @param array $parameters * @return UpdateCustomerRequest */ public function updateCustomer(array $parameters = []) { /** @var UpdateCustomerRequest $request */ $request = $this->createRequest(UpdateCustomerRequest::class, $parameters); return $request; } /** * @param array $parameters * @return FetchCustomerRequest */ public function fetchCustomer(array $parameters = []) { /** @var FetchCustomerRequest $request */ $request = $this->createRequest(FetchCustomerRequest::class, $parameters); return $request; } /** * @param array $parameters * @return FetchCustomerMandatesRequest */ public function fetchCustomerMandates(array $parameters = []) { return $this->createRequest(FetchCustomerMandatesRequest::class, $parameters); } /** * @param array $parameters * @return CreateCustomerMandateRequest */ public function createCustomerMandate(array $parameters = []) { return $this->createRequest(CreateCustomerMandateRequest::class, $parameters); } /** * @param array $parameters * @return RevokeCustomerMandateRequest */ public function revokeCustomerMandate(array $parameters = []) { return $this->createRequest(RevokeCustomerMandateRequest::class, $parameters); } /** * @param array $parameters * @return CancelOrderRequest */ public function void(array $parameters = []) { return $this->createRequest(CancelOrderRequest::class, $parameters); } } mollie/.gitignore 0000666 00000000067 15165413756 0010041 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml /.idea mollie/.travis.yml 0000666 00000001331 15165413756 0010155 0 ustar 00 language: php php: - 5.6 - 7.0 - 7.1 - 7.2 # This triggers builds to run on the new TravisCI infrastructure. # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ sudo: false ## Cache composer cache: directories: - $HOME/.composer/cache env: global: - setup=basic matrix: include: - php: 5.6 env: setup=lowest install: - if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi script: - composer validate --strict - vendor/bin/phpcs --standard=PSR2 src - vendor/bin/phpunit --coverage-text mollie/CONTRIBUTING.md 0000666 00000001040 15165413756 0010272 0 ustar 00 # Contributing Guidelines * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. * Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) style and that all tests pass. * Send the pull request. * Check that the Travis CI build passed. If not, rinse and repeat. mollie/tests/Message/FetchCustomerMandatesRequestTest.php 0000666 00000006577 15165413756 0017765 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\FetchCustomerMandatesRequest; use Omnipay\Mollie\Message\Response\FetchCustomerMandatesResponse; use Omnipay\Tests\TestCase; class FetchCustomerMandatesRequestTest extends TestCase { use AssertRequestTrait; /** * @var FetchCustomerMandatesRequest */ protected $request; public function setUp() { $this->request = new FetchCustomerMandatesRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'apiKey' => 'mykey', 'customerReference' => 'cst_R6JLAuqEgm', ) ); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertEmpty($data); } public function testSendSuccess() { $this->setMockHttpResponse("FetchCustomerMandatesSuccess.txt"); $response = $this->request->send(); $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/customers/cst_R6JLAuqEgm/mandates"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchCustomerMandatesResponse::class, $response); $mandates = $response->getMandates(); $this->assertSame("mdt_AcQl5fdL4h", $mandates[0]['id']); $this->assertSame("directdebit", $mandates[0]['method']); $this->assertTrue($response->hasValidMandates()); $this->assertJsonStringEqualsJsonString( '{"count":5,"_embedded":{"mandates":[{"resource":"mandate","id":"mdt_AcQl5fdL4h","mode":"test","status":"valid","method":"directdebit","details":{"consumerName":"John Doe","consumerAccount":"NL55INGB0000000000","consumerBic":"INGBNL2A"},"mandateReference":null,"signatureDate":"2018-05-07","createdAt":"2018-05-07T10:49:08+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_8wmqcHMN4U\/mandates\/mdt_AcQl5fdL4h","type":"application\/hal+json"},"customer":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_8wmqcHMN4U","type":"application\/hal+json"},"documentation":{"href":"https:\/\/mollie.com\/en\/docs\/reference\/customers\/create-mandate","type":"text\/html"}}},[],[],[],[]]},"_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_8wmqcHMN4U\/mandates?limit=5","type":"application\/hal+json"},"previous":null,"next":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_8wmqcHMN4U\/mandates?from=mdt_AcQl5fdL4h&limit=5","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/mandates-api\/revoke-mandate","type":"text\/html"}}}', $response->getMessage() ); } public function testSendFailure() { $this->setMockHttpResponse('FetchCustomerMandatesFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertJsonStringEqualsJsonString( '{"status":404,"title":"Not Found","detail":"No customer exists with token cst_6HUkmjwzBBa.","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage() ); } } mollie/tests/Message/CreateCustomerMandateRequestTest.php 0000666 00000006515 15165413756 0017744 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\CreateCustomerMandateRequest; use Omnipay\Mollie\Message\Response\CreateCustomerMandateResponse; use Omnipay\Tests\TestCase; class CreateCustomerMandateRequestTest extends TestCase { use AssertRequestTrait; /** * @var CreateCustomerMandateRequest */ protected $request; public function setUp() { $this->request = new CreateCustomerMandateRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => "mykey", 'consumerName' => "Customer A", 'consumerAccount' => "NL53INGB0000000000", "method" => "directdebit", 'customerReference' => 'cst_bSNBBJBzdG', 'mandateReference' => "YOUR-COMPANY-MD13804" )); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame("NL53INGB0000000000", $data['consumerAccount']); $this->assertSame('directdebit', $data['method']); $this->assertSame("YOUR-COMPANY-MD13804", $data['mandateReference']); $this->assertCount(4, $data); } public function testSendSuccess() { $this->setMockHttpResponse('CreateCustomerMandateSuccess.txt'); /** @var CreateCustomerMandateResponse $response */ $response = $this->request->send(); $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG/mandates"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CreateCustomerMandateResponse::class, $response); $this->assertSame("mdt_h3gAaD5zP", $response->getMandateId()); $this->assertTrue($response->isSuccessful()); $this->assertJsonStringEqualsJsonString( '{"resource":"mandate","id":"mdt_h3gAaD5zP","mode":"test","status":"valid","method":"directdebit","details":{"consumerName":"John Doe","consumerAccount":"NL55INGB0000000000","consumerBic":"INGBNL2A"},"mandateReference":"YOUR-COMPANY-MD13804","signatureDate":"2018-05-07","createdAt":"2018-05-07T10:49:08+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_4qqhO89gsT\/mandates\/mdt_h3gAaD5zP","type":"application\/hal+json"},"customer":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_4qqhO89gsT","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/mandates-api\/create-mandate","type":"text\/html"}}}', $response->getMessage() ); } public function testSendFailure() { $this->setMockHttpResponse('CreateCustomerMandateFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertJsonStringEqualsJsonString( '{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage() ); } } mollie/tests/Message/RefundRequestTest.php 0000666 00000010204 15165413756 0014736 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Mollie\Message\Request\PurchaseRequest; use Omnipay\Mollie\Message\Request\RefundRequest; use Omnipay\Mollie\Message\Response\RefundResponse; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase { use AssertRequestTrait; /** * @var PurchaseRequest */ protected $request; public function setUp() { $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize([ 'apiKey' => 'mykey', 'transactionReference' => 'tr_WDqYK6vllg', 'amount' => '12.00', 'currency' => 'EUR', ]); } /** * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function testGetData() { $this->request->initialize([ 'apiKey' => 'mykey', 'amount' => '12.00', 'currency' => 'EUR', 'transactionReference' => 'tr_WDqYK6vllg' ]); $data = $this->request->getData(); $this->assertSame(["value" => "12.00", "currency" => "EUR"], $data['amount']); $this->assertCount(1, $data); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException */ public function testGetDataWithoutAmount() { $this->request->initialize( [ 'apiKey' => 'mykey', 'transactionReference' => 'tr_WDqYK6vllg', ] ); $data = $this->request->getData(); $this->assertCount(0, $data); } public function testSendSuccess() { $this->setMockHttpResponse('RefundSuccess.txt'); /** @var RefundResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{"amount":{"value":"12.00","currency":"EUR"}}' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(RefundResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); $this->assertSame('re_4qqhO89gsT', $response->getTransactionId()); } public function test401Failure() { $this->setMockHttpResponse('Refund401Failure.txt'); /** @var RefundResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], ''), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(RefundResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertEquals('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } public function test422Failure() { $this->setMockHttpResponse('Refund422Failure.txt'); /** @var RefundResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{"amount":{"value":"12.00","currency":"EUR"}}' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(RefundResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertEquals('{"status":422,"title":"Unprocessable Entity","detail":"The payment method is invalid","field":"method","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); } } mollie/tests/Message/AssertRequestTrait.php 0000666 00000002030 15165413756 0015116 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; trait AssertRequestTrait { abstract function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false); abstract function assertJsonStringEqualsJsonString($expected, $actual, $message = null); public function assertEqualRequest(\AmeliaPsr\Http\Message\RequestInterface $expectedRequest, \AmeliaPsr\Http\Message\RequestInterface $actualRequest) { $this->assertEquals($expectedRequest->getMethod(), $actualRequest->getMethod(), "Expected request Method should be equal to actual request method."); $this->assertEquals($expectedRequest->getUri(), $actualRequest->getUri(), "Expected request Uri should be equal to actual request body."); if(!empty((string) $expectedRequest->getBody())) { $this->assertJsonStringEqualsJsonString((string) $expectedRequest->getBody(), (string) $actualRequest->getBody(), "Expected request Body should be equal to actual request body."); } } } mollie/tests/Message/CompletePurchaseRequestTest.php 0000666 00000005247 15165413756 0016771 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; use Omnipay\Tests\TestCase; class CompletePurchaseRequestTest extends TestCase { use AssertRequestTrait; /** * @var CompletePurchaseRequest */ protected $request; public function setUp() { $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey', )); $this->getHttpRequest()->request->replace(array( 'id' => 'tr_Qzin4iTWrU', )); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException * @expectedExceptionMessage The transactionReference parameter is required */ public function testGetDataWithoutIDParameter() { $this->getHttpRequest()->request->remove('id'); $data = $this->request->getData(); $this->assertEmpty($data); } /** * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame("tr_Qzin4iTWrU", $data['id']); $this->assertCount(1, $data); } public function testSendSuccess() { $this->setMockHttpResponse('CompletePurchaseSuccess.txt'); $response = $this->request->send(); $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CompletePurchaseResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isOpen()); $this->assertTrue($response->isPaid()); $this->assertFalse($response->isRedirect()); $this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference()); } public function testSendExpired() { $this->setMockHttpResponse('CompletePurchaseExpired.txt'); $response = $this->request->send(); $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CompletePurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isPaid()); $this->assertTrue($response->isExpired()); $this->assertFalse($response->isRedirect()); $this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference()); } } mollie/tests/Message/FetchIssuersRequestTest.php 0000666 00000005111 15165413756 0016123 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Issuer; use Omnipay\Mollie\Message\Request\FetchIssuersRequest; use Omnipay\Mollie\Message\Response\FetchIssuersResponse; use Omnipay\Tests\TestCase; class FetchIssuersRequestTest extends TestCase { use AssertRequestTrait; /** * @var FetchIssuersRequest */ protected $request; public function setUp() { $this->request = new FetchIssuersRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey' )); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertEmpty($data); } public function testSendSuccess() { $this->setMockHttpResponse('FetchIssuersSuccess.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchIssuersResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $expectedIssuer = new Issuer('ideal_ABNANL2A', 'ABN AMRO', 'ideal'); $expectedIssuer2 = new Issuer('ideal_ASNBNL21', 'ASN Bank', 'ideal'); $this->assertEquals(array($expectedIssuer, $expectedIssuer2), $response->getIssuers()); } public function testSendFailure() { $this->setMockHttpResponse('FetchIssuersFailure.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchIssuersResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); $this->assertEmpty($response->getIssuers()); } } mollie/tests/Message/CancelOrderRequestTest.php 0000666 00000005246 15165413756 0015706 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use Omnipay\Common\Http\ClientInterface; use Omnipay\Mollie\Message\Request\CancelOrderRequest; use Omnipay\Mollie\Message\Response\CancelOrderResponse; use Omnipay\Tests\TestCase; use AmeliaPsr\Http\Message\ResponseInterface; final class CancelOrderRequestTest extends TestCase { /** * @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject */ private $httpClient; /** * @var CancelOrderRequest */ private $request; public function setUp() { $this->httpClient = $this->createMock(ClientInterface::class); $this->request = new CancelOrderRequest($this->httpClient, $this->getHttpRequest()); } public function insufficientDataProvider() { return [ [['apiKey' => 'mykey']], [['transactionReference' => 'myref']], ]; } public function responseDataProvider() { return [ [['id' => 'ord_kEn1PlbGa'], false], [['status' => 'paid', 'id' => 'ord_kEn1PlbGa'], false], [['status' => 'canceled', 'id' => 'ord_kEn1PlbGa'], true], ]; } /** * @dataProvider insufficientDataProvider * * @expectedException \Omnipay\Common\Exception\InvalidRequestException * * @param array $input */ public function testGetDataWillValidateRequiredData(array $input) { $this->request->initialize($input); $this->request->getData(); } public function testGetDataWillReturnEmptyArray() { $this->request->initialize(['apiKey' => 'mykey', 'transactionReference' => 'myref']); self::assertEquals([], $this->request->getData()); } /** * @dataProvider responseDataProvider */ public function testSendData(array $responseData, $success) { $response = $this->createMock(ResponseInterface::class); $response->expects(self::once()) ->method('getBody') ->willReturn(\json_encode($responseData)); $this->httpClient->expects(self::once()) ->method('request') ->with( 'DELETE', 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa', ['Authorization' => 'Bearer mykey'] )->willReturn($response); $this->request->initialize(['apiKey' => 'mykey', 'transactionReference' => 'ord_kEn1PlbGa']); $voidResponse = $this->request->sendData([]); $this->assertInstanceOf(CancelOrderResponse::class, $voidResponse); $this->assertEquals($success, $voidResponse->isSuccessful()); $this->assertSame('ord_kEn1PlbGa', $voidResponse->getTransactionReference()); } } mollie/tests/Message/CompleteOrderRequestTest.php 0000666 00000004233 15165413756 0016264 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Mollie\Message\Request\CompleteOrderRequest; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Response\CompleteOrderResponse; use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; use Omnipay\Tests\TestCase; class CompleteOrderRequestTest extends TestCase { use AssertRequestTrait; /** * @var CompletePurchaseRequest */ protected $request; public function setUp() { $this->request = new CompleteOrderRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey', )); $this->getHttpRequest()->request->replace(array( 'id' => 'ord_kEn1PlbGa', )); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException * @expectedExceptionMessage The transactionReference parameter is required */ public function testGetDataWithoutIDParameter() { $this->getHttpRequest()->request->remove('id'); $data = $this->request->getData(); $this->assertEmpty($data); } /** * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame("ord_kEn1PlbGa", $data['id']); $this->assertCount(1, $data); } public function testSendSuccess() { $this->setMockHttpResponse('CompleteOrderSuccess.txt'); /** @var CompleteOrderResponse $response */ $response = $this->request->send(); $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/orders/ord_kEn1PlbGa"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CompleteOrderResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isOpen()); $this->assertFalse($response->isPaid()); $this->assertFalse($response->isRedirect()); $this->assertSame('ord_kEn1PlbGa', $response->getTransactionReference()); } } mollie/tests/Message/CreateCustomerRequestTest.php 0000666 00000007144 15165413756 0016451 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\CreateCustomerRequest; use Omnipay\Mollie\Message\Response\CreateCustomerResponse; use Omnipay\Tests\TestCase; class CreateCustomerRequestTest extends TestCase { use AssertRequestTrait; /** * * @var CreateCustomerRequest */ protected $request; public function setUp() { $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey', 'description' => 'John Doe', 'email' => 'john@doe.com', 'locale' => 'nl_NL', 'metadata' => 'Just some meta data.', )); } /** * @throws InvalidRequestException */ public function testData() { $this->request->initialize(array( 'apiKey' => 'mykey', 'description' => 'John Doe', 'email' => 'john@doe.com', 'metadata' => 'Just some meta data.', )); $data = $this->request->getData(); $this->assertSame("John Doe", $data['name']); $this->assertSame('john@doe.com', $data['email']); $this->assertSame('Just some meta data.', $data['metadata']); $this->assertCount(4, $data); } public function testSendSuccess() { $this->setMockHttpResponse('CreateCustomerSuccess.txt'); /** @var CreateCustomerResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/customers", [], '{ "name":"John Doe", "email":"john@doe.com", "metadata":"Just some meta data.", "locale":"nl_NL" }' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(CreateCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); $this->assertJsonStringEqualsJsonString( '{"resource":"customer","id":"cst_bSNBBJBzdG","mode":"test","name":"John Doe","email":"john@doe.com","locale":"nl_NL","metadata":"Just some meta data.","createdAt":"2018-07-19T12:58:47+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_6HUkmjwzBB","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/customers-api\/create-customer","type":"text\/html"}}}', $response->getMessage() ); } public function testSendFailure() { $this->setMockHttpResponse('CreateCustomerFailure.txt'); $response = $this->request->send(); $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/customers"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CreateCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } } mollie/tests/Message/RevokeCustomerMandateRequestTest.php 0000666 00000003413 15165413756 0017766 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\RevokeCustomerMandateRequest; use Omnipay\Mollie\Message\Response\RevokeCustomerMandateResponse; use Omnipay\Tests\TestCase; class RevokeCustomerMandateRequestTest extends TestCase { use AssertRequestTrait; /** * @var RevokeCustomerMandateRequest */ protected $request; public function setUp() { $this->request = new RevokeCustomerMandateRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize([ 'apiKey' => "mykey", 'customerReference' => 'cst_bSNBBJBzdG', 'mandateId' => "mdt_pWUnw6pkBN", ]); } /** * @throws InvalidRequestException */ public function testData() { $this->request->initialize([ 'apiKey' => "mykey", 'customerReference' => 'cst_bSNBBJBzdG', 'mandateId' => "mdt_pWUnw6pkBN", ]); $data = $this->request->getData(); $this->assertSame("cst_bSNBBJBzdG", $data['customerReference']); $this->assertSame("mdt_pWUnw6pkBN", $data['mandateId']); } public function testSendSuccess() { $this->setMockHttpResponse('RevokeCustomerMandateSuccess.txt'); /** @var RevokeCustomerMandateResponse $response */ $response = $this->request->send(); $this->assertEqualRequest(new Request("DELETE", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG/mandates/mdt_pWUnw6pkBN"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(RevokeCustomerMandateResponse::class, $response); $this->assertTrue($response->isSuccessful()); } } mollie/tests/Message/PurchaseRequestTest.php 0000666 00000022521 15165413756 0015272 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\PurchaseRequest; use Omnipay\Mollie\Message\Response\PurchaseResponse; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { use AssertRequestTrait; /** * @var PurchaseRequest */ protected $request; public function setUp() { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey', 'amount' => '12.00', 'currency' => 'USD', 'issuer' => 'my bank', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'method' => 'ideal', 'metadata' => ['meta'], 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', )); } /** * @throws InvalidRequestException */ public function testGetData() { $this->request->initialize([ 'apiKey' => 'mykey', 'amount' => '12.00', 'currency' => 'USD', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', 'metadata' => ['meta'], 'issuer' => 'my bank', 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', ]); $data = $this->request->getData(); $this->assertSame(["value" => "12.00", "currency" => "USD"], $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); $this->assertSame('ideal', $data['method']); $this->assertSame(['meta'], $data['metadata']); $this->assertSame('my bank', $data['issuer']); $this->assertSame('fr_FR', $data['locale']); $this->assertSame('billing-email@example.com', $data['billingEmail']); $this->assertCount(8, $data); } /** * @throws InvalidRequestException */ public function testGetDataWithWebhook() { $this->request->initialize(array( 'apiKey' => 'mykey', 'amount' => '12.00', 'currency' => 'EUR', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', 'metadata' => ['meta'], 'issuer' => 'my bank', 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', 'notifyUrl' => 'https://www.example.com/hook', )); $data = $this->request->getData(); $this->assertSame(["value" => "12.00", "currency" => "EUR"], $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); $this->assertSame('ideal', $data['method']); $this->assertSame(['meta'], $data['metadata']); $this->assertSame('my bank', $data['issuer']); $this->assertSame('fr_FR', $data['locale']); $this->assertSame('billing-email@example.com', $data['billingEmail']); $this->assertSame('https://www.example.com/hook', $data['webhookUrl']); $this->assertCount(9, $data); } /** * @throws InvalidRequestException */ public function testNoIssuer() { $this->request->initialize(array( 'apiKey' => 'mykey', 'amount' => '12.00', 'currency' => 'SEK', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', 'metadata' => ['meta'], 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', 'notifyUrl' => 'https://www.example.com/hook', )); $data = $this->request->getData(); $this->assertSame(["value" => "12.00", "currency" => "SEK"], $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); $this->assertSame('ideal', $data['method']); $this->assertSame(['meta'], $data['metadata']); $this->assertSame('fr_FR', $data['locale']); $this->assertSame('billing-email@example.com', $data['billingEmail']); $this->assertSame('https://www.example.com/hook', $data['webhookUrl']); $this->assertCount(8, $data); } public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/payments", [], '{ "amount":{ "value":"12.00", "currency":"USD" }, "description":"Description", "redirectUrl":"https:\/\/www.example.com\/return", "method":null, "metadata":[ "meta" ], "issuer":"my bank", "locale":"fr_FR", "billingEmail":"billing-email@example.com" }' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(PurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertSame('https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('tr_7UhSN1zuXS', $response->getTransactionReference()); $this->assertTrue($response->isOpen()); $this->assertFalse($response->isPaid()); $this->assertNull($response->getCode()); $this->assertJsonStringEqualsJsonString( '{"resource":"payment","id":"tr_7UhSN1zuXS","mode":"test","createdAt":"2018-03-20T09:13:37+00:00","amount":{"value":"10.00","currency":"EUR"},"description":"My first payment","method":null,"metadata":{"order_id":"12345"},"status":"open","isCancelable":false,"expiresAt":"2018-03-20T09:28:37+00:00","details":null,"profileId":"pfl_QkEhN94Ba","sequenceType":"oneoff","redirectUrl":"https:\/\/webshop.example.org\/order\/12345\/","webhookUrl":"https:\/\/webshop.example.org\/payments\/webhook\/","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/payments\/tr_7UhSN1zuXS","type":"application\/json"},"checkout":{"href":"https:\/\/www.mollie.com\/payscreen\/select-method\/7UhSN1zuXS","type":"text\/html"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/payments-api\/create-payment","type":"text\/html"}}}', $response->getMessage() ); } public function testSendSuccessWithQrcode() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->setInclude('details.qrCode')->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/payments?include=details.qrCode", [], '{ "amount":{ "value":"12.00", "currency":"USD" }, "description":"Description", "redirectUrl":"https:\/\/www.example.com\/return", "method":null, "metadata":[ "meta" ], "issuer":"my bank", "locale":"fr_FR", "billingEmail":"billing-email@example.com" }' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(PurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); } public function testIssuerFailure() { $this->setMockHttpResponse('PurchaseIssuerFailure.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/payments" ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(PurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('{"status":422,"title":"Unprocessable Entity","detail":"The payment method is invalid","field":"method","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); } } mollie/tests/Message/FetchTransactionRequestTest.php 0000666 00000007002 15165413756 0016754 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\FetchTransactionRequest; use Omnipay\Mollie\Message\Response\FetchTransactionResponse; use Omnipay\Tests\TestCase; class FetchTransactionRequestTest extends TestCase { use AssertRequestTrait; /** * @var FetchTransactionRequest */ protected $request; public function setUp() { $this->request = new FetchTransactionRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'apiKey' => 'mykey', 'transactionReference' => 'tr_WDqYK6vllg', ) ); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame("tr_WDqYK6vllg", $data['id']); $this->assertCount(1, $data); } public function testSendSuccess() { $this->setMockHttpResponse('FetchTransactionSuccess.txt'); /** @var FetchTransactionResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request( "GET", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchTransactionResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertTrue($response->isPaid()); $this->assertFalse($response->isCancelled()); $this->assertFalse($response->isPaidOut()); $this->assertTrue($response->isRedirect()); $this->assertFalse($response->isRefunded()); $this->assertFalse($response->isPartialRefunded()); $this->assertSame("paid", $response->getStatus()); $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); $this->assertSame("10.00", $response->getAmount()); } public function testSendExpired() { $this->setMockHttpResponse('FetchTransactionExpired.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request( "GET", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchTransactionResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); $this->assertTrue($response->isExpired()); } public function testSendFailure() { $this->setMockHttpResponse('FetchTransaction404Failure.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request( "GET", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchTransactionResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertEquals(404, $response->getStatus()); $this->assertNull($response->getAmount()); } } mollie/tests/Message/AbstractMollieRequestTest.php 0000666 00000004070 15165413756 0016424 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Mollie\Gateway; use Omnipay\Mollie\Message\Request\CompleteOrderRequest; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Response\CompleteOrderResponse; use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; use Omnipay\Tests\TestCase; class AbstractMollieRequestTest extends TestCase { /** * @var Gateway */ protected $gateway; public function setUp() { $this->gateway = new Gateway($this->getHttpClient()); } public function testVersionString() { $request = $this->gateway->fetchIssuers(); $request->send(); /** @var \AmeliaPsr\Http\Message\RequestInterface $httpRequest */ $httpRequest = $this->getMockedRequests()[0]; $versionString = 'Omnipay-Mollie/'.Gateway::GATEWAY_VERSION.' PHP/' . phpversion(); $this->assertEquals($versionString, $httpRequest->getHeaderLine('User-Agent')); } public function testCustomVersionStrings() { $this->gateway->initialize([ 'versionStrings' => ['Acme/6.84'] ]); $request = $this->gateway->fetchIssuers(); $request->send(); /** @var \AmeliaPsr\Http\Message\RequestInterface $httpRequest */ $httpRequest = $this->getMockedRequests()[0]; $versionString = 'Omnipay-Mollie/'.Gateway::GATEWAY_VERSION.' PHP/' . phpversion() . ' Acme/6.84'; $this->assertEquals($versionString, $httpRequest->getHeaderLine('User-Agent')); } public function testAddVersionString() { $this->gateway->addVersionString('Acme/6.84'); $request = $this->gateway->fetchIssuers(); $request->send(); /** @var \AmeliaPsr\Http\Message\RequestInterface $httpRequest */ $httpRequest = $this->getMockedRequests()[0]; $versionString = 'Omnipay-Mollie/'.Gateway::GATEWAY_VERSION.' PHP/' . phpversion() . ' Acme/6.84'; $this->assertEquals($versionString, $httpRequest->getHeaderLine('User-Agent')); } } mollie/tests/Message/FetchCustomerRequestTest.php 0000666 00000005527 15165413756 0016302 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\FetchCustomerRequest; use Omnipay\Mollie\Message\Response\FetchCustomerResponse; use Omnipay\Tests\TestCase; class FetchCustomerRequestTest extends TestCase { use AssertRequestTrait; /** * @var FetchCustomerRequest */ protected $request; public function setUp() { $this->request = new FetchCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'apiKey' => 'mykey', 'customerReference' => 'cst_bSNBBJBzdG', ) ); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertCount(0, $data); } public function testSendSuccess() { $this->setMockHttpResponse('FetchCustomerSuccess.txt'); /** @var FetchCustomerResponse $response */ $response = $this->request->send(); $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); $this->assertJsonStringEqualsJsonString( '{"resource":"customer","id":"cst_bSNBBJBzdG","mode":"test","name":"John Doe","email":"john@doe.com","locale":"nl_NL","metadata":null,"createdAt":"2018-07-19T12:58:47+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_6HUkmjwzBB","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/customers-api\/get-customer","type":"text\/html"}}}', $response->getMessage() ); } public function testSendFailure() { $this->setMockHttpResponse('FetchCustomerFailure.txt'); /** @var FetchCustomerResponse $response */ $response = $this->request->send(); $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); $this->assertSame('{"status":404,"title":"Not Found","detail":"No customer exists with token cst_6HUkmjwzBBa.","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); } } mollie/tests/Message/UpdateCustomerRequestTest.php 0000666 00000007536 15165413756 0016475 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; use Omnipay\Mollie\Message\Response\UpdateCustomerResponse; use Omnipay\Tests\TestCase; class UpdateCustomerRequestTest extends TestCase { use AssertRequestTrait; /** * * @var UpdateCustomerRequest */ protected $request; public function setUp() { $this->request = new UpdateCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey', 'customerReference' => 'cst_bSNBBJBzdG', 'description' => 'Jane Doe', 'email' => 'john@doe.com', 'locale' => 'nl_NL', 'metadata' => 'Just some meta data.', )); } /** * @throws InvalidRequestException */ public function testData() { $this->request->initialize(array( 'apiKey' => 'mykey', 'customerReference' => 'cst_bSNBBJBzdG', 'description' => 'Jane Doe', 'email' => 'john@doe.com', 'metadata' => 'Just some meta data.', )); $data = $this->request->getData(); $this->assertSame("Jane Doe", $data['name']); $this->assertSame('john@doe.com', $data['email']); $this->assertSame('Just some meta data.', $data['metadata']); $this->assertCount(4, $data); } public function testSendSuccess() { $this->setMockHttpResponse('UpdateCustomerSuccess.txt'); /** @var UpdateCustomerResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG", [], '{ "name": "Jane Doe", "email": "john@doe.com", "metadata": "Just some meta data.", "locale": "nl_NL" }' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(UpdateCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); $this->assertJsonStringEqualsJsonString( '{"resource":"customer","id":"cst_bSNBBJBzdG","mode":"test","name":"Jane Doe","email":"john@doe.com","locale":"nl_NL","metadata":"Just some meta data.","createdAt":"2018-07-19T12:58:47+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_6HUkmjwzBB","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/customers-api\/update-customer","type":"text\/html"}}}', $response->getMessage() ); } public function testSendFailure() { $this->setMockHttpResponse('UpdateCustomerFailure.txt'); /** @var UpdateCustomerResponse $response */ $response = $this->request->send(); $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(UpdateCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } } mollie/tests/Message/FetchPaymentMethodsRequestTest.php 0000666 00000010400 15165413756 0017424 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\PaymentMethod; use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; use Omnipay\Mollie\Message\Response\FetchPaymentMethodsResponse; use Omnipay\Tests\TestCase; class FetchPaymentMethodsRequestTest extends TestCase { use AssertRequestTrait; protected static $expectedRequestUri = 'https://api.mollie.com/v2/methods?amount%5Bvalue%5D=22.56&amount%5Bcurrency%5D=SEK&billingCountry=SE&locale=sv_SE&resource=orders&includeWallets=applepay&sequenceType=oneoff'; /** * @var FetchPaymentMethodsRequest */ protected $request; public function setUp() { $this->request = new FetchPaymentMethodsRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize([ 'apiKey' => 'mykey', 'amount' => '22.56', 'billingCountry' => 'SE', 'currency' => 'SEK', 'locale' => 'sv_SE', 'resource' => 'orders', 'sequenceType' => 'oneoff', 'includeWallets' => 'applepay', ]); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame('SEK', $data['amount']['currency']); $this->assertSame('22.56', $data['amount']['value']); $this->assertSame('SE', $data['billingCountry']); $this->assertSame('sv_SE', $data['locale']); $this->assertSame('orders', $data['resource']); $this->assertSame('oneoff', $data['sequenceType']); $this->assertSame('applepay', $data['includeWallets']); } /** * @throws InvalidRequestException */ public function testOptionalParameters() { $this->request->initialize([ 'apiKey' => 'mykey', ]); $this->assertEmpty(array_filter($this->request->getData())); $this->request->send(); $this->assertEqualRequest( new Request('GET', 'https://api.mollie.com/v2/methods'), $this->getMockClient()->getLastRequest() ); } /** * Require both amount and currency when either one is set. * * @throws InvalidRequestException */ public function testRequiredAmountParameters() { $this->expectException(InvalidRequestException::class); $this->request->initialize([ 'apiKey' => 'mykey', 'amount' => '78.02', ]); $this->request->getData(); } public function testSendSuccess() { $this->setMockHttpResponse('FetchPaymentMethodsSuccess.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request('GET', self::$expectedRequestUri), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchPaymentMethodsResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $paymentMethods = $response->getPaymentMethods(); $this->assertCount(12, $paymentMethods); $paymentMethod = new PaymentMethod('ideal', 'iDEAL'); $this->assertEquals($paymentMethod, $paymentMethods[0]); } public function testSendFailure() { $this->setMockHttpResponse('FetchPaymentMethodsFailure.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request('GET', self::$expectedRequestUri), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchPaymentMethodsResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); $this->assertEmpty($response->getPaymentMethods()); } } mollie/tests/Message/FetchOrderRequestTest.php 0000666 00000010457 15165413756 0015552 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Http\ClientInterface; use Omnipay\Mollie\Item; use Omnipay\Mollie\Message\Request\FetchOrderRequest; use Omnipay\Mollie\Message\Request\FetchTransactionRequest; use Omnipay\Mollie\Message\Response\FetchOrderResponse; use Omnipay\Tests\TestCase; use AmeliaPsr\Http\Message\ResponseInterface; class FetchOrderRequestTest extends TestCase { use AssertRequestTrait; /** * @var FetchTransactionRequest */ protected $request; public function setUp() { $this->request = new FetchOrderRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'apiKey' => 'mykey', 'transactionReference' => 'ord_kEn1PlbGa', ) ); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame("ord_kEn1PlbGa", $data['id']); $this->assertCount(1, $data); } public function testSendSuccess() { $this->setMockHttpResponse('FetchOrderSuccess.txt'); /** @var FetchOrderResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( new Request( "GET", "https://api.mollie.com/v2/orders/ord_kEn1PlbGa" ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(FetchOrderResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isPaid()); $this->assertFalse($response->isCancelled()); $this->assertFalse($response->isPaidOut()); $this->assertTrue($response->isRedirect()); $this->assertFalse($response->isRefunded()); $this->assertFalse($response->isPartialRefunded()); $this->assertSame("created", $response->getStatus()); $this->assertSame('ord_kEn1PlbGa', $response->getTransactionReference()); $this->assertSame("1027.99", $response->getAmount()); $this->assertCount(2, $response->getLines()); $line = $response->getLines()[0]; $this->assertSame('5702016116977', $line['sku']); $this->assertSame(2, $line['quantity']); $this->assertSame('0.00', $line['amountShipped']['value']); $this->assertCount(2, $response->getItems()->all()); /** @var Item $item */ $item = $response->getItems()->all()[0]; $this->assertSame('5702016116977', $item->getSku()); $this->assertSame(2, $item->getQuantity()); $this->assertSame('0.00', $item->getAmountShipped()); // We cannot parse _links, rest should match unset($line['_links']); $this->assertSame(array_keys($line), array_keys($item->getParameters())); } public function testSendDataWithIncludingPayments() { $expectedData = ['_embedded' => 'some-payments']; $clientResponse = $this->createMock(ResponseInterface::class); $clientResponse->expects(self::once()) ->method('getBody') ->willReturn(\json_encode($expectedData)); $httpClient = $this->createMock(ClientInterface::class); $httpClient->expects(self::once()) ->method('request') ->with( FetchOrderRequest::GET, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa?embed=payments', $this->callback(function ($headers) { return $headers['Authorization'] == 'Bearer mykey'; }), null )->willReturn($clientResponse); $request = new FetchOrderRequest($httpClient, $this->getHttpRequest()); $request->initialize( [ 'apiKey' => 'mykey', 'transactionReference' => 'ord_kEn1PlbGa', 'includePayments' => true, ] ); $response = $request->sendData(['id' => 'ord_kEn1PlbGa']); self::assertInstanceOf(FetchOrderResponse::class, $response); self::assertEquals($request, $response->getRequest()); self::assertEquals($expectedData, $response->getData()); } } mollie/tests/Message/CreateShipmentRequestTest.php 0000666 00000010043 15165413756 0016427 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Item; use Omnipay\Mollie\Message\Request\CreateCustomerRequest; use Omnipay\Mollie\Message\Request\CreateShipmentRequest; use Omnipay\Mollie\Message\Response\CreateCustomerResponse; use Omnipay\Mollie\Message\Response\CreateShipmentResponse; use Omnipay\Tests\TestCase; class CreateShipmentRequestTest extends TestCase { use AssertRequestTrait; /** * * @var CreateCustomerRequest */ protected $request; public function setUp() { $this->request = new CreateShipmentRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'mykey', 'transactionReference' => 'ord_xxx', 'items' => [ [ 'id' => 'odl_dgtxyl', 'quantity' => 1, ], [ 'id' => 'odl_jp31jz', ] ], 'tracking' => [ 'carrier' => 'PostNL', 'code' => '3SKABA000000000', 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C', ] )); } /** * @throws InvalidRequestException */ public function testData() { $data = $this->request->getData(); $this->assertSame("odl_dgtxyl", $data['lines'][0]['id']); $this->assertSame(1, $data['lines'][0]['quantity']); $this->assertCount(2, $data['lines'][0]); $this->assertSame("odl_jp31jz", $data['lines'][1]['id']); $this->assertCount(1, $data['lines'][1]); $this->assertSame([ 'carrier' => 'PostNL', 'code' => '3SKABA000000000', 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C', ], $data['tracking']); $this->assertCount(2, $data); } public function testSendSuccess() { $this->setMockHttpResponse('CreateShipmentSuccess.txt'); /** @var CreateShipmentResponse $response */ $response = $this->request->send(); $orderId = $this->request->getTransactionReference(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/orders/{$orderId}/shipments", [], '{ "lines": [ { "id": "odl_dgtxyl", "quantity": 1 }, { "id": "odl_jp31jz" } ], "tracking": { "carrier": "PostNL", "code": "3SKABA000000000", "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" } }' ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(CreateShipmentResponse::class, $response); $this->assertSame('shp_3wmsgCJN4U', $response->getTransactionReference()); $this->assertTrue($response->isSuccessful()); $this->assertCount(2, $response->getLines()); $line = $response->getLines()[0]; $this->assertSame('5702016116977', $line['sku']); $this->assertSame(1, $line['quantity']); $this->assertSame('299.00', $line['totalAmount']['value']); $this->assertCount(2, $response->getItems()->all()); /** @var Item $item */ $item = $response->getItems()->all()[0]; $this->assertSame('5702016116977', $item->getSku()); $this->assertSame(1, $item->getQuantity()); $this->assertSame('299.00', $item->getTotalAmount()); // We cannot parse _links, rest should match unset($line['_links']); $this->assertSame(array_keys($line), array_keys($item->getParameters())); } } mollie/tests/Message/CreateOrderRequestTest.php 0000666 00000023374 15165413756 0015726 0 ustar 00 <?php namespace Omnipay\Mollie\Test\Message; use AmeliaGuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\ItemBag; use Omnipay\Mollie\Item; use Omnipay\Mollie\Message\Request\CreateOrderRequest; use Omnipay\Mollie\Message\Request\PurchaseRequest; use Omnipay\Mollie\Message\Response\CreateOrderResponse; use Omnipay\Mollie\Message\Response\PurchaseResponse; use Omnipay\Tests\TestCase; class CreateOrderRequestTest extends TestCase { use AssertRequestTrait; /** * @var CreateOrderRequest */ protected $request; public function setUp() { $this->request = new CreateOrderRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'apiKey' => 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM', 'amount' => '1027.99', 'currency' => 'EUR', 'orderNumber' => '1337', 'lines' => [ [ 'type' => 'physical', 'sku' => '5702016116977', 'name' => 'LEGO 42083 Bugatti Chiron', 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', 'quantity' => 2, 'vatRate' => '21.00', 'unitPrice' => '399.00', 'totalAmount' => '698.00', 'discountAmount' => '100.00', 'vatAmount' => '121.14', ], [ 'type' => 'physical', 'sku' => '5702015594028', 'name' => 'LEGO 42056 Porsche 911 GT3 RS', 'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', 'quantity' => 1, 'vatRate' => '21.00', 'unitPrice' => '329.99', 'totalAmount' => '329.99', 'vatAmount' => '57.27', ], ], 'card' => [ 'company' => 'Mollie B.V.', 'email' => 'norris@chucknorrisfacts.net', 'birthday' => '1958-01-31', 'billingTitle' => 'Dhr', 'billingFirstName' => 'Piet', 'billingLastName' => 'Mondriaan', 'billingAddress1' => 'Keizersgracht 313', 'billingCity' => 'Amsterdam', 'billingPostcode' => '1234AB', 'billingState' => 'Noord-Holland', 'billingCountry' => 'NL', 'billingPhone' => '+31208202070', 'shippingTitle' => 'Mr', 'shippingFirstName' => 'Chuck', 'shippingLastName' => 'Norris', 'shippingAddress1' => 'Prinsengracht 313', 'shippingAddress2' => '4th floor', 'shippingCity' => 'Haarlem', 'shippingPostcode' => '5678AB', 'shippingState' => 'Noord-Holland', 'shippingCountry' => 'NL', ], 'metadata' => [ 'order_id' => '1337', 'description' => 'Lego cars', ], 'locale' => 'nl_NL', 'returnUrl' => 'https://example.org/redirect', 'notifyUrl' => 'https://example.org/webhook', 'paymentMethod' => 'klarnapaylater', 'billingEmail' => 'piet@mondriaan.com', )); } /** * @throws InvalidRequestException */ public function testGetData() { $data = $this->request->getData(); $this->assertSame(["value" => "1027.99", "currency" => "EUR"], $data['amount']); $this->assertSame('1337', $data['orderNumber']); $this->assertSame('https://example.org/redirect', $data['redirectUrl']); $this->assertSame('klarnapaylater', $data['method']); $this->assertSame('Lego cars', $data['metadata']['description']); $this->assertSame('nl_NL', $data['locale']); $this->assertCount(11, $data); } public function testGetAddressData() { $data = $this->request->getData(); $shippingAddress = $data['shippingAddress']; $this->assertSame('Mollie B.V.', $shippingAddress['organizationName']); $this->assertSame('Prinsengracht 313', $shippingAddress['streetAndNumber']); $this->assertSame('4th floor', $shippingAddress['streetAdditional']); $this->assertSame('Haarlem', $shippingAddress['city']); $this->assertSame('Noord-Holland', $shippingAddress['region']); $this->assertSame('5678AB', $shippingAddress['postalCode']); $this->assertSame('NL', $shippingAddress['country']); $this->assertSame('Mr', $shippingAddress['title']); $this->assertSame('Chuck', $shippingAddress['givenName']); $this->assertSame('Norris', $shippingAddress['familyName']); $this->assertSame('norris@chucknorrisfacts.net', $shippingAddress['email']); $billingAddress = $data['billingAddress']; $this->assertSame('Mollie B.V.', $billingAddress['organizationName']); $this->assertSame('Keizersgracht 313', $billingAddress['streetAndNumber']); $this->assertSame('Amsterdam', $billingAddress['city']); $this->assertSame('Noord-Holland', $billingAddress['region']); $this->assertSame('1234AB', $billingAddress['postalCode']); $this->assertSame('NL', $billingAddress['country']); $this->assertSame('Dhr', $billingAddress['title']); $this->assertSame('Piet', $billingAddress['givenName']); $this->assertSame('Mondriaan', $billingAddress['familyName']); $this->assertSame('piet@mondriaan.com', $billingAddress['email']); $this->assertSame('+31208202070', $billingAddress['phone']); } public function testGetLines() { $data = $this->request->getData(); $this->assertCount(2, $data['lines']); $line = $data['lines'][0]; $this->assertSame('physical', $line['type']); $this->assertSame('5702016116977', $line['sku']); $this->assertSame('LEGO 42083 Bugatti Chiron', $line['name']); $this->assertSame('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line['productUrl']); $this->assertSame('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line['imageUrl']); $this->assertSame(2, $line['quantity']); $this->assertSame('21.00', $line['vatRate']); $this->assertSame('399.00', $line['unitPrice']['value']); $this->assertSame('698.00', $line['totalAmount']['value']); $this->assertSame('100.00', $line['discountAmount']['value']); $this->assertSame('121.14', $line['vatAmount']['value']); } public function testDiscountLines() { $this->request->setLines([ [ 'type' => 'physical', 'sku' => '5702016116977', 'name' => 'LEGO 42083 Bugatti Chiron', 'quantity' => 2, 'vatRate' => '21.00', 'unitPrice' => '399.00', 'totalAmount' => '698.00', 'discountAmount' => '100.00', 'vatAmount' => '121.14', ], [ 'type' => 'discount', 'name' => 'Discount 100 EURO', 'quantity' => 1, 'vatRate' => '21.00', 'unitPrice' => '-100.00', 'totalAmount' => '-100.00', 'vatAmount' => '-17.36', ], ]); $this->setMockHttpResponse('CreateOrderSuccess.txt'); $response = $this->request->send(); $this->assertInstanceOf(CreateOrderResponse::class, $response); } public function testSendSuccess() { $this->setMockHttpResponse('CreateOrderSuccess.txt'); $response = $this->request->send(); $this->assertEqualRequest( new Request( "POST", "https://api.mollie.com/v2/orders", [], file_get_contents(__DIR__ . '/../Mock/CreateOrderRequest.txt') ), $this->getMockClient()->getLastRequest() ); $this->assertInstanceOf(CreateOrderResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertSame('https://www.mollie.com/payscreen/order/checkout/pbjz8x', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('ord_pbjz8x', $response->getTransactionReference()); $this->assertSame('created' ,$response->getStatus()); $this->assertTrue($response->isOpen()); $this->assertFalse($response->isPaid()); $this->assertNull($response->getCode()); } public function testSendFailure() { $this->setMockHttpResponse('CreateOrderFailure.txt'); $response = $this->request->send(); $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/orders"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CreateOrderResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } } mollie/tests/Mock/PurchaseIssuerFailure.txt 0000666 00000000530 15165413756 0015115 0 ustar 00 HTTP/1.1 422 Unprocessable Entity Content-Type: application/hal+json; charset=utf-8 { "status": 422, "title": "Unprocessable Entity", "detail": "The payment method is invalid", "field": "method", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/handling-errors", "type": "text/html" } } } mollie/tests/Mock/Refund422Failure.txt 0000666 00000000530 15165413756 0013623 0 ustar 00 HTTP/1.1 422 Unprocessable Entity Content-Type: application/hal+json; charset=utf-8 { "status": 422, "title": "Unprocessable Entity", "detail": "The payment method is invalid", "field": "method", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/handling-errors", "type": "text/html" } } } mollie/tests/Mock/CreateOrderFailure.txt 0000666 00000000525 15165413756 0014353 0 ustar 00 HTTP/1.1 401 Unauthorized Request Content-Type: application/hal+json; charset=utf-8 { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/CompletePurchaseSuccess.txt 0000666 00000002231 15165413756 0015434 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "resource": "payment", "id": "tr_Qzin4iTWrU", "mode": "test", "createdAt": "2018-07-19T12:38:21+00:00", "amount": { "value": "10.00", "currency": "EUR" }, "description": "Order #1234", "method": "ideal", "metadata": null, "status": "paid", "paidAt": "2018-07-19T12:38:34+00:00", "amountRefunded": { "value": "0.00", "currency": "EUR" }, "amountRemaining": { "value": "35.00", "currency": "EUR" }, "locale": "nl_NL", "countryCode": "NL", "profileId": "pfl_7N5qjbu42V", "sequenceType": "oneoff", "redirectUrl": "http://mollie.com", "webhookUrl": "http://mollie.com", "settlementAmount": { "value": "10.00", "currency": "EUR" }, "details": { "consumerName": "T. TEST", "consumerAccount": "NL17RABO0213698412", "consumerBic": "INGBNL2A" }, "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_2bMMNCF5A2", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/payments-api/get-payment", "type": "text/html" } } } mollie/tests/Mock/FetchTransactionExpired.txt 0000666 00000001443 15165413756 0015424 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 { "resource": "payment", "id": "tr_WDqYK6vllg", "mode": "test", "createdAt": "2018-03-12T10:56:15+00:00", "amount": { "value": "1.00", "currency": "EUR" }, "description": "Order 66", "method": null, "metadata": null, "status": "expired", "isCancelable": false, "expiresAt": "2018-03-12T11:11:15+00:00", "details": null, "profileId": "pfl_7N5qjbu42V", "sequenceType": "oneoff", "redirectUrl": "https://www.example.org/payment/completed", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" }, "checkout": { "href": "https://www.mollie.com/payscreen/select-method/PSj7b45bkj" } } } mollie/tests/Mock/FetchIssuersFailure.txt 0000666 00000000526 15165413756 0014564 0 ustar 00 HTTP/1.1 401 Unauthorized Request Content-Type: application/hal+json; charset=utf-8 { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/FetchCustomerMandatesFailure.txt 0000666 00000000475 15165413756 0016410 0 ustar 00 HTTP/1.1 404 Not Found Content-Type: application/hal+json; charset=utf-8 { "status": 404, "title": "Not Found", "detail": "No customer exists with token cst_6HUkmjwzBBa.", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/handling-errors", "type": "text/html" } } } mollie/tests/Mock/UpdateCustomerSuccess.txt 0000666 00000001077 15165413756 0015144 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "resource": "customer", "id": "cst_bSNBBJBzdG", "mode": "test", "name": "Jane Doe", "email": "john@doe.com", "locale": "nl_NL", "metadata": "Just some meta data.", "createdAt": "2018-07-19T12:58:47+00:00", "_links": { "self": { "href": "https://api.mollie.com/v2/customers/cst_6HUkmjwzBB", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/customers-api/update-customer", "type": "text/html" } } } mollie/tests/Mock/PurchaseSuccess.txt 0000666 00000002206 15165413756 0013745 0 ustar 00 HTTP/1.1 201 Created Content-Type: application/hal+json; charset=utf-8 { "resource": "payment", "id": "tr_7UhSN1zuXS", "mode": "test", "createdAt": "2018-03-20T09:13:37+00:00", "amount": { "value": "10.00", "currency": "EUR" }, "description": "My first payment", "method": null, "metadata": { "order_id": "12345" }, "status": "open", "isCancelable": false, "expiresAt": "2018-03-20T09:28:37+00:00", "details": null, "profileId": "pfl_QkEhN94Ba", "sequenceType": "oneoff", "redirectUrl": "https://webshop.example.org/order/12345/", "webhookUrl": "https://webshop.example.org/payments/webhook/", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", "type": "application/json" }, "checkout": { "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", "type": "text/html" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/payments-api/create-payment", "type": "text/html" } } } mollie/tests/Mock/CreateCustomerMandateFailure.txt 0000666 00000000525 15165413756 0016373 0 ustar 00 HTTP/1.1 401 Unauthorized Request Content-Type: application/hal+json; charset=utf-8 { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/CreateShipmentSuccess.txt 0000666 00000006515 15165413756 0015115 0 ustar 00 HTTP/1.1 201 Created Content-Type: application/hal+json { "resource": "shipment", "id": "shp_3wmsgCJN4U", "orderId": "ord_kEn1PlbGa", "createdAt": "2018-08-09T14:33:54+00:00", "tracking": { "carrier": "PostNL", "code": "3SKABA000000000", "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" }, "lines": [ { "resource": "orderline", "id": "odl_dgtxyl", "orderId": "ord_pbjz8x", "name": "LEGO 42083 Bugatti Chiron", "sku": "5702016116977", "type": "physical", "status": "shipping", "isCancelable": true, "quantity": 1, "unitPrice": { "value": "399.00", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "51.89", "currency": "EUR" }, "discountAmount": { "value": "100.00", "currency": "EUR" }, "totalAmount": { "value": "299.00", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", "type": "text/html" } } }, { "resource": "orderline", "id": "odl_jp31jz", "orderId": "ord_pbjz8x", "name": "LEGO 42056 Porsche 911 GT3 RS", "sku": "5702015594028", "type": "physical", "status": "completed", "isCancelable": false, "quantity": 1, "unitPrice": { "value": "329.99", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "57.27", "currency": "EUR" }, "totalAmount": { "value": "329.99", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", "type": "text/html" } } } ], "_links": { "self": { "href": "https://api.mollie.com/v2/order/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U", "type": "application/hal+json" }, "order": { "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment", "type": "text/html" } } } mollie/tests/Mock/FetchTransactionSuccess.txt 0000666 00000002201 15165413756 0015425 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "resource": "payment", "id": "tr_WDqYK6vllg", "mode": "test", "createdAt": "2018-03-20T13:13:37+00:00", "amount": { "value": "10.00", "currency": "EUR" }, "description": "My first payment", "method": null, "metadata": { "order_id": "12345" }, "status": "paid", "isCancelable": false, "expiresAt": "2018-03-20T13:28:37+00:00", "details": null, "profileId": "pfl_QkEhN94Ba", "sequenceType": "oneoff", "redirectUrl": "https://webshop.example.org/order/12345/", "webhookUrl": "https://webshop.example.org/payments/webhook/", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", "type": "application/hal+json" }, "checkout": { "href": "https://www.mollie.com/payscreen/select-method/WDqYK6vllg", "type": "text/html" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/payments-api/get-payment", "type": "text/html" } } } mollie/tests/Mock/CompletePurchaseExpired.txt 0000666 00000001317 15165413756 0015430 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "resource": "payment", "id": "tr_Qzin4iTWrU", "mode": "test", "createdAt": "2018-07-19T12:04:56+00:00", "amount": { "value": "100.00", "currency": "EUR" }, "description": "apex.sh performance test payment", "method": null, "metadata": null, "status": "expired", "expiredAt": "2018-07-19T12:21:04+00:00", "locale": "nl_NL", "profileId": "pfl_7N5qjbu42V", "sequenceType": "oneoff", "redirectUrl": "https://www.example.org/", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_wnUB738Suu", "type": "application/hal+json" } } } mollie/tests/Mock/CreateCustomerFailure.txt 0000666 00000000525 15165413756 0015101 0 ustar 00 HTTP/1.1 401 Unauthorized Request Content-Type: application/hal+json; charset=utf-8 { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/FetchCustomerSuccess.txt 0000666 00000001052 15165413756 0014744 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "resource": "customer", "id": "cst_bSNBBJBzdG", "mode": "test", "name": "John Doe", "email": "john@doe.com", "locale": "nl_NL", "metadata": null, "createdAt": "2018-07-19T12:58:47+00:00", "_links": { "self": { "href": "https://api.mollie.com/v2/customers/cst_6HUkmjwzBB", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", "type": "text/html" } } } mollie/tests/Mock/FetchPaymentMethodsFailure.txt 0000666 00000000525 15165413756 0016067 0 ustar 00 HTTP/1.1 401 Unauthorized Request Content-Type: application/hal+json; charset=utf-8 { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/FetchOrderSuccess.txt 0000666 00000015217 15165413756 0014226 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json { "resource": "order", "id": "ord_kEn1PlbGa", "profileId": "pfl_URR55HPMGx", "method": "ideal", "amount": { "value": "1027.99", "currency": "EUR" }, "status": "created", "isCancelable": true, "metadata": null, "createdAt": "2018-08-02T09:29:56+00:00", "expiresAt": "2018-08-30T09:29:56+00:00", "mode": "live", "locale": "nl_NL", "billingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "postalCode": "1016 EE", "city": "Amsterdam", "country": "nl", "givenName": "Luke", "familyName": "Skywalker", "email": "luke@skywalker.com" }, "orderNumber": "18475", "shippingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "postalCode": "1016 EE", "city": "Amsterdam", "country": "nl", "givenName": "Luke", "familyName": "Skywalker", "email": "luke@skywalker.com" }, "redirectUrl": "https://example.org/redirect", "lines": [ { "resource": "orderline", "id": "odl_dgtxyl", "orderId": "ord_pbjz8x", "name": "LEGO 42083 Bugatti Chiron", "sku": "5702016116977", "type": "physical", "status": "created", "isCancelable": false, "quantity": 2, "quantityShipped": 0, "amountShipped": { "value": "0.00", "currency": "EUR" }, "quantityRefunded": 0, "amountRefunded": { "value": "0.00", "currency": "EUR" }, "quantityCanceled": 0, "amountCanceled": { "value": "0.00", "currency": "EUR" }, "shippableQuantity": 0, "refundableQuantity": 0, "cancelableQuantity": 0, "unitPrice": { "value": "399.00", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "121.14", "currency": "EUR" }, "discountAmount": { "value": "100.00", "currency": "EUR" }, "totalAmount": { "value": "698.00", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", "type": "text/html" } } }, { "resource": "orderline", "id": "odl_jp31jz", "orderId": "ord_pbjz8x", "name": "LEGO 42056 Porsche 911 GT3 RS", "sku": "5702015594028", "type": "physical", "status": "created", "isCancelable": false, "quantity": 1, "quantityShipped": 0, "amountShipped": { "value": "0.00", "currency": "EUR" }, "quantityRefunded": 0, "amountRefunded": { "value": "0.00", "currency": "EUR" }, "quantityCanceled": 0, "amountCanceled": { "value": "0.00", "currency": "EUR" }, "shippableQuantity": 0, "refundableQuantity": 0, "cancelableQuantity": 0, "unitPrice": { "value": "329.99", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "57.27", "currency": "EUR" }, "totalAmount": { "value": "329.99", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", "type": "text/html" } } } ], "_embedded": { "payments": [ { "resource": "payment", "id": "tr_ncaPcAhuUV", "mode": "live", "createdAt": "2018-09-07T12:00:05+00:00", "amount": { "value": "1027.99", "currency": "EUR" }, "description": "Order #1337 (Lego cars)", "method": null, "metadata": null, "status": "open", "isCancelable": false, "locale": "nl_NL", "profileId": "pfl_URR55HPMGx", "orderId": "ord_kEn1PlbGa", "sequenceType": "oneoff", "redirectUrl": "https://example.org/redirect", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_ncaPcAhuUV", "type": "application/hal+json" }, "checkout": { "href": "https://www.mollie.com/payscreen/select-method/ncaPcAhuUV", "type": "text/html" }, "order": { "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", "type": "application/hal+json" } } } ] }, "_links": { "self": { "href": "https://api.mollie.com/v2/orders/ord_pbjz8x", "type": "application/hal+json" }, "checkout": { "href": "https://www.mollie.com/payscreen/order/checkout/pbjz8x", "type": "text/html" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", "type": "text/html" } } } mollie/tests/Mock/CompleteOrderSuccess.txt 0000666 00000015217 15165413756 0014745 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json { "resource": "order", "id": "ord_kEn1PlbGa", "profileId": "pfl_URR55HPMGx", "method": "ideal", "amount": { "value": "1027.99", "currency": "EUR" }, "status": "created", "isCancelable": true, "metadata": null, "createdAt": "2018-08-02T09:29:56+00:00", "expiresAt": "2018-08-30T09:29:56+00:00", "mode": "live", "locale": "nl_NL", "billingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "postalCode": "1016 EE", "city": "Amsterdam", "country": "nl", "givenName": "Luke", "familyName": "Skywalker", "email": "luke@skywalker.com" }, "orderNumber": "18475", "shippingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "postalCode": "1016 EE", "city": "Amsterdam", "country": "nl", "givenName": "Luke", "familyName": "Skywalker", "email": "luke@skywalker.com" }, "redirectUrl": "https://example.org/redirect", "lines": [ { "resource": "orderline", "id": "odl_dgtxyl", "orderId": "ord_pbjz8x", "name": "LEGO 42083 Bugatti Chiron", "sku": "5702016116977", "type": "physical", "status": "created", "isCancelable": false, "quantity": 2, "quantityShipped": 0, "amountShipped": { "value": "0.00", "currency": "EUR" }, "quantityRefunded": 0, "amountRefunded": { "value": "0.00", "currency": "EUR" }, "quantityCanceled": 0, "amountCanceled": { "value": "0.00", "currency": "EUR" }, "shippableQuantity": 0, "refundableQuantity": 0, "cancelableQuantity": 0, "unitPrice": { "value": "399.00", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "121.14", "currency": "EUR" }, "discountAmount": { "value": "100.00", "currency": "EUR" }, "totalAmount": { "value": "698.00", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", "type": "text/html" } } }, { "resource": "orderline", "id": "odl_jp31jz", "orderId": "ord_pbjz8x", "name": "LEGO 42056 Porsche 911 GT3 RS", "sku": "5702015594028", "type": "physical", "status": "created", "isCancelable": false, "quantity": 1, "quantityShipped": 0, "amountShipped": { "value": "0.00", "currency": "EUR" }, "quantityRefunded": 0, "amountRefunded": { "value": "0.00", "currency": "EUR" }, "quantityCanceled": 0, "amountCanceled": { "value": "0.00", "currency": "EUR" }, "shippableQuantity": 0, "refundableQuantity": 0, "cancelableQuantity": 0, "unitPrice": { "value": "329.99", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "57.27", "currency": "EUR" }, "totalAmount": { "value": "329.99", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", "type": "text/html" } } } ], "_embedded": { "payments": [ { "resource": "payment", "id": "tr_ncaPcAhuUV", "mode": "live", "createdAt": "2018-09-07T12:00:05+00:00", "amount": { "value": "1027.99", "currency": "EUR" }, "description": "Order #1337 (Lego cars)", "method": null, "metadata": null, "status": "open", "isCancelable": false, "locale": "nl_NL", "profileId": "pfl_URR55HPMGx", "orderId": "ord_kEn1PlbGa", "sequenceType": "oneoff", "redirectUrl": "https://example.org/redirect", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_ncaPcAhuUV", "type": "application/hal+json" }, "checkout": { "href": "https://www.mollie.com/payscreen/select-method/ncaPcAhuUV", "type": "text/html" }, "order": { "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", "type": "application/hal+json" } } } ] }, "_links": { "self": { "href": "https://api.mollie.com/v2/orders/ord_pbjz8x", "type": "application/hal+json" }, "checkout": { "href": "https://www.mollie.com/payscreen/order/checkout/pbjz8x", "type": "text/html" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", "type": "text/html" } } } mollie/tests/Mock/FetchTransaction404Failure.txt 0000666 00000000476 15165413756 0015650 0 ustar 00 HTTP/1.1 404 Not Found Content-Type: application/hal+json; charset=utf-8 { "status": 404, "title": "Not Found", "detail": "No transaction exists with token tr_Qzin4iTWrU.", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/handling-errors", "type": "text/html" } } } mollie/tests/Mock/CreateOrderRequest.txt 0000666 00000006200 15165413756 0014410 0 ustar 00 { "amount": { "value": "1027.99", "currency": "EUR" }, "billingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "city": "Amsterdam", "region": "Noord-Holland", "postalCode": "1234AB", "country": "NL", "title": "Dhr", "givenName": "Piet", "familyName": "Mondriaan", "email": "piet@mondriaan.com", "phone": "+31208202070" }, "shippingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Prinsengracht 313", "streetAdditional": "4th floor", "city": "Haarlem", "region": "Noord-Holland", "postalCode": "5678AB", "country": "NL", "title": "Mr", "givenName": "Chuck", "familyName": "Norris", "email": "norris@chucknorrisfacts.net" }, "metadata": { "order_id": "1337", "description": "Lego cars" }, "consumerDateOfBirth": "1958-01-31", "locale": "nl_NL", "orderNumber": "1337", "redirectUrl": "https://example.org/redirect", "webhookUrl": "https://example.org/webhook", "method": "klarnapaylater", "lines": [ { "type": "physical", "sku": "5702016116977", "name": "LEGO 42083 Bugatti Chiron", "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", "quantity": 2, "vatRate": "21.00", "unitPrice": { "currency": "EUR", "value": "399.00" }, "totalAmount": { "currency": "EUR", "value": "698.00" }, "discountAmount": { "currency": "EUR", "value": "100.00" }, "vatAmount": { "currency": "EUR", "value": "121.14" } }, { "type": "physical", "sku": "5702015594028", "name": "LEGO 42056 Porsche 911 GT3 RS", "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", "quantity": 1, "vatRate": "21.00", "unitPrice": { "currency": "EUR", "value": "329.99" }, "totalAmount": { "currency": "EUR", "value": "329.99" }, "vatAmount": { "currency": "EUR", "value": "57.27" } } ] } mollie/tests/Mock/Refund401Failure.txt 0000666 00000001311 15165413756 0013616 0 ustar 00 HTTP/1.1 401 Authorization Required Server: nginx/1.4.4 Date: Mon, 20 Jan 2014 10:04:18 GMT Content-Type: application/json; charset=utf-8 Content-Length: 155 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store Strict-Transport-Security: max-age=31556926; includeSubDomains Www-Authenticate: Basic realm="Mollie API Key" { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/CreateCustomerMandateSuccess.txt 0000666 00000001707 15165413756 0016417 0 ustar 00 HTTP/1.1 201 Created Content-Type: application/json; charset=utf-8 { "resource": "mandate", "id": "mdt_h3gAaD5zP", "mode": "test", "status": "valid", "method": "directdebit", "details": { "consumerName": "John Doe", "consumerAccount": "NL55INGB0000000000", "consumerBic": "INGBNL2A" }, "mandateReference": "YOUR-COMPANY-MD13804", "signatureDate": "2018-05-07", "createdAt": "2018-05-07T10:49:08+00:00", "_links": { "self": { "href": "https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP", "type": "application/hal+json" }, "customer": { "href": "https://api.mollie.com/v2/customers/cst_4qqhO89gsT", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/mandates-api/create-mandate", "type": "text/html" } } } mollie/tests/Mock/RevokeCustomerMandateSuccess.txt 0000666 00000000031 15165413756 0016434 0 ustar 00 HTTP/1.1 204 No Content mollie/tests/Mock/FetchPaymentMethodsSuccess.txt 0000666 00000014012 15165413756 0016104 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "_embedded": { "methods": [ { "resource": "method", "id": "ideal", "description": "iDEAL", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/ideal", "type": "application/hal+json" } } }, { "resource": "method", "id": "creditcard", "description": "Credit card", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/creditcard.png", "size2x": "https://www.mollie.com/images/payscreen/methods/creditcard%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/creditcard", "type": "application/hal+json" } } }, { "resource": "method", "id": "paypal", "description": "PayPal", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/paypal.png", "size2x": "https://www.mollie.com/images/payscreen/methods/paypal%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/paypal", "type": "application/hal+json" } } }, { "resource": "method", "id": "bancontact", "description": "Bancontact", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/mistercash.png", "size2x": "https://www.mollie.com/images/payscreen/methods/mistercash%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/mistercash", "type": "application/hal+json" } } }, { "resource": "method", "id": "banktransfer", "description": "Bank transfer", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/banktransfer.png", "size2x": "https://www.mollie.com/images/payscreen/methods/banktransfer%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/banktransfer", "type": "application/hal+json" } } }, { "resource": "method", "id": "sofort", "description": "SOFORT Banking", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/sofort.png", "size2x": "https://www.mollie.com/images/payscreen/methods/sofort%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/sofort", "type": "application/hal+json" } } }, { "resource": "method", "id": "eps", "description": "eps", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/eps.png", "size2x": "https://www.mollie.com/images/payscreen/methods/eps%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/eps", "type": "application/hal+json" } } }, { "resource": "method", "id": "giropay", "description": "Giropay", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/giropay.png", "size2x": "https://www.mollie.com/images/payscreen/methods/giropay%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/giropay", "type": "application/hal+json" } } }, { "resource": "method", "id": "kbc", "description": "KBC/CBC Payment Button", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/kbc.png", "size2x": "https://www.mollie.com/images/payscreen/methods/kbc%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/kbc", "type": "application/hal+json" } } }, { "resource": "method", "id": "belfius", "description": "Belfius Pay Button", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/belfius.png", "size2x": "https://www.mollie.com/images/payscreen/methods/belfius%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/belfius", "type": "application/hal+json" } } }, { "resource": "method", "id": "inghomepay", "description": "ING Home'Pay", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/inghomepay.png", "size2x": "https://www.mollie.com/images/payscreen/methods/inghomepay%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/inghomepay", "type": "application/hal+json" } } }, { "resource": "method", "id": "bitcoin", "description": "Bitcoin", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/bitcoin.png", "size2x": "https://www.mollie.com/images/payscreen/methods/bitcoin%402x.png" }, "_links": { "self": { "href": "https://api.mollie.com/v2/methods/bitcoin", "type": "application/hal+json" } } } ] }, "count": 12, "_links": { "documentation": { "href": "https://docs.mollie.com/reference/v2/methods-api/list-methods", "type": "text/html" }, "self": { "href": "https://api.mollie.nl/v2/methods", "type": "application/hal+json" } } } mollie/tests/Mock/RefundSuccess.txt 0000666 00000002212 15165413756 0013413 0 ustar 00 HTTP/1.1 201 Created Server: nginx/1.4.4 Date: Sun, 19 Jan 2014 11:41:55 GMT Content-Type: application/json; charset=utf-8 Content-Length: 344 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store Strict-Transport-Security: max-age=31556926; includeSubDomains X-Whom: dc1-web-2 { "resource": "refund", "id": "re_4qqhO89gsT", "amount": { "currency": "EUR", "value": "5.95" }, "status": "pending", "createdAt": "2018-03-14T17:09:02.0Z", "description": "Order", "paymentId": "tr_WDqYK6vllg", "_links": { "self": { "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", "type": "application/hal+json" }, "payment": { "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/refunds-api/create-refund", "type": "text/html" } } } mollie/tests/Mock/CreateCustomerSuccess.txt 0000666 00000001104 15165413756 0015114 0 ustar 00 HTTP/1.1 201 Created Content-Type: application/hal+json; charset=utf-8 { "resource": "customer", "id": "cst_bSNBBJBzdG", "mode": "test", "name": "John Doe", "email": "john@doe.com", "locale": "nl_NL", "metadata": "Just some meta data.", "createdAt": "2018-07-19T12:58:47+00:00", "_links": { "self": { "href": "https://api.mollie.com/v2/customers/cst_6HUkmjwzBB", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/customers-api/create-customer", "type": "text/html" } } } mollie/tests/Mock/FetchCustomerFailure.txt 0000666 00000000475 15165413756 0014733 0 ustar 00 HTTP/1.1 404 Not Found Content-Type: application/hal+json; charset=utf-8 { "status": 404, "title": "Not Found", "detail": "No customer exists with token cst_6HUkmjwzBBa.", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/handling-errors", "type": "text/html" } } } mollie/tests/Mock/CreateOrderSuccess.txt 0000666 00000012651 15165413756 0014377 0 ustar 00 HTTP/1.1 201 Created Content-Type: application/hal+json; charset=utf-8 { "resource": "order", "id": "ord_pbjz8x", "profileId": "pfl_URR55HPMGx", "method": "klarnapaylater", "amount": { "value": "1027.99", "currency": "EUR" }, "status": "created", "isCancelable": true, "metadata": { "order_id": "1337", "description": "Lego cars" }, "createdAt": "2018-08-02T09:29:56+00:00", "expiresAt": "2018-08-30T09:29:56+00:00", "mode": "test", "locale": "nl_NL", "billingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "city": "Amsterdam", "region": "Noord-Holland", "postalCode": "1234AB", "country": "NL", "title": "Dhr.", "givenName": "Piet", "familyName": "Mondriaan", "email": "piet@mondriaan.com", "phone": "+31309202070" }, "consumerDateOfBirth": "1958-01-31", "orderNumber": "1337", "shippingAddress": { "organizationName": "Mollie B.V.", "streetAndNumber": "Keizersgracht 313", "streetAdditional": "4th floor", "city": "Haarlem", "region": "Noord-Holland", "postalCode": "5678AB", "country": "NL", "title": "Mr.", "givenName": "Chuck", "familyName": "Norris", "email": "norris@chucknorrisfacts.net" }, "redirectUrl": "https://example.org/redirect", "webhookUrl": "https://example.org/webhook", "lines": [ { "resource": "orderline", "id": "odl_dgtxyl", "orderId": "ord_pbjz8x", "name": "LEGO 42083 Bugatti Chiron", "sku": "5702016116977", "type": "physical", "status": "created", "isCancelable": false, "quantity": 2, "quantityShipped": 0, "amountShipped": { "value": "0.00", "currency": "EUR" }, "quantityRefunded": 0, "amountRefunded": { "value": "0.00", "currency": "EUR" }, "quantityCanceled": 0, "amountCanceled": { "value": "0.00", "currency": "EUR" }, "shippableQuantity": 0, "refundableQuantity": 0, "cancelableQuantity": 0, "unitPrice": { "value": "399.00", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "121.14", "currency": "EUR" }, "discountAmount": { "value": "100.00", "currency": "EUR" }, "totalAmount": { "value": "698.00", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", "type": "text/html" } } }, { "resource": "orderline", "id": "odl_jp31jz", "orderId": "ord_pbjz8x", "name": "LEGO 42056 Porsche 911 GT3 RS", "sku": "5702015594028", "type": "physical", "status": "created", "isCancelable": false, "quantity": 1, "quantityShipped": 0, "amountShipped": { "value": "0.00", "currency": "EUR" }, "quantityRefunded": 0, "amountRefunded": { "value": "0.00", "currency": "EUR" }, "quantityCanceled": 0, "amountCanceled": { "value": "0.00", "currency": "EUR" }, "shippableQuantity": 0, "refundableQuantity": 0, "cancelableQuantity": 0, "unitPrice": { "value": "329.99", "currency": "EUR" }, "vatRate": "21.00", "vatAmount": { "value": "57.27", "currency": "EUR" }, "totalAmount": { "value": "329.99", "currency": "EUR" }, "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "productUrl": { "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", "type": "text/html" }, "imageUrl": { "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", "type": "text/html" } } } ], "_links": { "self": { "href": "https://api.mollie.com/v2/orders/ord_pbjz8x", "type": "application/hal+json" }, "checkout": { "href": "https://www.mollie.com/payscreen/order/checkout/pbjz8x", "type": "text/html" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", "type": "text/html" } } } mollie/tests/Mock/UpdateCustomerFailure.txt 0000666 00000000526 15165413756 0015121 0 ustar 00 HTTP/1.1 401 Unauthorized Request Content-Type: application/hal+json; charset=utf-8 { "status": 401, "title": "Unauthorized Request", "detail": "Missing authentication, or failed to authenticate", "_links": { "documentation": { "href": "https://docs.mollie.com/guides/authentication", "type": "text/html" } } } mollie/tests/Mock/FetchCustomerMandatesSuccess.txt 0000666 00000003710 15165413756 0016424 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "count": 5, "_embedded": { "mandates": [ { "resource": "mandate", "id": "mdt_AcQl5fdL4h", "mode": "test", "status": "valid", "method": "directdebit", "details": { "consumerName": "John Doe", "consumerAccount": "NL55INGB0000000000", "consumerBic": "INGBNL2A" }, "mandateReference": null, "signatureDate": "2018-05-07", "createdAt": "2018-05-07T10:49:08+00:00", "_links": { "self": { "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates/mdt_AcQl5fdL4h", "type": "application/hal+json" }, "customer": { "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U", "type": "application/hal+json" }, "documentation": { "href": "https://mollie.com/en/docs/reference/customers/create-mandate", "type": "text/html" } } }, { }, { }, { }, { } ] }, "_links": { "self": { "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates?limit=5", "type": "application/hal+json" }, "previous": null, "next": { "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates?from=mdt_AcQl5fdL4h&limit=5", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/mandates-api/revoke-mandate", "type": "text/html" } } } mollie/tests/Mock/FetchIssuersSuccess.txt 0000666 00000002624 15165413756 0014606 0 ustar 00 HTTP/1.1 200 OK Content-Type: application/hal+json; charset=utf-8 { "resource": "method", "id": "ideal", "description": "iDEAL", "image": { "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" }, "issuers": [ { "resource": "issuer", "id": "ideal_ABNANL2A", "name": "ABN AMRO", "image": { "size1x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/ABNANL2A.png", "size2x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/ABNANL2A.png" } }, { "resource": "issuer", "id": "ideal_ASNBNL21", "name": "ASN Bank", "image": { "size1x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/ASNBNL21.png", "size2x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/ASNBNL21.png" } } ], "_links": { "self": { "href": "https://api.mollie.com/v2/methods/ideal", "type": "application/hal+json" }, "documentation": { "href": "https://docs.mollie.com/reference/v2/methods-api/get-method", "type": "text/html" } } } mollie/tests/GatewayTest.php 0000666 00000014671 15165413756 0012173 0 ustar 00 <?php namespace Omnipay\Mollie\Test; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Gateway; use Omnipay\Mollie\Message\Request\CancelOrderRequest; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Request\CreateCustomerMandateRequest; use Omnipay\Mollie\Message\Request\CreateCustomerRequest; use Omnipay\Mollie\Message\Request\FetchCustomerMandatesRequest; use Omnipay\Mollie\Message\Request\FetchCustomerRequest; use Omnipay\Mollie\Message\Request\FetchIssuersRequest; use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; use Omnipay\Mollie\Message\Request\FetchTransactionRequest; use Omnipay\Mollie\Message\Request\PurchaseRequest; use Omnipay\Mollie\Message\Request\RefundRequest; use Omnipay\Mollie\Message\Request\RevokeCustomerMandateRequest; use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; use Omnipay\Tests\GatewayTestCase; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class GatewayTest extends GatewayTestCase { /** * @var Gateway */ protected $gateway; public function setUp() { parent::setUp(); $this->gateway = new Gateway(); } public function testFetchIssuers() { $request = $this->gateway->fetchIssuers(); $this->assertInstanceOf(FetchIssuersRequest::class, $request); } public function testFetchPaymentMethods() { $request = $this->gateway->fetchPaymentMethods(); $this->assertInstanceOf(FetchPaymentMethodsRequest::class, $request); } /** * @throws InvalidRequestException */ public function testPurchase() { $request = $this->gateway->purchase(array('amount' => '10.00', 'currency' => 'EUR')); $this->assertInstanceOf(PurchaseRequest::class, $request); $this->assertSame('10.00', $request->getAmount()); $this->assertSame('EUR', $request->getCurrency()); } /** * @throws InvalidRequestException */ public function testPurchaseReturn() { $request = $this->gateway->completePurchase(array('amount' => '10.00', 'currency' => 'EUR')); $this->assertInstanceOf(CompletePurchaseRequest::class, $request); $this->assertSame('10.00', $request->getAmount()); $this->assertSame('EUR', $request->getCurrency()); } public function testRefund() { $request = $this->gateway->refund( array( 'apiKey' => 'key', 'transactionReference' => 'tr_Qzin4iTWrU', 'amount' => '10.00', 'currency' => 'EUR' ) ); $this->assertInstanceOf(RefundRequest::class, $request); $data = $request->getData(); $this->assertSame( [ 'value' => '10.00', 'currency' => 'EUR' ], $data['amount'] ); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException */ public function testThatRefundDoesntWorkWithoutAmount() { $request = $this->gateway->refund( array( 'apiKey' => 'key', 'transactionReference' => 'tr_Qzin4iTWrU' ) ); $this->assertInstanceOf(RefundRequest::class, $request); $request->getData(); } public function testFetchTransaction() { $request = $this->gateway->fetchTransaction( array( 'apiKey' => 'key', 'transactionReference' => 'tr_Qzin4iTWrU', ) ); $this->assertInstanceOf(FetchTransactionRequest::class, $request); $data = $request->getData(); $this->assertSame('tr_Qzin4iTWrU', $data['id']); } public function testCreateCustomer() { $request = $this->gateway->createCustomer( array( 'description' => 'Test name', 'email' => 'test@example.com', 'metadata' => 'Something something something dark side.', 'locale' => 'nl_NL', ) ); $this->assertInstanceOf(CreateCustomerRequest::class, $request); } public function testUpdateCustomer() { $request = $this->gateway->updateCustomer( array( 'apiKey' => 'key', 'customerReference' => 'cst_bSNBBJBzdG', 'description' => 'Test name2', 'email' => 'test@example.com', 'metadata' => 'Something something something dark side.', 'locale' => 'nl_NL', ) ); $this->assertInstanceOf(UpdateCustomerRequest::class, $request); $data = $request->getData(); $this->assertSame('Test name2', $data['name']); } public function testFetchCustomer() { $request = $this->gateway->fetchCustomer( array( 'apiKey' => 'key', 'customerReference' => 'cst_bSNBBJBzdG', ) ); $this->assertInstanceOf(FetchCustomerRequest::class, $request); } public function testFetchCustomerMandates() { $request = $this->gateway->fetchCustomerMandates( array( 'apiKey' => 'key', 'customerReference' => 'cst_bSNBBJBzdG', ) ); $this->assertInstanceOf(FetchCustomerMandatesRequest::class, $request); } public function testRevokeCustomerMandate() { $request = $this->gateway->revokeCustomerMandate( array( 'apiKey' => "key", "customerReference" => "cst_bSNBBJBzdG", "mandateId" => "mdt_pWUnw6pkBN", ) ); $this->assertInstanceOf(RevokeCustomerMandateRequest::class, $request); } public function testCreateCustomerMandate() { $request = $this->gateway->createCustomerMandate( array( 'apiKey' => "mykey", 'consumerName' => "Customer A", 'consumerAccount' => "NL53INGB0000000000", "method" => "directdebit", 'customerReference' => 'cst_bSNBBJBzdG', 'mandateReference' => "YOUR-COMPANY-MD13804", ) ); $this->assertInstanceOf(CreateCustomerMandateRequest::class, $request); } public function testVoid() { $this->assertInstanceOf(CancelOrderRequest::class, $this->gateway->void()); } } mollie/LICENSE 0000666 00000002047 15165413756 0007056 0 ustar 00 Copyright (c) 2012-2013 Adrian Macneil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. common/grumphp.yml 0000666 00000000530 15165413756 0010260 0 ustar 00 parameters: git_dir: . bin_dir: vendor/bin tasks: phpunit: config_file: ~ testsuite: ~ group: [] always_execute: false phpcs: standard: PSR2 warning_severity: ~ ignore_patterns: - tests/ triggered_by: [php] common/LICENSE 0000666 00000002035 15165413756 0007062 0 ustar 00 Copyright (c) Adrian Macneil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. common/composer.json 0000666 00000003527 15165413756 0010606 0 ustar 00 { "name": "omnipay/common", "type": "library", "description": "Common components for Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "purchase" ], "homepage": "https://github.com/thephpleague/omnipay-common", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Barry vd. Heuvel", "email": "barryvdh@gmail.com" }, { "name": "Jason Judge", "email": "jason.judge@consil.co.uk" }, { "name": "Del" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-common/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Common\\" : "src/Common" }, "classmap": ["src/Omnipay.php"] }, "require": { "php": "^5.6|^7", "php-http/client-implementation": "^1", "php-http/message": "^1.5", "php-http/discovery": "^1.2.1", "symfony/http-foundation": "^2.1|^3|^4|^5", "moneyphp/money": "^3.1" }, "require-dev": { "omnipay/tests": "^3", "php-http/mock-client": "^1", "squizlabs/php_codesniffer": "^3.5", "phpro/grumphp": "^0.14" }, "extra": { "branch-alias": { "dev-master": "3.0.x-dev" } }, "suggest": { "league/omnipay": "The default Omnipay package provides a default HTTP Adapter." }, "scripts": { "test": "phpunit", "check-style": "phpcs -p --standard=PSR2 src/", "fix-style": "phpcbf -p --standard=PSR2 src/" }, "minimum-stability": "dev", "prefer-stable": true } common/src/Omnipay.php 0000666 00000006126 15165413756 0010776 0 ustar 00 <?php /** * Omnipay class */ namespace Omnipay; use Omnipay\Common\GatewayFactory; use Omnipay\Common\Http\ClientInterface; /** * Omnipay class * * Provides static access to the gateway factory methods. This is the * recommended route for creation and establishment of payment gateway * objects via the standard GatewayFactory. * * Example: * * <code> * // Create a gateway for the PayPal ExpressGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('ExpressGateway'); * * // Initialise the gateway * $gateway->initialize(...); * * // Get the gateway parameters. * $parameters = $gateway->getParameters(); * * // Create a credit card object * $card = new CreditCard(...); * * // Do an authorisation transaction on the gateway * if ($gateway->supportsAuthorize()) { * $gateway->authorize(...); * } else { * throw new \Exception('Gateway does not support authorize()'); * } * </code> * * For further code examples see the *omnipay-example* repository on github. * * @method static array all() * @method static array replace(array $gateways) * @method static string register(string $className) * @method static array find() * @method static array getSupportedGateways() * @codingStandardsIgnoreStart * @method static \Omnipay\Common\GatewayInterface create(string $class, ClientInterface $httpClient = null, \Symfony\Component\HttpFoundation\Request $httpRequest = null) * @codingStandardsIgnoreEnd * * @see \Omnipay\Common\GatewayFactory */ class Omnipay { /** * Internal factory storage * * @var GatewayFactory */ private static $factory; /** * Get the gateway factory * * Creates a new empty GatewayFactory if none has been set previously. * * @return GatewayFactory A GatewayFactory instance */ public static function getFactory() { if (is_null(self::$factory)) { self::$factory = new GatewayFactory; } return self::$factory; } /** * Set the gateway factory * * @param GatewayFactory $factory A GatewayFactory instance */ public static function setFactory(GatewayFactory $factory = null) { self::$factory = $factory; } /** * Static function call router. * * All other function calls to the Omnipay class are routed to the * factory. e.g. Omnipay::getSupportedGateways(1, 2, 3, 4) is routed to the * factory's getSupportedGateways method and passed the parameters 1, 2, 3, 4. * * Example: * * <code> * // Create a gateway for the PayPal ExpressGateway * $gateway = Omnipay::create('ExpressGateway'); * </code> * * @see GatewayFactory * * @param string $method The factory method to invoke. * @param array $parameters Parameters passed to the factory method. * * @return mixed */ public static function __callStatic($method, $parameters) { $factory = self::getFactory(); return call_user_func_array(array($factory, $method), $parameters); } } common/src/Common/ParametersTrait.php 0000666 00000003727 15165413756 0013725 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Common\Exception\InvalidRequestException; use Symfony\Component\HttpFoundation\ParameterBag; trait ParametersTrait { /** * Internal storage of all of the parameters. * * @var ParameterBag */ protected $parameters; /** * Set one parameter. * * @param string $key Parameter key * @param mixed $value Parameter value * @return $this */ protected function setParameter($key, $value) { $this->parameters->set($key, $value); return $this; } /** * Get one parameter. * * @param string $key Parameter key * @return mixed A single parameter value. */ protected function getParameter($key) { return $this->parameters->get($key); } /** * Get all parameters. * * @return array An associative array of parameters. */ public function getParameters() { return $this->parameters->all(); } /** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * @return $this. */ public function initialize(array $parameters = []) { $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } /** * Validate the request. * * This method is called internally by gateways to avoid wasting time with an API call * when the request is clearly invalid. * * @param string ... a variable length list of required parameters * @throws InvalidRequestException */ public function validate(...$args) { foreach ($args as $key) { $value = $this->parameters->get($key); if (! isset($value)) { throw new InvalidRequestException("The $key parameter is required"); } } } } common/src/Common/GatewayFactory.php 0000666 00000004367 15165413756 0013550 0 ustar 00 <?php /** * Omnipay Gateway Factory class */ namespace Omnipay\Common; use Omnipay\Common\Exception\RuntimeException; use Omnipay\Common\Http\ClientInterface; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Omnipay Gateway Factory class * * This class abstracts a set of gateways that can be independently * registered, accessed, and used. * * Note that static calls to the Omnipay class are routed to this class by * the static call router (__callStatic) in Omnipay. * * Example: * * <code> * // Create a gateway for the PayPal ExpressGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('ExpressGateway'); * </code> * */ class GatewayFactory { /** * Internal storage for all available gateways * * @var array */ private $gateways = array(); /** * All available gateways * * @return array An array of gateway names */ public function all() { return $this->gateways; } /** * Replace the list of available gateways * * @param array $gateways An array of gateway names */ public function replace(array $gateways) { $this->gateways = $gateways; } /** * Register a new gateway * * @param string $className Gateway name */ public function register($className) { if (!in_array($className, $this->gateways)) { $this->gateways[] = $className; } } /** * Create a new gateway instance * * @param string $class Gateway name * @param ClientInterface|null $httpClient A HTTP Client implementation * @param HttpRequest|null $httpRequest A Symfony HTTP Request implementation * @throws RuntimeException If no such gateway is found * @return GatewayInterface An object of class $class is created and returned */ public function create($class, ClientInterface $httpClient = null, HttpRequest $httpRequest = null) { $class = Helper::getGatewayClassName($class); if (!class_exists($class)) { throw new RuntimeException("Class '$class' not found"); } return new $class($httpClient, $httpRequest); } } common/src/Common/CreditCard.php 0000666 00000102531 15165413756 0012613 0 ustar 00 <?php /** * Credit Card class */ namespace Omnipay\Common; use DateTime; use DateTimeZone; use Omnipay\Common\Exception\InvalidCreditCardException; use Symfony\Component\HttpFoundation\ParameterBag; /** * Credit Card class * * This class defines and abstracts all of the credit card types used * throughout the Omnipay system. * * Example: * * <code> * // Define credit card parameters, which should look like this * $parameters = [ * 'firstName' => 'Bobby', * 'lastName' => 'Tables', * 'number' => '4444333322221111', * 'cvv' => '123', * 'expiryMonth' => '12', * 'expiryYear' => '2017', * 'email' => 'testcard@gmail.com', * ]; * * // Create a credit card object * $card = new CreditCard($parameters); * </code> * * The full list of card attributes that may be set via the parameter to * *new* is as follows: * * * title * * firstName * * lastName * * name * * company * * address1 * * address2 * * city * * postcode * * state * * country * * phone * * phoneExtension * * fax * * number * * expiryMonth * * expiryYear * * startMonth * * startYear * * cvv * * tracks * * issueNumber * * billingTitle * * billingName * * billingFirstName * * billingLastName * * billingCompany * * billingAddress1 * * billingAddress2 * * billingCity * * billingPostcode * * billingState * * billingCountry * * billingPhone * * billingFax * * shippingTitle * * shippingName * * shippingFirstName * * shippingLastName * * shippingCompany * * shippingAddress1 * * shippingAddress2 * * shippingCity * * shippingPostcode * * shippingState * * shippingCountry * * shippingPhone * * shippingFax * * email * * birthday * * gender * * If any unknown parameters are passed in, they will be ignored. No error is thrown. */ class CreditCard { use ParametersTrait; const BRAND_VISA = 'visa'; const BRAND_MASTERCARD = 'mastercard'; const BRAND_DISCOVER = 'discover'; const BRAND_AMEX = 'amex'; const BRAND_DINERS_CLUB = 'diners_club'; const BRAND_JCB = 'jcb'; const BRAND_SWITCH = 'switch'; const BRAND_SOLO = 'solo'; const BRAND_DANKORT = 'dankort'; const BRAND_MAESTRO = 'maestro'; const BRAND_FORBRUGSFORENINGEN = 'forbrugsforeningen'; const BRAND_LASER = 'laser'; /** * All known/supported card brands, and a regular expression to match them. * * The order of the card brands is important, as some of the regular expressions overlap. * * Note: The fact that a particular card brand has been added to this array does not imply * that a selected gateway will support the card. * * @link https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb * @var array */ const REGEX_MASTERCARD = '/^(5[1-5]\d{4}|677189)\d{10}$|^2(?:2(?:2[1-9]|[3-9]\d)|[3-6]\d\d|7(?:[01]\d|20))\d{12}$/'; protected $supported_cards = array( self::BRAND_VISA => '/^4\d{12}(\d{3})?$/', self::BRAND_MASTERCARD => self::REGEX_MASTERCARD, self::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/', self::BRAND_AMEX => '/^3[47]\d{13}$/', self::BRAND_DINERS_CLUB => '/^3(0[0-5]|[68]\d)\d{11}$/', self::BRAND_JCB => '/^35(28|29|[3-8]\d)\d{12}$/', self::BRAND_SWITCH => '/^6759\d{12}(\d{2,3})?$/', self::BRAND_SOLO => '/^6767\d{12}(\d{2,3})?$/', self::BRAND_DANKORT => '/^5019\d{12}$/', self::BRAND_MAESTRO => '/^(5[06-8]|6\d)\d{10,17}$/', self::BRAND_FORBRUGSFORENINGEN => '/^600722\d{10}$/', self::BRAND_LASER => '/^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/', ); /** * Create a new CreditCard object using the specified parameters * * @param array $parameters An array of parameters to set on the new object */ public function __construct($parameters = null) { $this->initialize($parameters); } /** * All known/supported card brands, and a regular expression to match them. * * Note: The fact that this class knows about a particular card brand does not imply * that your gateway supports it. * * @return array */ public function getSupportedBrands() { return $this->supported_cards; } /** * Set a custom supported card brand with a regular expression to match it. * * Note: The fact that a particular card is known does not imply that your * gateway supports it. * * Set $add_to_front to true if the key should be added to the front of the array * * @param string $name The name of the new supported brand. * @param string $expression The regular expression to check if a card is supported. * @return boolean success */ public function addSupportedBrand($name, $expression) { $known_brands = array_keys($this->supported_cards); if (in_array($name, $known_brands)) { return false; } $this->supported_cards[$name] = $expression; return true; } /** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * @return $this */ public function initialize(array $parameters = null) { $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } /** * Set the credit card year. * * The input value is normalised to a 4 digit number. * * @param string $key Parameter key, e.g. 'expiryYear' * @param mixed $value Parameter value * @return $this */ protected function setYearParameter($key, $value) { // normalize year to four digits if (null === $value || '' === $value) { $value = null; } else { $value = (int) gmdate('Y', gmmktime(0, 0, 0, 1, 1, (int) $value)); } return $this->setParameter($key, $value); } /** * Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown. * * This method is called internally by gateways to avoid wasting time with an API call * when the credit card is clearly invalid. * * Generally if you want to validate the credit card yourself with custom error * messages, you should use your framework's validation library, not this method. * * @return void * @throws Exception\InvalidRequestException * @throws InvalidCreditCardException */ public function validate() { $requiredParameters = array( 'number' => 'credit card number', 'expiryMonth' => 'expiration month', 'expiryYear' => 'expiration year' ); foreach ($requiredParameters as $key => $val) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The $val is required"); } } if ($this->getExpiryDate('Ym') < gmdate('Ym')) { throw new InvalidCreditCardException('Card has expired'); } if (!Helper::validateLuhn($this->getNumber())) { throw new InvalidCreditCardException('Card number is invalid'); } if (!is_null($this->getNumber()) && !preg_match('/^\d{12,19}$/i', $this->getNumber())) { throw new InvalidCreditCardException('Card number should have 12 to 19 digits'); } } /** * Get Card Title. * * @return string */ public function getTitle() { return $this->getBillingTitle(); } /** * Set Card Title. * * @param string $value Parameter value * @return $this */ public function setTitle($value) { $this->setBillingTitle($value); $this->setShippingTitle($value); return $this; } /** * Get Card First Name. * * @return string */ public function getFirstName() { return $this->getBillingFirstName(); } /** * Set Card First Name (Billing and Shipping). * * @param string $value Parameter value * @return $this */ public function setFirstName($value) { $this->setBillingFirstName($value); $this->setShippingFirstName($value); return $this; } /** * Get Card Last Name. * * @return string */ public function getLastName() { return $this->getBillingLastName(); } /** * Set Card Last Name (Billing and Shipping). * * @param string $value Parameter value * @return $this */ public function setLastName($value) { $this->setBillingLastName($value); $this->setShippingLastName($value); return $this; } /** * Get Card Name. * * @return string */ public function getName() { return $this->getBillingName(); } /** * Set Card Name (Billing and Shipping). * * @param string $value Parameter value * @return $this */ public function setName($value) { $this->setBillingName($value); $this->setShippingName($value); return $this; } /** * Get Card Number. * * @return string */ public function getNumber() { return $this->getParameter('number'); } /** * Set Card Number * * Non-numeric characters are stripped out of the card number, so * it's safe to pass in strings such as "4444-3333 2222 1111" etc. * * @param string $value Parameter value * @return $this */ public function setNumber($value) { // strip non-numeric characters return $this->setParameter('number', preg_replace('/\D/', '', $value)); } /** * Get the last 4 digits of the card number. * * @return string */ public function getNumberLastFour() { return substr($this->getNumber(), -4, 4) ?: null; } /** * Returns a masked credit card number with only the last 4 chars visible * * @param string $mask Character to use in place of numbers * @return string */ public function getNumberMasked($mask = 'X') { $maskLength = strlen($this->getNumber()) - 4; return str_repeat($mask, $maskLength) . $this->getNumberLastFour(); } /** * Credit Card Brand * * Iterates through known/supported card brands to determine the brand of this card * * @return string */ public function getBrand() { foreach ($this->getSupportedBrands() as $brand => $val) { if (preg_match($val, $this->getNumber())) { return $brand; } } } /** * Get the card expiry month. * * @return int */ public function getExpiryMonth() { return $this->getParameter('expiryMonth'); } /** * Sets the card expiry month. * * @param string $value * @return $this */ public function setExpiryMonth($value) { return $this->setParameter('expiryMonth', (int) $value); } /** * Get the card expiry year. * * @return int */ public function getExpiryYear() { return $this->getParameter('expiryYear'); } /** * Sets the card expiry year. * * @param string $value * @return $this */ public function setExpiryYear($value) { return $this->setYearParameter('expiryYear', $value); } /** * Get the card expiry date, using the specified date format string. * * @param string $format * * @return string */ public function getExpiryDate($format) { return gmdate($format, gmmktime(0, 0, 0, $this->getExpiryMonth(), 1, $this->getExpiryYear())); } /** * Get the card start month. * * @return string */ public function getStartMonth() { return $this->getParameter('startMonth'); } /** * Sets the card start month. * * @param string $value * @return $this */ public function setStartMonth($value) { return $this->setParameter('startMonth', (int) $value); } /** * Get the card start year. * * @return int */ public function getStartYear() { return $this->getParameter('startYear'); } /** * Sets the card start year. * * @param string $value * @return $this */ public function setStartYear($value) { return $this->setYearParameter('startYear', $value); } /** * Get the card start date, using the specified date format string * * @param string $format * * @return string */ public function getStartDate($format) { return gmdate($format, gmmktime(0, 0, 0, $this->getStartMonth(), 1, $this->getStartYear())); } /** * Get the card CVV. * * @return string */ public function getCvv() { return $this->getParameter('cvv'); } /** * Sets the card CVV. * * @param string $value * @return $this */ public function setCvv($value) { return $this->setParameter('cvv', $value); } /** * Get raw data for all tracks on the credit card magnetic strip. * * @return string */ public function getTracks() { return $this->getParameter('tracks'); } /** * Get raw data for track 1 on the credit card magnetic strip. * * @return string|null */ public function getTrack1() { return $this->getTrackByPattern('/\%B\d{1,19}\^.{2,26}\^\d{4}\d*\?/'); } /** * Get raw data for track 2 on the credit card magnetic strip. * * @return string|null */ public function getTrack2() { return $this->getTrackByPattern('/;\d{1,19}=\d{4}\d*\?/'); } /** * Get raw data for a track on the credit card magnetic strip based on the pattern for track 1 or 2. * * @param $pattern * @return string|null */ protected function getTrackByPattern($pattern) { if ($tracks = $this->getTracks()) { if (preg_match($pattern, $tracks, $matches) === 1) { return $matches[0]; } } } /** * Sets raw data from all tracks on the credit card magnetic strip. Used by gateways that support card-present * transactions. * * @param $value * @return $this */ public function setTracks($value) { return $this->setParameter('tracks', $value); } /** * Get the card issue number. * * @return string */ public function getIssueNumber() { return $this->getParameter('issueNumber'); } /** * Sets the card issue number. * * @param string $value * @return $this */ public function setIssueNumber($value) { return $this->setParameter('issueNumber', $value); } /** * Get the card billing title. * * @return string */ public function getBillingTitle() { return $this->getParameter('billingTitle'); } /** * Sets the card billing title. * * @param string $value * @return $this */ public function setBillingTitle($value) { return $this->setParameter('billingTitle', $value); } /** * Get the card billing name. * * @return string */ public function getBillingName() { return trim($this->getBillingFirstName() . ' ' . $this->getBillingLastName()); } /** * Split the full name in the first and last name. * * @param $fullName * @return array with first and lastname */ protected function listFirstLastName($fullName) { $names = explode(' ', $fullName, 2); return [$names[0], isset($names[1]) ? $names[1] : null]; } /** * Sets the card billing name. * * @param string $value * @return $this */ public function setBillingName($value) { $names = $this->listFirstLastName($value); $this->setBillingFirstName($names[0]); $this->setBillingLastName($names[1]); return $this; } /** * Get the first part of the card billing name. * * @return string */ public function getBillingFirstName() { return $this->getParameter('billingFirstName'); } /** * Sets the first part of the card billing name. * * @param string $value * @return $this */ public function setBillingFirstName($value) { return $this->setParameter('billingFirstName', $value); } /** * Get the last part of the card billing name. * * @return string */ public function getBillingLastName() { return $this->getParameter('billingLastName'); } /** * Sets the last part of the card billing name. * * @param string $value * @return $this */ public function setBillingLastName($value) { return $this->setParameter('billingLastName', $value); } /** * Get the billing company name. * * @return string */ public function getBillingCompany() { return $this->getParameter('billingCompany'); } /** * Sets the billing company name. * * @param string $value * @return $this */ public function setBillingCompany($value) { return $this->setParameter('billingCompany', $value); } /** * Get the billing address, line 1. * * @return string */ public function getBillingAddress1() { return $this->getParameter('billingAddress1'); } /** * Sets the billing address, line 1. * * @param string $value * @return $this */ public function setBillingAddress1($value) { return $this->setParameter('billingAddress1', $value); } /** * Get the billing address, line 2. * * @return string */ public function getBillingAddress2() { return $this->getParameter('billingAddress2'); } /** * Sets the billing address, line 2. * * @param string $value * @return $this */ public function setBillingAddress2($value) { return $this->setParameter('billingAddress2', $value); } /** * Get the billing city. * * @return string */ public function getBillingCity() { return $this->getParameter('billingCity'); } /** * Sets billing city. * * @param string $value * @return $this */ public function setBillingCity($value) { return $this->setParameter('billingCity', $value); } /** * Get the billing postcode. * * @return string */ public function getBillingPostcode() { return $this->getParameter('billingPostcode'); } /** * Sets the billing postcode. * * @param string $value * @return $this */ public function setBillingPostcode($value) { return $this->setParameter('billingPostcode', $value); } /** * Get the billing state. * * @return string */ public function getBillingState() { return $this->getParameter('billingState'); } /** * Sets the billing state. * * @param string $value * @return $this */ public function setBillingState($value) { return $this->setParameter('billingState', $value); } /** * Get the billing country name. * * @return string */ public function getBillingCountry() { return $this->getParameter('billingCountry'); } /** * Sets the billing country name. * * @param string $value * @return $this */ public function setBillingCountry($value) { return $this->setParameter('billingCountry', $value); } /** * Get the billing phone number. * * @return string */ public function getBillingPhone() { return $this->getParameter('billingPhone'); } /** * Sets the billing phone number. * * @param string $value * @return $this */ public function setBillingPhone($value) { return $this->setParameter('billingPhone', $value); } /** * Get the billing phone number extension. * * @return string */ public function getBillingPhoneExtension() { return $this->getParameter('billingPhoneExtension'); } /** * Sets the billing phone number extension. * * @param string $value * @return $this */ public function setBillingPhoneExtension($value) { return $this->setParameter('billingPhoneExtension', $value); } /** * Get the billing fax number. * * @return string */ public function getBillingFax() { return $this->getParameter('billingFax'); } /** * Sets the billing fax number. * * @param string $value * @return $this */ public function setBillingFax($value) { return $this->setParameter('billingFax', $value); } /** * Get the title of the card shipping name. * * @return string */ public function getShippingTitle() { return $this->getParameter('shippingTitle'); } /** * Sets the title of the card shipping name. * * @param string $value * @return $this */ public function setShippingTitle($value) { return $this->setParameter('shippingTitle', $value); } /** * Get the card shipping name. * * @return string */ public function getShippingName() { return trim($this->getShippingFirstName() . ' ' . $this->getShippingLastName()); } /** * Sets the card shipping name. * * @param string $value * @return $this */ public function setShippingName($value) { $names = $this->listFirstLastName($value); $this->setShippingFirstName($names[0]); $this->setShippingLastName($names[1]); return $this; } /** * Get the first part of the card shipping name. * * @return string */ public function getShippingFirstName() { return $this->getParameter('shippingFirstName'); } /** * Sets the first part of the card shipping name. * * @param string $value * @return $this */ public function setShippingFirstName($value) { return $this->setParameter('shippingFirstName', $value); } /** * Get the last part of the card shipping name. * * @return string */ public function getShippingLastName() { return $this->getParameter('shippingLastName'); } /** * Sets the last part of the card shipping name. * * @param string $value * @return $this */ public function setShippingLastName($value) { return $this->setParameter('shippingLastName', $value); } /** * Get the shipping company name. * * @return string */ public function getShippingCompany() { return $this->getParameter('shippingCompany'); } /** * Sets the shipping company name. * * @param string $value * @return $this */ public function setShippingCompany($value) { return $this->setParameter('shippingCompany', $value); } /** * Get the shipping address, line 1. * * @return string */ public function getShippingAddress1() { return $this->getParameter('shippingAddress1'); } /** * Sets the shipping address, line 1. * * @param string $value * @return $this */ public function setShippingAddress1($value) { return $this->setParameter('shippingAddress1', $value); } /** * Get the shipping address, line 2. * * @return string */ public function getShippingAddress2() { return $this->getParameter('shippingAddress2'); } /** * Sets the shipping address, line 2. * * @param string $value * @return $this */ public function setShippingAddress2($value) { return $this->setParameter('shippingAddress2', $value); } /** * Get the shipping city. * * @return string */ public function getShippingCity() { return $this->getParameter('shippingCity'); } /** * Sets the shipping city. * * @param string $value * @return $this */ public function setShippingCity($value) { return $this->setParameter('shippingCity', $value); } /** * Get the shipping postcode. * * @return string */ public function getShippingPostcode() { return $this->getParameter('shippingPostcode'); } /** * Sets the shipping postcode. * * @param string $value * @return $this */ public function setShippingPostcode($value) { return $this->setParameter('shippingPostcode', $value); } /** * Get the shipping state. * * @return string */ public function getShippingState() { return $this->getParameter('shippingState'); } /** * Sets the shipping state. * * @param string $value * @return $this */ public function setShippingState($value) { return $this->setParameter('shippingState', $value); } /** * Get the shipping country. * * @return string */ public function getShippingCountry() { return $this->getParameter('shippingCountry'); } /** * Sets the shipping country. * * @param string $value * @return $this */ public function setShippingCountry($value) { return $this->setParameter('shippingCountry', $value); } /** * Get the shipping phone number. * * @return string */ public function getShippingPhone() { return $this->getParameter('shippingPhone'); } /** * Sets the shipping phone number. * * @param string $value * @return $this */ public function setShippingPhone($value) { return $this->setParameter('shippingPhone', $value); } /** * Get the shipping phone number extension. * * @return string */ public function getShippingPhoneExtension() { return $this->getParameter('shippingPhoneExtension'); } /** * Sets the shipping phone number extension. * * @param string $value * @return $this */ public function setShippingPhoneExtension($value) { return $this->setParameter('shippingPhoneExtension', $value); } /** * Get the shipping fax number. * * @return string */ public function getShippingFax() { return $this->getParameter('shippingFax'); } /** * Sets the shipping fax number. * * @param string $value * @return $this */ public function setShippingFax($value) { return $this->setParameter('shippingFax', $value); } /** * Get the billing address, line 1. * * @return string */ public function getAddress1() { return $this->getParameter('billingAddress1'); } /** * Sets the billing and shipping address, line 1. * * @param string $value * @return $this */ public function setAddress1($value) { $this->setParameter('billingAddress1', $value); $this->setParameter('shippingAddress1', $value); return $this; } /** * Get the billing address, line 2. * * @return string */ public function getAddress2() { return $this->getParameter('billingAddress2'); } /** * Sets the billing and shipping address, line 2. * * @param string $value * @return $this */ public function setAddress2($value) { $this->setParameter('billingAddress2', $value); $this->setParameter('shippingAddress2', $value); return $this; } /** * Get the billing city. * * @return string */ public function getCity() { return $this->getParameter('billingCity'); } /** * Sets the billing and shipping city. * * @param string $value * @return $this */ public function setCity($value) { $this->setParameter('billingCity', $value); $this->setParameter('shippingCity', $value); return $this; } /** * Get the billing postcode. * * @return string */ public function getPostcode() { return $this->getParameter('billingPostcode'); } /** * Sets the billing and shipping postcode. * * @param string $value * @return $this */ public function setPostcode($value) { $this->setParameter('billingPostcode', $value); $this->setParameter('shippingPostcode', $value); return $this; } /** * Get the billing state. * * @return string */ public function getState() { return $this->getParameter('billingState'); } /** * Sets the billing and shipping state. * * @param string $value * @return $this */ public function setState($value) { $this->setParameter('billingState', $value); $this->setParameter('shippingState', $value); return $this; } /** * Get the billing country. * * @return string */ public function getCountry() { return $this->getParameter('billingCountry'); } /** * Sets the billing and shipping country. * * @param string $value * @return $this */ public function setCountry($value) { $this->setParameter('billingCountry', $value); $this->setParameter('shippingCountry', $value); return $this; } /** * Get the billing phone number. * * @return string */ public function getPhone() { return $this->getParameter('billingPhone'); } /** * Sets the billing and shipping phone number. * * @param string $value * @return $this */ public function setPhone($value) { $this->setParameter('billingPhone', $value); $this->setParameter('shippingPhone', $value); return $this; } /** * Get the billing phone number extension. * * @return string */ public function getPhoneExtension() { return $this->getParameter('billingPhoneExtension'); } /** * Sets the billing and shipping phone number extension. * * @param string $value * @return $this */ public function setPhoneExtension($value) { $this->setParameter('billingPhoneExtension', $value); $this->setParameter('shippingPhoneExtension', $value); return $this; } /** * Get the billing fax number.. * * @return string */ public function getFax() { return $this->getParameter('billingFax'); } /** * Sets the billing and shipping fax number. * * @param string $value * @return $this */ public function setFax($value) { $this->setParameter('billingFax', $value); $this->setParameter('shippingFax', $value); return $this; } /** * Get the card billing company name. * * @return string */ public function getCompany() { return $this->getParameter('billingCompany'); } /** * Sets the billing and shipping company name. * * @param string $value * @return $this */ public function setCompany($value) { $this->setParameter('billingCompany', $value); $this->setParameter('shippingCompany', $value); return $this; } /** * Get the cardholder's email address. * * @return string */ public function getEmail() { return $this->getParameter('email'); } /** * Sets the cardholder's email address. * * @param string $value * @return $this */ public function setEmail($value) { return $this->setParameter('email', $value); } /** * Get the cardholder's birthday. * * @return string */ public function getBirthday($format = 'Y-m-d') { $value = $this->getParameter('birthday'); return $value ? $value->format($format) : null; } /** * Sets the cardholder's birthday. * * @param string $value * @return $this */ public function setBirthday($value) { if ($value) { $value = new DateTime($value, new DateTimeZone('UTC')); } else { $value = null; } return $this->setParameter('birthday', $value); } /** * Get the cardholder's gender. * * @return string */ public function getGender() { return $this->getParameter('gender'); } /** * Sets the cardholder's gender. * * @param string $value * @return $this */ public function setGender($value) { return $this->setParameter('gender', $value); } } common/src/Common/GatewayInterface.php 0000666 00000006620 15165413756 0014033 0 ustar 00 <?php /** * Payment gateway interface */ namespace Omnipay\Common; /** * Payment gateway interface * * This interface class defines the standard functions that any * Omnipay gateway needs to define. * * * @method \Omnipay\Common\Message\NotificationInterface acceptNotification(array $options = array()) (Optional method) * Receive and handle an instant payment notification (IPN) * @method \Omnipay\Common\Message\RequestInterface authorize(array $options = array()) (Optional method) * Authorize an amount on the customers card * @method \Omnipay\Common\Message\RequestInterface completeAuthorize(array $options = array()) (Optional method) * Handle return from off-site gateways after authorization * @method \Omnipay\Common\Message\RequestInterface capture(array $options = array()) (Optional method) * Capture an amount you have previously authorized * @method \Omnipay\Common\Message\RequestInterface purchase(array $options = array()) (Optional method) * Authorize and immediately capture an amount on the customers card * @method \Omnipay\Common\Message\RequestInterface completePurchase(array $options = array()) (Optional method) * Handle return from off-site gateways after purchase * @method \Omnipay\Common\Message\RequestInterface refund(array $options = array()) (Optional method) * Refund an already processed transaction * @method \Omnipay\Common\Message\RequestInterface fetchTransaction(array $options = []) (Optional method) * Fetches transaction information * @method \Omnipay\Common\Message\RequestInterface void(array $options = array()) (Optional method) * Generally can only be called up to 24 hours after submitting a transaction * @method \Omnipay\Common\Message\RequestInterface createCard(array $options = array()) (Optional method) * The returned response object includes a cardReference, which can be used for future transactions * @method \Omnipay\Common\Message\RequestInterface updateCard(array $options = array()) (Optional method) * Update a stored card * @method \Omnipay\Common\Message\RequestInterface deleteCard(array $options = array()) (Optional method) * Delete a stored card */ interface GatewayInterface { /** * Get gateway display name * * This can be used by carts to get the display name for each gateway. * @return string */ public function getName(); /** * Get gateway short name * * This name can be used with GatewayFactory as an alias of the gateway class, * to create new instances of this gateway. * @return string */ public function getShortName(); /** * Define gateway parameters, in the following format: * * array( * 'username' => '', // string variable * 'testMode' => false, // boolean variable * 'landingPage' => array('billing', 'login'), // enum variable, first item is default * ); * @return array */ public function getDefaultParameters(); /** * Initialize gateway with parameters * @return $this */ public function initialize(array $parameters = array()); /** * Get all gateway parameters * @return array */ public function getParameters(); } common/src/Common/ItemBag.php 0000666 00000003334 15165413756 0012120 0 ustar 00 <?php /** * Cart Item Bag */ namespace Omnipay\Common; /** * Cart Item Bag * * This class defines a bag (multi element set or array) of single cart items * in the Omnipay system. * */ class ItemBag implements \IteratorAggregate, \Countable { /** * Item storage * * * @var array */ protected $items; /** * Constructor * * @param array $items An array of items */ public function __construct(array $items = array()) { $this->replace($items); } /** * Return all the items * * * @return array An array of items */ public function all() { return $this->items; } /** * Replace the contents of this bag with the specified items * * * @param array $items An array of items */ public function replace(array $items = array()) { $this->items = array(); foreach ($items as $item) { $this->add($item); } } /** * Add an item to the bag * * * @param ItemInterface|array $item An existing item, or associative array of item parameters */ public function add($item) { if ($item instanceof ItemInterface) { $this->items[] = $item; } else { $this->items[] = new Item($item); } } /** * Returns an iterator for items * * @return \ArrayIterator An \ArrayIterator instance */ public function getIterator() { return new \ArrayIterator($this->items); } /** * Returns the number of items * * @return int The number of items */ public function count() { return count($this->items); } } common/src/Common/Issuer.php 0000666 00000002677 15165413756 0012073 0 ustar 00 <?php /** * Issuer */ namespace Omnipay\Common; /** * Issuer * * This class abstracts some functionality around card issuers used in the * Omnipay system. */ class Issuer { /** * The identifier of the issuer. * * @var string */ protected $id; /** * The full name of the issuer. * * @var string */ protected $name; /** * The ID of a payment method that the issuer belongs to. ** * @var string */ protected $paymentMethod; /** * Create a new Issuer * * @param string $id The identifier of this issuer * @param string $name The name of this issuer * @param string|null $paymentMethod The ID of a payment method this issuer belongs to */ public function __construct($id, $name, $paymentMethod = null) { $this->id = $id; $this->name = $name; $this->paymentMethod = $paymentMethod; } /** * The identifier of this issuer * * @return string */ public function getId() { return $this->id; } /** * The name of this issuer * * @return string */ public function getName() { return $this->name; } /** * The ID of a payment method this issuer belongs to * * @return string */ public function getPaymentMethod() { return $this->paymentMethod; } } common/src/Common/Exception/InvalidRequestException.php 0000666 00000000345 15165413756 0017363 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Invalid Request Exception * * Thrown when a request is invalid or missing required fields. */ class InvalidRequestException extends \Exception implements OmnipayException { } common/src/Common/Exception/RuntimeException.php 0000666 00000000232 15165413756 0016042 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Runtime Exception */ class RuntimeException extends \RuntimeException implements OmnipayException { } common/src/Common/Exception/BadMethodCallException.php 0000666 00000000256 15165413756 0017050 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Bad Method Call Exception */ class BadMethodCallException extends \BadMethodCallException implements OmnipayException { } common/src/Common/Exception/InvalidCreditCardException.php 0000666 00000000360 15165413756 0017734 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Invalid Credit Card Exception * * Thrown when a credit card is invalid or missing required fields. */ class InvalidCreditCardException extends \Exception implements OmnipayException { } common/src/Common/Exception/InvalidResponseException.php 0000666 00000000717 15165413756 0017534 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Invalid Response exception. * * Thrown when a gateway responded with invalid or unexpected data (for example, a security hash did not match). */ class InvalidResponseException extends \Exception implements OmnipayException { public function __construct($message = "Invalid response from payment gateway", $code = 0, $previous = null) { parent::__construct($message, $code, $previous); } } common/src/Common/Exception/OmnipayException.php 0000666 00000000171 15165413756 0016035 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Omnipay Exception marker interface */ interface OmnipayException { } common/src/Common/ItemInterface.php 0000666 00000001034 15165413756 0013322 0 ustar 00 <?php /** * Cart Item interface */ namespace Omnipay\Common; /** * Cart Item interface * * This interface defines the functionality that all cart items in * the Omnipay system are to have. */ interface ItemInterface { /** * Name of the item */ public function getName(); /** * Description of the item */ public function getDescription(); /** * Quantity of the item */ public function getQuantity(); /** * Price of the item */ public function getPrice(); } common/src/Common/Message/ResponseInterface.php 0000666 00000002475 15165413756 0015620 0 ustar 00 <?php /** * Response interface */ namespace Omnipay\Common\Message; /** * Response Interface * * This interface class defines the standard functions that any Omnipay response * interface needs to be able to provide. It is an extension of MessageInterface. * */ interface ResponseInterface extends MessageInterface { /** * Get the original request which generated this response * * @return RequestInterface */ public function getRequest(); /** * Is the response successful? * * @return boolean */ public function isSuccessful(); /** * Does the response require a redirect? * * @return boolean */ public function isRedirect(); /** * Is the transaction cancelled by the user? * * @return boolean */ public function isCancelled(); /** * Response Message * * @return null|string A response message from the payment gateway */ public function getMessage(); /** * Response code * * @return null|string A response code from the payment gateway */ public function getCode(); /** * Gateway Reference * * @return null|string A reference provided by the gateway to represent this transaction */ public function getTransactionReference(); } common/src/Common/Message/AbstractResponse.php 0000666 00000013450 15165413756 0015456 0 ustar 00 <?php /** * Abstract Response */ namespace Omnipay\Common\Message; use Omnipay\Common\Exception\RuntimeException; use Symfony\Component\HttpFoundation\RedirectResponse as HttpRedirectResponse; use Symfony\Component\HttpFoundation\Response as HttpResponse; /** * Abstract Response * * This abstract class implements ResponseInterface and defines a basic * set of functions that all Omnipay Requests are intended to include. * * Objects of this class or a subclass are usually created in the Request * object (subclass of AbstractRequest) as the return parameters from the * send() function. * * Example -- validating and sending a request: * * <code> * $myResponse = $myRequest->send(); * // now do something with the $myResponse object, test for success, etc. * </code> * */ abstract class AbstractResponse implements ResponseInterface { /** * The embodied request object. * * @var RequestInterface */ protected $request; /** * The data contained in the response. * * @var mixed */ protected $data; /** * Constructor * * @param RequestInterface $request the initiating request. * @param mixed $data */ public function __construct(RequestInterface $request, $data) { $this->request = $request; $this->data = $data; } /** * Get the initiating request object. * * @return RequestInterface */ public function getRequest() { return $this->request; } /** * Is the response successful? * * @return boolean */ public function isPending() { return false; } /** * Does the response require a redirect? * * @return boolean */ public function isRedirect() { return false; } /** * Is the response a transparent redirect? * * @return boolean */ public function isTransparentRedirect() { return false; } /** * Is the transaction cancelled by the user? * * @return boolean */ public function isCancelled() { return false; } /** * Get the response data. * * @return mixed */ public function getData() { return $this->data; } /** * Response Message * * @return null|string A response message from the payment gateway */ public function getMessage() { return null; } /** * Response code * * @return null|string A response code from the payment gateway */ public function getCode() { return null; } /** * Gateway Reference * * @return null|string A reference provided by the gateway to represent this transaction */ public function getTransactionReference() { return null; } /** * Get the transaction ID as generated by the merchant website. * * @return string */ public function getTransactionId() { return null; } /** * Gets the redirect target url. * * @return string */ public function getRedirectUrl() { return null; } /** * Get the required redirect method (either GET or POST). * * @return string */ public function getRedirectMethod() { return 'GET'; } /** * Gets the redirect form data array, if the redirect method is POST. * * @return array */ public function getRedirectData() { return []; } /** * Automatically perform any required redirect * * This method is meant to be a helper for simple scenarios. If you want to customize the * redirection page, just call the getRedirectUrl() and getRedirectData() methods directly. * * @return void */ public function redirect() { $this->getRedirectResponse()->send(); } /** * @return HttpRedirectResponse|HttpResponse */ public function getRedirectResponse() { $this->validateRedirect(); if ('GET' === $this->getRedirectMethod()) { return new HttpRedirectResponse($this->getRedirectUrl()); } $hiddenFields = ''; foreach ($this->getRedirectData() as $key => $value) { $hiddenFields .= sprintf( '<input type="hidden" name="%1$s" value="%2$s" />', htmlentities($key, ENT_QUOTES, 'UTF-8', false), htmlentities($value, ENT_QUOTES, 'UTF-8', false) )."\n"; } $output = '<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Redirecting...</title> </head> <body onload="document.forms[0].submit();"> <form action="%1$s" method="post"> <p>Redirecting to payment page...</p> <p> %2$s <input type="submit" value="Continue" /> </p> </form> </body> </html>'; $output = sprintf( $output, htmlentities($this->getRedirectUrl(), ENT_QUOTES, 'UTF-8', false), $hiddenFields ); return new HttpResponse($output); } /** * Validate that the current Response is a valid redirect. * * @return void */ protected function validateRedirect() { if (!$this instanceof RedirectResponseInterface || !$this->isRedirect()) { throw new RuntimeException('This response does not support redirection.'); } if (empty($this->getRedirectUrl())) { throw new RuntimeException('The given redirectUrl cannot be empty.'); } if (!in_array($this->getRedirectMethod(), ['GET', 'POST'])) { throw new RuntimeException('Invalid redirect method "'.$this->getRedirectMethod().'".'); } } } common/src/Common/Message/RequestInterface.php 0000666 00000002071 15165413756 0015442 0 ustar 00 <?php /** * Request Interface */ namespace Omnipay\Common\Message; /** * Request Interface * * This interface class defines the standard functions that any Omnipay request * interface needs to be able to provide. It is an extension of MessageInterface. * */ interface RequestInterface extends MessageInterface { /** * Initialize request with parameters * @param array $parameters The parameters to send */ public function initialize(array $parameters = array()); /** * Get all request parameters * * @return array */ public function getParameters(); /** * Get the response to this request (if the request has been sent) * * @return ResponseInterface */ public function getResponse(); /** * Send the request * * @return ResponseInterface */ public function send(); /** * Send the request with specified data * * @param mixed $data The data to send * @return ResponseInterface */ public function sendData($data); } common/src/Common/Message/NotificationInterface.php 0000666 00000001574 15165413756 0016447 0 ustar 00 <?php namespace Omnipay\Common\Message; /** * Incoming notification */ interface NotificationInterface extends MessageInterface { const STATUS_COMPLETED = 'completed'; const STATUS_PENDING = 'pending'; const STATUS_FAILED = 'failed'; /** * Gateway Reference * * @return string A reference provided by the gateway to represent this transaction */ public function getTransactionReference(); /** * Was the transaction successful? * * @return string Transaction status, one of {@link NotificationInterface::STATUS_COMPLETED}, * {@link NotificationInterface::STATUS_PENDING}, or {@link NotificationInterface::STATUS_FAILED}. */ public function getTransactionStatus(); /** * Response Message * * @return string A response message from the payment gateway */ public function getMessage(); } common/src/Common/Message/FetchIssuersResponseInterface.php 0000666 00000001370 15165413756 0020141 0 ustar 00 <?php /** * Fetch Issuers Response interface */ namespace Omnipay\Common\Message; /** * Fetch Issuers Response interface * * This interface class defines the functionality of a response * that is a "fetch issuers" response. It extends the ResponseInterface * interface class with some extra functions relating to the * specifics of a response to fetch the issuers from the gateway. * This happens when the gateway needs the customer to choose a * card issuer. * */ interface FetchIssuersResponseInterface extends ResponseInterface { /** * Get the returned list of issuers. * * These represent banks which the user must choose between. * * @return \Omnipay\Common\Issuer[] */ public function getIssuers(); } common/src/Common/Message/MessageInterface.php 0000666 00000000775 15165413756 0015407 0 ustar 00 <?php /** * Message Interface */ namespace Omnipay\Common\Message; /** * Message Interface * * This interface class defines the standard functions that any Omnipay message * interface needs to be able to provide. */ interface MessageInterface { /** * Get the raw data array for this message. The format of this varies from gateway to * gateway, but will usually be either an associative array, or a SimpleXMLElement. * * @return mixed */ public function getData(); } common/src/Common/Message/RedirectResponseInterface.php 0000666 00000001722 15165413756 0017274 0 ustar 00 <?php /** * Redirect Response interface */ namespace Omnipay\Common\Message; /** * Redirect Response interface * * This interface class defines the functionality of a response * that is a redirect response. It extends the ResponseInterface * interface class with some extra functions relating to the * specifics of a redirect response from the gateway. * */ interface RedirectResponseInterface extends ResponseInterface { /** * Gets the redirect target url. * * @return string */ public function getRedirectUrl(); /** * Get the required redirect method (either GET or POST). * * @return string */ public function getRedirectMethod(); /** * Gets the redirect form data array, if the redirect method is POST. * * @return array */ public function getRedirectData(); /** * Perform the required redirect. * * @return void */ public function redirect(); } common/src/Common/Message/FetchPaymentMethodsResponseInterface.php 0000666 00000001511 15165413756 0021442 0 ustar 00 <?php /** * Fetch Payment Methods Response interface */ namespace Omnipay\Common\Message; /** * Fetch Payment Methods Response interface * * This interface class defines the functionality of a response * that is a "fetch payment method" response. It extends the ResponseInterface * interface class with some extra functions relating to the * specifics of a response to fetch the payment method from the gateway. * This happens when the gateway needs the customer to choose a * payment method. * */ interface FetchPaymentMethodsResponseInterface extends ResponseInterface { /** * Get the returned list of payment methods. * * These represent separate payment methods which the user must choose between. * * @return \Omnipay\Common\PaymentMethod[] */ public function getPaymentMethods(); } common/src/Common/Message/AbstractRequest.php 0000666 00000037773 15165413756 0015326 0 ustar 00 <?php /** * Abstract Request */ namespace Omnipay\Common\Message; use Money\Currencies\ISOCurrencies; use Money\Currency; use Money\Formatter\DecimalMoneyFormatter; use Money\Money; use Money\Number; use Money\Parser\DecimalMoneyParser; use Omnipay\Common\CreditCard; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Exception\RuntimeException; use Omnipay\Common\Helper; use Omnipay\Common\Http\Client; use Omnipay\Common\Http\ClientInterface; use Omnipay\Common\ItemBag; use Omnipay\Common\ParametersTrait; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Abstract Request * * This abstract class implements RequestInterface and defines a basic * set of functions that all Omnipay Requests are intended to include. * * Requests of this class are usually created using the createRequest * function of the gateway and then actioned using methods within this * class or a class that extends this class. * * Example -- creating a request: * * <code> * class MyRequest extends \Omnipay\Common\Message\AbstractRequest {}; * * class MyGateway extends \Omnipay\Common\AbstractGateway { * function myRequest($parameters) { * $this->createRequest('MyRequest', $parameters); * } * } * * // Create the gateway object * $gw = Omnipay::create('MyGateway'); * * // Create the request object * $myRequest = $gw->myRequest($someParameters); * </code> * * Example -- validating and sending a request: * * <code> * try { * $myRequest->validate(); * $myResponse = $myRequest->send(); * } catch (InvalidRequestException $e) { * print "Something went wrong: " . $e->getMessage() . "\n"; * } * // now do something with the $myResponse object, test for success, etc. * </code> * */ abstract class AbstractRequest implements RequestInterface { use ParametersTrait { setParameter as traitSetParameter; } /** * The request client. * * @var ClientInterface */ protected $httpClient; /** * The HTTP request object. * * @var \Symfony\Component\HttpFoundation\Request */ protected $httpRequest; /** * An associated ResponseInterface. * * @var ResponseInterface */ protected $response; /** * @var ISOCurrencies */ protected $currencies; /** * @var bool */ protected $zeroAmountAllowed = true; /** * @var bool */ protected $negativeAmountAllowed = false; /** * Create a new Request * * @param ClientInterface $httpClient A HTTP client to make API calls with * @param HttpRequest $httpRequest A Symfony HTTP request object */ public function __construct(ClientInterface $httpClient, HttpRequest $httpRequest) { $this->httpClient = $httpClient; $this->httpRequest = $httpRequest; $this->initialize(); } /** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * * @return $this * @throws RuntimeException */ public function initialize(array $parameters = array()) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); } $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } /** * Set a single parameter * * @param string $key The parameter key * @param mixed $value The value to set * @return $this * @throws RuntimeException if a request parameter is modified after the request has been sent. */ protected function setParameter($key, $value) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); } return $this->traitSetParameter($key, $value); } /** * Gets the test mode of the request from the gateway. * * @return boolean */ public function getTestMode() { return $this->getParameter('testMode'); } /** * Sets the test mode of the request. * * @param boolean $value True for test mode on. * @return $this */ public function setTestMode($value) { return $this->setParameter('testMode', $value); } /** * Get the card. * * @return CreditCard */ public function getCard() { return $this->getParameter('card'); } /** * Sets the card. * * @param CreditCard $value * @return $this */ public function setCard($value) { if ($value && !$value instanceof CreditCard) { $value = new CreditCard($value); } return $this->setParameter('card', $value); } /** * Get the card token. * * @return string */ public function getToken() { return $this->getParameter('token'); } /** * Sets the card token. * * @param string $value * @return $this */ public function setToken($value) { return $this->setParameter('token', $value); } /** * Get the card reference. * * @return string */ public function getCardReference() { return $this->getParameter('cardReference'); } /** * Sets the card reference. * * @param string $value * @return $this */ public function setCardReference($value) { return $this->setParameter('cardReference', $value); } /** * @return ISOCurrencies */ protected function getCurrencies() { if ($this->currencies === null) { $this->currencies = new ISOCurrencies(); } return $this->currencies; } /** * @param string|int|null $amount * @return null|Money * @throws InvalidRequestException */ private function getMoney($amount = null) { $currencyCode = $this->getCurrency() ?: 'USD'; $currency = new Currency($currencyCode); $amount = $amount !== null ? $amount : $this->getParameter('amount'); if ($amount === null) { return null; } elseif ($amount instanceof Money) { $money = $amount; } elseif (is_integer($amount)) { $money = new Money($amount, $currency); } else { $moneyParser = new DecimalMoneyParser($this->getCurrencies()); $number = Number::fromString($amount); // Check for rounding that may occur if too many significant decimal digits are supplied. $decimal_count = strlen($number->getFractionalPart()); $subunit = $this->getCurrencies()->subunitFor($currency); if ($decimal_count > $subunit) { throw new InvalidRequestException('Amount precision is too high for currency.'); } $money = $moneyParser->parse((string) $number, $currency); } // Check for a negative amount. if (!$this->negativeAmountAllowed && $money->isNegative()) { throw new InvalidRequestException('A negative amount is not allowed.'); } // Check for a zero amount. if (!$this->zeroAmountAllowed && $money->isZero()) { throw new InvalidRequestException('A zero amount is not allowed.'); } return $money; } /** * Validates and returns the formatted amount. * * @throws InvalidRequestException on any validation failure. * @return string The amount formatted to the correct number of decimal places for the selected currency. */ public function getAmount() { $money = $this->getMoney(); if ($money !== null) { $moneyFormatter = new DecimalMoneyFormatter($this->getCurrencies()); return $moneyFormatter->format($money); } } /** * Sets the payment amount. * * @param string|null $value * @return $this */ public function setAmount($value) { return $this->setParameter('amount', $value !== null ? (string) $value : null); } /** * Get the payment amount as an integer. * * @return integer */ public function getAmountInteger() { $money = $this->getMoney(); if ($money !== null) { return (int) $money->getAmount(); } } /** * Sets the payment amount as integer. * * @param int $value * @return $this */ public function setAmountInteger($value) { return $this->setParameter('amount', (int) $value); } /** * Sets the payment amount as integer. * * @param Money $value * @return $this */ public function setMoney(Money $value) { $currency = $value->getCurrency()->getCode(); $this->setCurrency($currency); return $this->setParameter('amount', $value); } /** * Get the payment currency code. * * @return string */ public function getCurrency() { return $this->getParameter('currency'); } /** * Sets the payment currency code. * * @param string $value * @return $this */ public function setCurrency($value) { if ($value !== null) { $value = strtoupper($value); } return $this->setParameter('currency', $value); } /** * Get the payment currency number. * * @return string|null */ public function getCurrencyNumeric() { if (! $this->getCurrency()) { return null; } $currency = new Currency($this->getCurrency()); if ($this->getCurrencies()->contains($currency)) { return (string) $this->getCurrencies()->numericCodeFor($currency); } } /** * Get the number of decimal places in the payment currency. * * @return integer */ public function getCurrencyDecimalPlaces() { if ($this->getCurrency()) { $currency = new Currency($this->getCurrency()); if ($this->getCurrencies()->contains($currency)) { return $this->getCurrencies()->subunitFor($currency); } } return 2; } /** * Format an amount for the payment currency. * * @param string $amount * @return string */ public function formatCurrency($amount) { $money = $this->getMoney((string) $amount); $formatter = new DecimalMoneyFormatter($this->getCurrencies()); return $formatter->format($money); } /** * Get the request description. * * @return string */ public function getDescription() { return $this->getParameter('description'); } /** * Sets the request description. * * @param string $value * @return $this */ public function setDescription($value) { return $this->setParameter('description', $value); } /** * Get the transaction ID. * * The transaction ID is the identifier generated by the merchant website. * * @return string */ public function getTransactionId() { return $this->getParameter('transactionId'); } /** * Sets the transaction ID. * * @param string $value * @return $this */ public function setTransactionId($value) { return $this->setParameter('transactionId', $value); } /** * Get the transaction reference. * * The transaction reference is the identifier generated by the remote * payment gateway. * * @return string */ public function getTransactionReference() { return $this->getParameter('transactionReference'); } /** * Sets the transaction reference. * * @param string $value * @return $this */ public function setTransactionReference($value) { return $this->setParameter('transactionReference', $value); } /** * A list of items in this order * * @return ItemBag|null A bag containing items in this order */ public function getItems() { return $this->getParameter('items'); } /** * Set the items in this order * * @param ItemBag|array $items An array of items in this order * @return $this */ public function setItems($items) { if ($items && !$items instanceof ItemBag) { $items = new ItemBag($items); } return $this->setParameter('items', $items); } /** * Get the client IP address. * * @return string */ public function getClientIp() { return $this->getParameter('clientIp'); } /** * Sets the client IP address. * * @param string $value * @return $this */ public function setClientIp($value) { return $this->setParameter('clientIp', $value); } /** * Get the request return URL. * * @return string */ public function getReturnUrl() { return $this->getParameter('returnUrl'); } /** * Sets the request return URL. * * @param string $value * @return $this */ public function setReturnUrl($value) { return $this->setParameter('returnUrl', $value); } /** * Get the request cancel URL. * * @return string */ public function getCancelUrl() { return $this->getParameter('cancelUrl'); } /** * Sets the request cancel URL. * * @param string $value * @return $this */ public function setCancelUrl($value) { return $this->setParameter('cancelUrl', $value); } /** * Get the request notify URL. * * @return string */ public function getNotifyUrl() { return $this->getParameter('notifyUrl'); } /** * Sets the request notify URL. * * @param string $value * @return $this */ public function setNotifyUrl($value) { return $this->setParameter('notifyUrl', $value); } /** * Get the payment issuer. * * This field is used by some European gateways, and normally represents * the bank where an account is held (separate from the card brand). * * @return string */ public function getIssuer() { return $this->getParameter('issuer'); } /** * Set the payment issuer. * * This field is used by some European gateways, and normally represents * the bank where an account is held (separate from the card brand). * * @param string $value * @return $this */ public function setIssuer($value) { return $this->setParameter('issuer', $value); } /** * Get the payment issuer. * * This field is used by some European gateways, which support * multiple payment providers with a single API. * * @return string */ public function getPaymentMethod() { return $this->getParameter('paymentMethod'); } /** * Set the payment method. * * This field is used by some European gateways, which support * multiple payment providers with a single API. * * @param string $value * @return $this */ public function setPaymentMethod($value) { return $this->setParameter('paymentMethod', $value); } /** * Send the request * * @return ResponseInterface */ public function send() { $data = $this->getData(); return $this->sendData($data); } /** * Get the associated Response. * * @return ResponseInterface */ public function getResponse() { if (null === $this->response) { throw new RuntimeException('You must call send() before accessing the Response!'); } return $this->response; } } common/src/Common/AbstractGateway.php 0000666 00000020202 15165413756 0013666 0 ustar 00 <?php /** * Base payment gateway class */ namespace Omnipay\Common; use Omnipay\Common\Http\Client; use Omnipay\Common\Http\ClientInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Base payment gateway class * * This abstract class should be extended by all payment gateways * throughout the Omnipay system. It enforces implementation of * the GatewayInterface interface and defines various common attibutes * and methods that all gateways should have. * * Example: * * <code> * // Initialise the gateway * $gateway->initialize(...); * * // Get the gateway parameters. * $parameters = $gateway->getParameters(); * * // Create a credit card object * $card = new CreditCard(...); * * // Do an authorisation transaction on the gateway * if ($gateway->supportsAuthorize()) { * $gateway->authorize(...); * } else { * throw new \Exception('Gateway does not support authorize()'); * } * </code> * * For further code examples see the *omnipay-example* repository on github. * */ abstract class AbstractGateway implements GatewayInterface { use ParametersTrait { setParameter as traitSetParameter; getParameter as traitGetParameter; } /** * @var ClientInterface */ protected $httpClient; /** * @var \Symfony\Component\HttpFoundation\Request */ protected $httpRequest; /** * Create a new gateway instance * * @param ClientInterface $httpClient A HTTP client to make API calls with * @param HttpRequest $httpRequest A Symfony HTTP request object */ public function __construct(ClientInterface $httpClient = null, HttpRequest $httpRequest = null) { $this->httpClient = $httpClient ?: $this->getDefaultHttpClient(); $this->httpRequest = $httpRequest ?: $this->getDefaultHttpRequest(); $this->initialize(); } /** * Get the short name of the Gateway * * @return string */ public function getShortName() { return Helper::getGatewayShortName(get_class($this)); } /** * Initialize this gateway with default parameters * * @param array $parameters * @return $this */ public function initialize(array $parameters = array()) { $this->parameters = new ParameterBag; // set default parameters foreach ($this->getDefaultParameters() as $key => $value) { if (is_array($value)) { $this->parameters->set($key, reset($value)); } else { $this->parameters->set($key, $value); } } Helper::initialize($this, $parameters); return $this; } /** * @return array */ public function getDefaultParameters() { return array(); } /** * @param string $key * @return mixed */ public function getParameter($key) { return $this->traitGetParameter($key); } /** * @param string $key * @param mixed $value * @return $this */ public function setParameter($key, $value) { return $this->traitSetParameter($key, $value); } /** * @return boolean */ public function getTestMode() { return $this->getParameter('testMode'); } /** * @param boolean $value * @return $this */ public function setTestMode($value) { return $this->setParameter('testMode', $value); } /** * @return string */ public function getCurrency() { return strtoupper($this->getParameter('currency')); } /** * @param string $value * @return $this */ public function setCurrency($value) { return $this->setParameter('currency', $value); } /** * Supports Authorize * * @return boolean True if this gateway supports the authorize() method */ public function supportsAuthorize() { return method_exists($this, 'authorize'); } /** * Supports Complete Authorize * * @return boolean True if this gateway supports the completeAuthorize() method */ public function supportsCompleteAuthorize() { return method_exists($this, 'completeAuthorize'); } /** * Supports Capture * * @return boolean True if this gateway supports the capture() method */ public function supportsCapture() { return method_exists($this, 'capture'); } /** * Supports Purchase * * @return boolean True if this gateway supports the purchase() method */ public function supportsPurchase() { return method_exists($this, 'purchase'); } /** * Supports Complete Purchase * * @return boolean True if this gateway supports the completePurchase() method */ public function supportsCompletePurchase() { return method_exists($this, 'completePurchase'); } /** * Supports Fetch Transaction * * @return boolean True if this gateway supports the fetchTransaction() method */ public function supportsFetchTransaction() { return method_exists($this, 'fetchTransaction'); } /** * Supports Refund * * @return boolean True if this gateway supports the refund() method */ public function supportsRefund() { return method_exists($this, 'refund'); } /** * Supports Void * * @return boolean True if this gateway supports the void() method */ public function supportsVoid() { return method_exists($this, 'void'); } /** * Supports AcceptNotification * * @return boolean True if this gateway supports the acceptNotification() method */ public function supportsAcceptNotification() { return method_exists($this, 'acceptNotification'); } /** * Supports CreateCard * * @return boolean True if this gateway supports the create() method */ public function supportsCreateCard() { return method_exists($this, 'createCard'); } /** * Supports DeleteCard * * @return boolean True if this gateway supports the delete() method */ public function supportsDeleteCard() { return method_exists($this, 'deleteCard'); } /** * Supports UpdateCard * * @return boolean True if this gateway supports the update() method */ public function supportsUpdateCard() { return method_exists($this, 'updateCard'); } /** * Create and initialize a request object * * This function is usually used to create objects of type * Omnipay\Common\Message\AbstractRequest (or a non-abstract subclass of it) * and initialise them with using existing parameters from this gateway. * * Example: * * <code> * class MyRequest extends \Omnipay\Common\Message\AbstractRequest {}; * * class MyGateway extends \Omnipay\Common\AbstractGateway { * function myRequest($parameters) { * $this->createRequest('MyRequest', $parameters); * } * } * * // Create the gateway object * $gw = Omnipay::create('MyGateway'); * * // Create the request object * $myRequest = $gw->myRequest($someParameters); * </code> * * @param string $class The request class name * @param array $parameters * @return \Omnipay\Common\Message\AbstractRequest */ protected function createRequest($class, array $parameters) { $obj = new $class($this->httpClient, $this->httpRequest); return $obj->initialize(array_replace($this->getParameters(), $parameters)); } /** * Get the global default HTTP client. * * @return ClientInterface */ protected function getDefaultHttpClient() { return new Client(); } /** * Get the global default HTTP request. * * @return HttpRequest */ protected function getDefaultHttpRequest() { return HttpRequest::createFromGlobals(); } } common/src/Common/Item.php 0000666 00000003766 15165413756 0011517 0 ustar 00 <?php /** * Cart Item */ namespace Omnipay\Common; use Symfony\Component\HttpFoundation\ParameterBag; /** * Cart Item * * This class defines a single cart item in the Omnipay system. * */ class Item implements ItemInterface { use ParametersTrait; /** * Create a new item with the specified parameters * * @param array|null $parameters An array of parameters to set on the new object */ public function __construct(array $parameters = null) { $this->initialize($parameters); } /** * Initialize this item with the specified parameters * * @param array|null $parameters An array of parameters to set on this object * @return $this Item */ public function initialize(array $parameters = null) { $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } /** * {@inheritDoc} */ public function getName() { return $this->getParameter('name'); } /** * Set the item name */ public function setName($value) { return $this->setParameter('name', $value); } /** * {@inheritDoc} */ public function getDescription() { return $this->getParameter('description'); } /** * Set the item description */ public function setDescription($value) { return $this->setParameter('description', $value); } /** * {@inheritDoc} */ public function getQuantity() { return $this->getParameter('quantity'); } /** * Set the item quantity */ public function setQuantity($value) { return $this->setParameter('quantity', $value); } /** * {@inheritDoc} */ public function getPrice() { return $this->getParameter('price'); } /** * Set the item price */ public function setPrice($value) { return $this->setParameter('price', $value); } } common/src/Common/Http/Client.php 0000666 00000004364 15165413756 0012751 0 ustar 00 <?php namespace Omnipay\Common\Http; use function AmeliaGuzzleHttp\Psr7\str; use AmeliaHttp\Client\HttpClient; use AmeliaHttp\Discovery\HttpClientDiscovery; use AmeliaHttp\Discovery\MessageFactoryDiscovery; use AmeliaHttp\Message\RequestFactory; use Omnipay\Common\Http\Exception\NetworkException; use Omnipay\Common\Http\Exception\RequestException; use AmeliaPsr\Http\Message\RequestInterface; use AmeliaPsr\Http\Message\ResponseInterface; use AmeliaPsr\Http\Message\StreamInterface; use AmeliaPsr\Http\Message\UriInterface; class Client implements ClientInterface { /** * The Http Client which implements `public function sendRequest(RequestInterface $request)` * Note: Will be changed to PSR-18 when released * * @var HttpClient */ private $httpClient; /** * @var RequestFactory */ private $requestFactory; public function __construct($httpClient = null, RequestFactory $requestFactory = null) { $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); } /** * @param $method * @param $uri * @param array $headers * @param string|array|resource|StreamInterface|null $body * @param string $protocolVersion * @return ResponseInterface * @throws \Http\Client\Exception */ public function request( $method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1' ) { $request = $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocolVersion); return $this->sendRequest($request); } /** * @param RequestInterface $request * @return ResponseInterface * @throws \Http\Client\Exception */ private function sendRequest(RequestInterface $request) { try { return $this->httpClient->sendRequest($request); } catch (\Http\Client\Exception\NetworkException $networkException) { throw new NetworkException($networkException->getMessage(), $request, $networkException); } catch (\Exception $exception) { throw new RequestException($exception->getMessage(), $request, $exception); } } } common/src/Common/Http/Exception/NetworkException.php 0000666 00000000202 15165413756 0016764 0 ustar 00 <?php namespace Omnipay\Common\Http\Exception; use Omnipay\Common\Http\Exception; class NetworkException extends Exception { } common/src/Common/Http/Exception/RequestException.php 0000666 00000000202 15165413756 0016763 0 ustar 00 <?php namespace Omnipay\Common\Http\Exception; use Omnipay\Common\Http\Exception; class RequestException extends Exception { } common/src/Common/Http/Exception.php 0000666 00000001243 15165413756 0013462 0 ustar 00 <?php namespace Omnipay\Common\Http; use AmeliaPsr\Http\Message\RequestInterface; use Throwable; abstract class Exception extends \RuntimeException { /** @var RequestInterface */ protected $request; public function __construct($message, RequestInterface $request, $previous = null) { $this->request = $request; parent::__construct($message, 0, $previous); } /** * Returns the request. * * The request object MAY be a different object from the one passed to ClientInterface::sendRequest() * * @return RequestInterface */ public function getRequest() { return $this->request; } } common/src/Common/Http/ClientInterface.php 0000666 00000002071 15165413756 0014563 0 ustar 00 <?php namespace Omnipay\Common\Http; use Omnipay\Common\Http\Exception\NetworkException; use Omnipay\Common\Http\Exception\RequestException; use AmeliaPsr\Http\Message\ResponseInterface; use AmeliaPsr\Http\Message\StreamInterface; use AmeliaPsr\Http\Message\UriInterface; interface ClientInterface { /** * Creates a new PSR-7 request. * * @param string $method * @param string|UriInterface $uri * @param array $headers * @param resource|string|StreamInterface|null $body * @param string $protocolVersion * * @throws RequestException when the HTTP client is passed a request that is invalid and cannot be sent. * @throws NetworkException if there is an error with the network or the remote server cannot be reached. * * @return ResponseInterface */ public function request( $method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1' ); } common/src/Common/PaymentMethod.php 0000666 00000002046 15165413756 0013365 0 ustar 00 <?php /** * Payment Method */ namespace Omnipay\Common; /** * Payment Method * * This class defines a payment method to be used in the Omnipay system. * */ class PaymentMethod { /** * The ID of the payment method. Used as the payment method ID in the * Issuer class. * * @var string */ protected $id; /** * The full name of the payment method * * @var string */ protected $name; /** * Create a new PaymentMethod * * @param string $id The identifier of this payment method * @param string $name The name of this payment method */ public function __construct($id, $name) { $this->id = $id; $this->name = $name; } /** * The identifier of this payment method * * @return string */ public function getId() { return $this->id; } /** * The name of this payment method * * @return string */ public function getName() { return $this->name; } } common/src/Common/Helper.php 0000666 00000010106 15165413756 0012022 0 ustar 00 <?php /** * Helper class */ namespace Omnipay\Common; use InvalidArgumentException; /** * Helper class * * This class defines various static utility functions that are in use * throughout the Omnipay system. */ class Helper { /** * Convert a string to camelCase. Strings already in camelCase will not be harmed. * * @param string $str The input string * @return string camelCased output string */ public static function camelCase($str) { $str = self::convertToLowercase($str); return preg_replace_callback( '/_([a-z])/', function ($match) { return strtoupper($match[1]); }, $str ); } /** * Convert strings with underscores to be all lowercase before camelCase is preformed. * * @param string $str The input string * @return string The output string */ protected static function convertToLowercase($str) { $explodedStr = explode('_', $str); $lowercasedStr = []; if (count($explodedStr) > 1) { foreach ($explodedStr as $value) { $lowercasedStr[] = strtolower($value); } $str = implode('_', $lowercasedStr); } return $str; } /** * Validate a card number according to the Luhn algorithm. * * @param string $number The card number to validate * @return boolean True if the supplied card number is valid */ public static function validateLuhn($number) { $str = ''; foreach (array_reverse(str_split($number)) as $i => $c) { $str .= $i % 2 ? $c * 2 : $c; } return array_sum(str_split($str)) % 10 === 0; } /** * Initialize an object with a given array of parameters * * Parameters are automatically converted to camelCase. Any parameters which do * not match a setter on the target object are ignored. * * @param mixed $target The object to set parameters on * @param array $parameters An array of parameters to set */ public static function initialize($target, array $parameters = null) { if ($parameters) { foreach ($parameters as $key => $value) { $method = 'set'.ucfirst(static::camelCase($key)); if (method_exists($target, $method)) { $target->$method($value); } } } } /** * Resolve a gateway class to a short name. * * The short name can be used with GatewayFactory as an alias of the gateway class, * to create new instances of a gateway. */ public static function getGatewayShortName($className) { if (0 === strpos($className, '\\')) { $className = substr($className, 1); } if (0 === strpos($className, 'Omnipay\\')) { return trim(str_replace('\\', '_', substr($className, 8, -7)), '_'); } return '\\'.$className; } /** * Resolve a short gateway name to a full namespaced gateway class. * * Class names beginning with a namespace marker (\) are left intact. * Non-namespaced classes are expected to be in the \Omnipay namespace, e.g.: * * \Custom\Gateway => \Custom\Gateway * \Custom_Gateway => \Custom_Gateway * Stripe => \Omnipay\Stripe\Gateway * PayPal\Express => \Omnipay\PayPal\ExpressGateway * PayPal_Express => \Omnipay\PayPal\ExpressGateway * * @param string $shortName The short gateway name * @return string The fully namespaced gateway class name */ public static function getGatewayClassName($shortName) { if (0 === strpos($shortName, '\\')) { return $shortName; } // replace underscores with namespace marker, PSR-0 style $shortName = str_replace('_', '\\', $shortName); if (false === strpos($shortName, '\\')) { $shortName .= '\\'; } return '\\Omnipay\\'.$shortName.'Gateway'; } } common/CONTRIBUTING.md 0000666 00000001040 15165413756 0010301 0 ustar 00 # Contributing Guidelines * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. * Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) style and that all tests pass. * Send the pull request. * Check that the Travis CI build passed. If not, rinse and repeat. common/UPGRADE.md 0000666 00000005462 15165413756 0007475 0 ustar 00 ## Upgrade apps from 2.x to 3.x - The `redirect()` method no longer calls `exit()` after sending the content. This is up to the developer now. - It is now possible to use `setAmountInteger(integer $value)` and `setMoney(Money $money)` - HTTPPlug is used. Guzzle will be installed when using `omnipay/omnipay`, otherwise you need to require your own implementation (see http://docs.php-http.org/en/latest/clients.html) - The package is renamed from `omnipay/omnipay` to `league/omnipay` and no longer installs all gateways by default. ## Upgrade Gateways from 2.x to 3.x The primary difference is the HTTP Client. We are now using HTTPlug (http://httplug.io/) but rely on our own interface. ### Breaking - Change typehint from Guzzle ClientInterface to `Omnipay\Common\Http\ClientInterface` - `$client->get('..')`/`$client->post('..')` etc are removed, you can call `$client->request('GET', '')`. - No need to call `$request->send()`, requests are sent directly. - Instead of `$client->createRequest(..)` you can create+send the request directly with `$client->request(..)`. - When sending a JSON body, convert the body to a string with `json_encode()` and set the correct Content-Type. - The response is a PSR-7 Response object. You can call `$response->getBody()->getContents()` to get the body as a string. - `$response->json()` and `$response->xml()` are gone, but you can implement the logic directly. - An HTTP Client is no longer added by default by `omnipay/common`, but `omnipay/omnipay` will add Guzzle. Gateways should not rely on Guzzle or other clients directly. - `$body` should be a string (eg. `http_build_query($data)` or `json_encode($data)` instead of just `$data`). - The `$headers` parameters should be an `array` (not `null`, but can be empty) Examples: ```php // V2 XML: $response = $this->httpClient->post($this->endpoint, null, $data)->send(); $result = $httpResponse->xml(); // V3 XML: $response = $this->httpClient->request('POST', $this->endpoint, [], http_build_query($data)); $result = simplexml_load_string($httpResponse->getBody()->getContents()); ``` ```php // Example JSON request: $response = $this->httpClient->request('POST', $this->endpoint, [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', ], json_encode($data)); $result = json_decode($response->getBody()->getContents(), true); ``` #### Testing PHPUnit is upgraded to PHPUnit 6. Common issues: - `setExpectedException()` is removed ```php // PHPUnit 5: $this->setExpectedException($class, $message); // PHPUnit 6: $this->expectException($class); $this->expectExceptionMessage($message); ``` - Tests that do not perform any assertions, will be marked as risky. This can be avoided by annotating them with ` @doesNotPerformAssertions` - You should remove the `Mockery\Adapter\Phpunit\TestListener` in phpunit.xml.dist common/README.md 0000666 00000005260 15165413756 0007337 0 ustar 00 # Omnipay Common **Core components for the Omnipay PHP payment processing library** [![Latest Version on Packagist][ico-version]][link-packagist] [![Software License][ico-license]](LICENSE.md) [![Build Status][ico-travis]][link-travis] [![Coverage Status][ico-scrutinizer]][link-scrutinizer] [![Quality Score][ico-code-quality]][link-code-quality] [![Total Downloads][ico-downloads]][link-downloads] [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP. This package implements common classes required by Omnipay. ## Documentation Please see [https://omnipay.thephpleague.com/](https://omnipay.thephpleague.com/) for the installation & usage documentation. ## Change log Please see [UPGRADE](UPGRADE.md) for more information on how to upgrade to the latest version. ## Support If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-common/issues), or better yet, fork the library and submit a pull request. ## Security If you discover any security related issues, please email barryvdh@gmail.com instead of using the issue tracker. ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. [ico-version]: https://img.shields.io/packagist/v/omnipay/common.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square [ico-travis]: https://img.shields.io/travis/thephpleague/omnipay-common/master.svg?style=flat-square [ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/thephpleague/omnipay-common.svg?style=flat-square [ico-code-quality]: https://img.shields.io/scrutinizer/g/thephpleague/omnipay-common.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/omnipay/common.svg?style=flat-square [link-packagist]: https://packagist.org/packages/omnipay/common [link-travis]: https://travis-ci.org/thephpleague/omnipay-common [link-scrutinizer]: https://scrutinizer-ci.com/g/thephpleague/omnipay-common/code-structure [link-code-quality]: https://scrutinizer-ci.com/g/thephpleague/omnipay-common [link-downloads]: https://packagist.org/packages/omnipay/common [link-contributors]: ../../contributors paypal/LICENSE 0000666 00000002047 15165413756 0007063 0 ustar 00 Copyright (c) 2012-2013 Adrian Macneil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. paypal/phpunit.xml.dist 0000666 00000001230 15165413756 0011222 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false"> <testsuites> <testsuite name="Omnipay Test Suite"> <directory>./tests/</directory> </testsuite> </testsuites> <filter> <whitelist> <directory>./src</directory> </whitelist> </filter> </phpunit> paypal/.travis.yml 0000666 00000001035 15165413756 0010163 0 ustar 00 language: php php: - 5.6 - 7.0 - 7.1 - 7.2 env: global: - setup=basic matrix: include: - php: 5.6 env: setup=lowest sudo: false before_install: - travis_retry composer self-update install: - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist; fi - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text paypal/.gitignore 0000666 00000000167 15165413756 0010047 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml .idea/ .directory dirlist.app dirlist.vendor dirlist.cache documents/ paypal/README.md 0000666 00000004370 15165413756 0007336 0 ustar 00 # Omnipay: PayPal **PayPal driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-paypal) [](https://packagist.org/packages/omnipay/paypal) [](https://packagist.org/packages/omnipay/paypal) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP. This package implements PayPal support for Omnipay. ## Installation Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/paypal` with Composer: ``` composer require league/omnipay omnipay/paypal ``` ## Basic Usage The following gateways are provided by this package: * PayPal_Express (PayPal Express Checkout) * PayPal_ExpressInContext (PayPal Express In-Context Checkout) * PayPal_Pro (PayPal Website Payments Pro) * PayPal_Rest (Paypal Rest API) For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. ## Quirks The transaction reference obtained from the purchase() response can't be used to refund a purchase. The transaction reference from the completePurchase() response is the one that should be used. ## Out Of Scope Omnipay does not cover recurring payments or billing agreements, and so those features are not included in this package. Extensions to this gateway are always welcome. ## Support If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-paypal/issues), or better yet, fork the library and submit a pull request. paypal/tests/ProGatewayTest.php 0000666 00000003340 15165413756 0012650 0 ustar 00 <?php namespace Omnipay\PayPal; use Omnipay\Tests\GatewayTestCase; use Omnipay\Common\CreditCard; class ProGatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new ProGateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'card' => new CreditCard(array( 'firstName' => 'Example', 'lastName' => 'User', 'number' => '4111111111111111', 'expiryMonth' => '12', 'expiryYear' => date('Y'), 'cvv' => '123', )), ); } public function testAuthorize() { $this->setMockHttpResponse('ProPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('96U93778BD657313D', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testPurchase() { $this->setMockHttpResponse('ProPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('96U93778BD657313D', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testFetchTransaction() { $request = $this->gateway->fetchTransaction(array('transactionReference' => 'abc123')); $this->assertInstanceOf('\Omnipay\PayPal\Message\FetchTransactionRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); } } paypal/tests/RestGatewayTest.php 0000666 00000026111 15165413756 0013026 0 ustar 00 <?php namespace Omnipay\PayPal; use Omnipay\Tests\GatewayTestCase; use Omnipay\Common\CreditCard; class RestGatewayTest extends GatewayTestCase { /** @var RestGateway */ public $gateway; /** @var array */ public $options; /** @var array */ public $subscription_options; public function setUp() { parent::setUp(); $this->gateway = new RestGateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setToken('TEST-TOKEN-123'); $this->gateway->setTokenExpires(time() + 600); $this->options = array( 'amount' => '10.00', 'card' => new CreditCard(array( 'firstName' => 'Example', 'lastName' => 'User', 'number' => '4111111111111111', 'expiryMonth' => '12', 'expiryYear' => date('Y'), 'cvv' => '123', )), ); $this->subscription_options = array( 'transactionReference' => 'ABC-1234', 'description' => 'Description goes here', ); } public function testBearerToken() { $this->gateway->setToken(''); $this->setMockHttpResponse('RestTokenSuccess.txt'); $this->assertFalse($this->gateway->hasToken()); $this->assertEquals('A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0', $this->gateway->getToken()); // triggers request $this->assertEquals(time() + 28800, $this->gateway->getTokenExpires()); $this->assertTrue($this->gateway->hasToken()); } public function testBearerTokenReused() { $this->setMockHttpResponse('RestTokenSuccess.txt'); $this->gateway->setToken('MYTOKEN'); $this->gateway->setTokenExpires(time() + 60); $this->assertTrue($this->gateway->hasToken()); $this->assertEquals('MYTOKEN', $this->gateway->getToken()); } public function testBearerTokenExpires() { $this->setMockHttpResponse('RestTokenSuccess.txt'); $this->gateway->setToken('MYTOKEN'); $this->gateway->setTokenExpires(time() - 60); $this->assertFalse($this->gateway->hasToken()); $this->assertEquals('A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0', $this->gateway->getToken()); } public function testAuthorize() { $this->setMockHttpResponse('RestPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('44E89981F8714392Y', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testPurchase() { $this->setMockHttpResponse('RestPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('44E89981F8714392Y', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testCapture() { $request = $this->gateway->capture(array( 'transactionReference' => 'abc123', 'amount' => 10.00, 'currency' => 'AUD', )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestCaptureRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/authorization/abc123/capture', $endPoint); $data = $request->getData(); $this->assertNotEmpty($data); } public function testRefund() { $request = $this->gateway->refund(array( 'transactionReference' => 'abc123', 'amount' => 10.00, 'currency' => 'AUD', )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestRefundRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/sale/abc123/refund', $endPoint); $data = $request->getData(); $this->assertNotEmpty($data); } public function testFullRefund() { $request = $this->gateway->refund(array( 'transactionReference' => 'abc123', )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestRefundRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/sale/abc123/refund', $endPoint); $data = $request->getData(); // we're expecting an empty object here $json = json_encode($data); $this->assertEquals('{}', $json); } public function testFetchTransaction() { $request = $this->gateway->fetchTransaction(array('transactionReference' => 'abc123')); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestFetchTransactionRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $data = $request->getData(); $this->assertEmpty($data); } public function testListPlan() { $request = $this->gateway->listPlan(array( 'page' => 0, 'status' => 'ACTIVE', 'pageSize' => 10, //number of plans in a single page 'totalRequired' => 'yes' )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestListPlanRequest', $request); $this->assertSame(0, $request->getPage()); $this->assertSame('ACTIVE', $request->getStatus()); $this->assertSame(10, $request->getPageSize()); $this->assertSame('yes', $request->getTotalRequired()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/billing-plans', $endPoint); $data = $request->getData(); $this->assertNotEmpty($data); } public function testFetchPurchase() { $request = $this->gateway->fetchPurchase(array('transactionReference' => 'abc123')); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestFetchPurchaseRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $data = $request->getData(); $this->assertEmpty($data); } public function testListPurchase() { $request = $this->gateway->listPurchase(array( 'count' => 15, 'startId' => 'PAY123', 'startIndex' => 1, 'startTime' => '2015-09-07T00:00:00Z', 'endTime' => '2015-09-08T00:00:00Z', )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestListPurchaseRequest', $request); $this->assertSame(15, $request->getCount()); $this->assertSame('PAY123', $request->getStartId()); $this->assertSame(1, $request->getStartIndex()); $this->assertSame('2015-09-07T00:00:00Z', $request->getStartTime()); $this->assertSame('2015-09-08T00:00:00Z', $request->getEndTime()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/payment', $endPoint); $data = $request->getData(); $this->assertNotEmpty($data); } public function testCreateCard() { $this->setMockHttpResponse('RestCreateCardSuccess.txt'); $response = $this->gateway->createCard($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testPayWithSavedCard() { $this->setMockHttpResponse('RestCreateCardSuccess.txt'); $response = $this->gateway->createCard($this->options)->send(); $cardRef = $response->getCardReference(); $this->setMockHttpResponse('RestPurchaseSuccess.txt'); $response = $this->gateway->purchase(array('amount'=>'10.00', 'cardReference'=>$cardRef))->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('44E89981F8714392Y', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } // Incomplete generic tests for subscription payments public function testCompleteSubscription() { $this->setMockHttpResponse('RestExecuteSubscriptionSuccess.txt'); $response = $this->gateway->completeSubscription($this->subscription_options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getMessage()); $this->assertEquals('I-0LN988D3JACS', $response->getTransactionReference()); } public function testCancelSubscription() { $this->setMockHttpResponse('RestGenericSubscriptionSuccess.txt'); $response = $this->gateway->cancelSubscription($this->subscription_options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getMessage()); } public function testSuspendSubscription() { $this->setMockHttpResponse('RestGenericSubscriptionSuccess.txt'); $response = $this->gateway->suspendSubscription($this->subscription_options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getMessage()); } public function testReactivateSubscription() { $this->setMockHttpResponse('RestGenericSubscriptionSuccess.txt'); $response = $this->gateway->reactivateSubscription($this->subscription_options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getMessage()); } public function testRefundCapture() { $request = $this->gateway->refundCapture(array( 'transactionReference' => 'abc123' )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestRefundCaptureRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/capture/abc123/refund', $endPoint); $request->setAmount('15.99'); $request->setCurrency('BRL'); $request->setDescription('Test Description'); $data = $request->getData(); // we're expecting an empty object here $json = json_encode($data); $this->assertEquals('{"amount":{"currency":"BRL","total":"15.99"},"description":"Test Description"}', $json); } public function testVoid() { $request = $this->gateway->void(array( 'transactionReference' => 'abc123' )); $this->assertInstanceOf('\Omnipay\PayPal\Message\RestVoidRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); $endPoint = $request->getEndpoint(); $this->assertSame('https://api.paypal.com/v1/payments/authorization/abc123/void', $endPoint); $data = $request->getData(); $this->assertEmpty($data); } } paypal/tests/ExpressInContextGatewayTest.php 0000666 00000005053 15165413756 0015400 0 ustar 00 <?php namespace Omnipay\PayPal; use Omnipay\Tests\GatewayTestCase; class ExpressInContextGatewayTest extends GatewayTestCase { /** * @var \Omnipay\PayPal\ExpressInContextGateway */ protected $gateway; /** * @var array */ protected $options; /** * @var array */ protected $voidOptions; public function setUp() { parent::setUp(); $this->gateway = new ExpressInContextGateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', ); $this->voidOptions = array( 'transactionReference' => 'ASDFASDFASDF', ); } public function testAuthorizeSuccess() { $this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); } public function testPurchaseSuccess() { $this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); } public function testOrderSuccess() { $this->setMockHttpResponse('ExpressOrderSuccess.txt'); $response = $this->gateway->order($this->options)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); } } paypal/tests/ExpressGatewayTest.php 0000666 00000017540 15165413756 0013550 0 ustar 00 <?php namespace Omnipay\PayPal; use Omnipay\Tests\GatewayTestCase; class ExpressGatewayTest extends GatewayTestCase { /** * @var \Omnipay\PayPal\ExpressGateway */ protected $gateway; /** * @var array */ protected $options; /** * @var array */ protected $voidOptions; public function setUp() { parent::setUp(); $this->gateway = new ExpressGateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', ); $this->voidOptions = array( 'transactionReference' => 'ASDFASDFASDF', ); } public function testAuthorizeSuccess() { $this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); } public function testAuthorizeFailure() { $this->setMockHttpResponse('ExpressPurchaseFailure.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage()); } public function testPurchaseSuccess() { $this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); } public function testPurchaseFailure() { $this->setMockHttpResponse('ExpressPurchaseFailure.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage()); } public function testOrderSuccess() { $this->setMockHttpResponse('ExpressOrderSuccess.txt'); $response = $this->gateway->order($this->options)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); } public function testOrderFailure() { $this->setMockHttpResponse('ExpressOrderFailure.txt'); $response = $this->gateway->order($this->options)->send(); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage()); } public function testVoidSuccess() { $this->setMockHttpResponse('ExpressVoidSuccess.txt'); $response = $this->gateway->void($this->voidOptions)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('ASDFASDFASDF', $response->getTransactionReference()); } public function testVoidFailure() { $this->setMockHttpResponse('ExpressVoidFailure.txt'); $response = $this->gateway->void($this->voidOptions)->send(); $this->assertInstanceOf('\Omnipay\PayPal\Message\Response', $response); $this->assertFalse($response->isSuccessful()); } public function testFetchCheckout() { $options = array('token' => 'abc123'); $request = $this->gateway->fetchCheckout($options); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressFetchCheckoutRequest', $request); $this->assertSame('abc123', $request->getToken()); } public function testCompletePurchaseFailureRedirect() { $this->setMockHttpResponse('ExpressCompletePurchaseFailureRedirect.txt'); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals('ASDFASDFASDF', $response->getTransactionReference()); $this->assertSame('This transaction couldn\'t be completed. Please redirect your customer to PayPal.', $response->getMessage()); } public function testCompletePurchaseHttpOptions() { $this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); $this->getHttpRequest()->query->replace(array( 'token' => 'GET_TOKEN', 'PayerID' => 'GET_PAYERID', )); $response = $this->gateway->completePurchase(array( 'amount' => '10.00', 'currency' => 'EUR', ))->send(); $httpRequests = $this->getMockedRequests(); $httpRequest = $httpRequests[0]; parse_str((string)$httpRequest->getBody(), $postData); $this->assertSame('GET_TOKEN', $postData['TOKEN']); $this->assertSame('GET_PAYERID', $postData['PAYERID']); } public function testCompletePurchaseCustomOptions() { $this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); // Those values should not be used if custom token or payerid are passed $this->getHttpRequest()->query->replace(array( 'token' => 'GET_TOKEN', 'PayerID' => 'GET_PAYERID', )); $response = $this->gateway->completePurchase(array( 'amount' => '10.00', 'currency' => 'EUR', 'token' => 'CUSTOM_TOKEN', 'payerid' => 'CUSTOM_PAYERID', ))->send(); $httpRequests = $this->getMockedRequests(); $httpRequest = $httpRequests[0]; parse_str((string)$httpRequest->getBody(), $postData); $this->assertSame('CUSTOM_TOKEN', $postData['TOKEN']); $this->assertSame('CUSTOM_PAYERID', $postData['PAYERID']); } public function testTransactionSearch() { $transactionSearch = $this->gateway->transactionSearch(array( 'startDate' => '2015-01-01', 'endDate' => '2015-12-31', )); $this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressTransactionSearchRequest', $transactionSearch); $this->assertInstanceOf('\DateTime', $transactionSearch->getStartDate()); $this->assertInstanceOf('\DateTime', $transactionSearch->getEndDate()); } } paypal/tests/Mock/ExpressOrderFailure.txt 0000666 00000000666 15165413756 0014614 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 19:21:05 GMT Server: Apache Content-Length: 292 Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2013%2d02%2d15T19%3a21%3a06Z&CORRELATIONID=2b58be2b8e60e&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10525&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20The%20amount%20to%20be%20charged%20is%20zero%2e&L_SEVERITYCODE0=Error paypal/tests/Mock/RestFetchPurchaseSuccess.txt 0000666 00000003204 15165413756 0015561 0 ustar 00 HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=1534 Paypal-Debug-Id: 98cbd3ab19dfe SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=129&TopLevelTxnStartTime=146fc9074ec&Host=slcsbjm3.slc.paypal.com&pid=15797 CORRELATION-ID: 98cbd3ab19dfe Content-Language: * Date: Thu, 03 Jul 2014 14:11:10 GMT Content-Type: application/json { "id": "PAY-0WB587530N302915SKXWVCSQ", "create_time": "2015-09-07T08:56:42Z", "update_time": "2015-09-07T08:56:42Z", "state": "created", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "shipping_address": [] } }, "transactions": [ { "amount": { "total": "10.00", "currency": "AUD", "details": { "subtotal": "10.00" } }, "description": "This is a test purchase transaction.", "related_resources": [] } ], "links": [ { "href": "https:\/\/api.sandbox.paypal.com\/v1\/payments\/payment\/PAY-0WB587530N302915SKXWVCSQ", "rel": "self", "method": "GET" }, { "href": "https:\/\/www.sandbox.paypal.com\/cgi-bin\/webscr?cmd=_express-checkout&token=EC-3DR71034MD528800J", "rel": "approval_url", "method": "REDIRECT" }, { "href": "https:\/\/api.sandbox.paypal.com\/v1\/payments\/payment\/PAY-0WB587530N302915SKXWVCSQ\/execute", "rel": "execute", "method": "POST" } ] } paypal/tests/Mock/ExpressCompletePurchaseFailure.txt 0000666 00000000550 15165413756 0016774 0 ustar 00 HTTP/1.1 200 OK Date: Wed, 20 Feb 2013 13:55:50 GMT Server: Apache Content-Length: 214 Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2013%2d02%2d20T13%3a55%3a50Z&CORRELATIONID=73310039452e7&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10410&L_SHORTMESSAGE0=Invalid%20token&L_LONGMESSAGE0=Invalid%20token%2e&L_SEVERITYCODE0=Error paypal/tests/Mock/RestTokenSuccess.txt 0000666 00000001337 15165413756 0014122 0 ustar 00 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=3205 Paypal-Debug-Id: 217a9ddefd384 SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=91&TopLevelTxnStartTime=146fbfe679a&Host=slcsbidensectoken502.slc.paypal.com&pid=29059 CORRELATION-ID: 217a9ddefd384 Date: Thu, 03 Jul 2014 11:31:32 GMT Content-Type: application/json Content-Length: 328 {"scope":"openid https://uri.paypal.com/services/invoicing https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/vault/credit-card","access_token":"A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":28800} paypal/tests/Mock/ExpressVoidSuccess.txt 0000666 00000000432 15165413756 0014452 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 19:19:21 GMT Server: Apache Content-Length: 136 Connection: close Content-Type: text/plain; charset=utf-8 AUTHORIZATIONID=ASDFASDFASDF&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305 paypal/tests/Mock/RestGenericSubscriptionSuccess.txt 0000666 00000000543 15165413756 0017021 0 ustar 00 HTTP/1.1 204 OK Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=3205 Paypal-Debug-Id: 217a9ddefd384 SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=91&TopLevelTxnStartTime=146fbfe679a&Host=slcsbidensectoken502.slc.paypal.com&pid=29059 CORRELATION-ID: 217a9ddefd384 Date: Thu, 03 Jul 2014 11:31:32 GMT paypal/tests/Mock/ProPurchaseFailure.txt 0000666 00000000746 15165413756 0014421 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 18:49:26 GMT Server: Apache Content-Length: 340 Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2013%2d02%2d15T18%3a49%3a27Z&CORRELATIONID=ec641b50c33b0&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10562&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20expiration%20year%2e&L_SEVERITYCODE0=Error&AMT=150%2e04&CURRENCYCODE=USD paypal/tests/Mock/RestRefundSuccess.txt 0000666 00000001764 15165413756 0014271 0 ustar 00 HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=76018 Paypal-Debug-Id: 965491cb1a1e5 SERVER_INFO: paymentsplatformserv:v1.payments.sale&CalThreadId=129&TopLevelTxnStartTime=14701c36ef9&Host=slcsbjm3.slc.paypal.com&pid=15797 CORRELATION-ID: 965491cb1a1e5 Content-Language: * Date: Fri, 04 Jul 2014 14:24:52 GMT Content-Type: application/json Content-Length: 592 {"id":"7G199247NK652674M","create_time":"2014-07-04T14:24:52Z","update_time":"2014-07-04T14:24:52Z","state":"completed","amount":{"total":"2.34","currency":"USD"},"sale_id":"44E89981F8714392Y","parent_payment":"PAY-6RT04683U7444573DKO2WI6A","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/refund/7G199247NK652674M","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RT04683U7444573DKO2WI6A","rel":"parent_payment","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/44E89981F8714392Y","rel":"sale","method":"GET"}]} paypal/tests/Mock/RestCreateCardSuccess.txt 0000666 00000002152 15165413756 0015033 0 ustar 00 HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=39734 Paypal-Debug-Id: 17a8320884bba Content-Language: * CORRELATION-ID: 17a8320884bba Date: Fri, 04 Jul 2014 14:50:33 GMT SERVER_INFO: vaultplatformserv:v1.vault.credit-card&CalThreadId=76352&TopLevelTxnStartTime=14701dafae7&Host=slcsbvaultplatformserv501.slc.paypal.com&pid=19516 Content-Type: application/json Content-Length: 690 {"id":"CARD-70E78145XN686604FKO3L6OQ","state":"ok","payer_id":"user12345","type":"visa","number":"xxxxxxxxxxxx0331","expire_month":"11","expire_year":"2018","first_name":"Betsy","last_name":"Buyer","valid_until":"2017-07-03T00:00:00Z","create_time":"2014-07-04T14:50:34Z","update_time":"2014-07-04T14:50:34Z","links":[{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-70E78145XN686604FKO3L6OQ","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-70E78145XN686604FKO3L6OQ","rel":"delete","method":"DELETE"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-70E78145XN686604FKO3L6OQ","rel":"patch","method":"PATCH"}]} paypal/tests/Mock/RestCompletePurchaseFailure.txt 0000666 00000001262 15165413756 0016261 0 ustar 00 HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbplatformapiserv3002.slc.paypal.com;threadId=533 Paypal-Debug-Id: 65f24674659dc SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=166&TopLevelTxnStartTime=14b8c851ff1&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=12653 Content-Language: * Date: Sun, 15 Feb 2015 09:15:09 GMT Connection: close, close Content-Type: application/json Content-Length: 235 {"name":"PAYMENT_STATE_INVALID","message":"This request is invalid due to the current state of the payment","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID","debug_id":"65f24674659dc"} paypal/tests/Mock/ExpressTransactionSearchResponse.txt 0000666 00000023361 15165413756 0017360 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Feb 2016 18:30:58 GMT Server: Apache X-PAYPAL-OPERATION-NAME: TransactionSearch Connection: close HTTP_X_PP_AZ_LOCATOR: sandbox3 Content-Length: 9990 Content-Type: text/plain; charset=utf-8 L_TIMESTAMP0=2016%2d02%2d01T18%3a47%3a21Z&L_TIMESTAMP1=2016%2d02%2d01T18%3a47%3a17Z&L_TIMESTAMP2=2015%2d12%2d19T18%3a56%3a28Z&L_TIMESTAMP3=2015%2d12%2d19T18%3a56%3a25Z&L_TIMESTAMP4=2015%2d12%2d19T18%3a49%3a00Z&L_TIMESTAMP5=2015%2d12%2d19T18%3a48%3a57Z&L_TIMESTAMP6=2015%2d12%2d19T18%3a41%3a55Z&L_TIMESTAMP7=2015%2d12%2d19T18%3a41%3a52Z&L_TIMESTAMP8=2015%2d12%2d19T18%3a26%3a13Z&L_TIMESTAMP9=2015%2d12%2d19T18%3a21%3a03Z&L_TIMESTAMP10=2015%2d12%2d19T17%3a06%3a11Z&L_TIMESTAMP11=2015%2d12%2d19T17%3a05%3a15Z&L_TIMESTAMP12=2015%2d12%2d19T17%3a02%3a06Z&L_TIMESTAMP13=2015%2d12%2d19T17%3a01%3a42Z&L_TIMESTAMP14=2015%2d12%2d19T16%3a59%3a20Z&L_TIMESTAMP15=2015%2d12%2d19T16%3a58%3a54Z&L_TIMESTAMP16=2015%2d12%2d19T16%3a52%3a10Z&L_TIMESTAMP17=2015%2d12%2d19T16%3a51%3a26Z&L_TIMESTAMP18=2015%2d12%2d19T16%3a32%3a29Z&L_TIMESTAMP19=2015%2d12%2d19T16%3a31%3a41Z&L_TIMESTAMP20=2015%2d12%2d19T16%3a20%3a01Z&L_TIMESTAMP21=2015%2d12%2d19T16%3a00%3a50Z&L_TIMESTAMP22=2015%2d12%2d19T15%3a45%3a56Z&L_TIMESTAMP23=2015%2d12%2d18T22%3a35%3a53Z&L_TIMESTAMP24=2015%2d12%2d18T22%3a34%3a45Z&L_TIMESTAMP25=2015%2d12%2d18T22%3a29%3a37Z&L_TIMESTAMP26=2015%2d12%2d18T22%3a16%3a42Z&L_TIMESTAMP27=2015%2d12%2d18T22%3a12%3a29Z&L_TIMESTAMP28=2015%2d12%2d18T21%3a36%3a40Z&L_TIMESTAMP29=2015%2d12%2d18T21%3a07%3a59Z&L_TIMESTAMP30=2015%2d12%2d18T19%3a36%3a27Z&L_TIMESTAMP31=2015%2d12%2d18T19%3a09%3a21Z&L_TIMESTAMP32=2015%2d12%2d18T17%3a27%3a39Z&L_TIMESTAMP33=2015%2d12%2d18T17%3a05%3a32Z&L_TIMEZONE0=GMT&L_TIMEZONE1=GMT&L_TIMEZONE2=GMT&L_TIMEZONE3=GMT&L_TIMEZONE4=GMT&L_TIMEZONE5=GMT&L_TIMEZONE6=GMT&L_TIMEZONE7=GMT&L_TIMEZONE8=GMT&L_TIMEZONE9=GMT&L_TIMEZONE10=GMT&L_TIMEZONE11=GMT&L_TIMEZONE12=GMT&L_TIMEZONE13=GMT&L_TIMEZONE14=GMT&L_TIMEZONE15=GMT&L_TIMEZONE16=GMT&L_TIMEZONE17=GMT&L_TIMEZONE18=GMT&L_TIMEZONE19=GMT&L_TIMEZONE20=GMT&L_TIMEZONE21=GMT&L_TIMEZONE22=GMT&L_TIMEZONE23=GMT&L_TIMEZONE24=GMT&L_TIMEZONE25=GMT&L_TIMEZONE26=GMT&L_TIMEZONE27=GMT&L_TIMEZONE28=GMT&L_TIMEZONE29=GMT&L_TIMEZONE30=GMT&L_TIMEZONE31=GMT&L_TIMEZONE32=GMT&L_TIMEZONE33=GMT&L_TYPE0=Payment&L_TYPE1=Authorization&L_TYPE2=Payment&L_TYPE3=Authorization&L_TYPE4=Payment&L_TYPE5=Authorization&L_TYPE6=Payment&L_TYPE7=Authorization&L_TYPE8=Authorization&L_TYPE9=Authorization&L_TYPE10=Payment&L_TYPE11=Authorization&L_TYPE12=Payment&L_TYPE13=Authorization&L_TYPE14=Payment&L_TYPE15=Authorization&L_TYPE16=Payment&L_TYPE17=Authorization&L_TYPE18=Payment&L_TYPE19=Authorization&L_TYPE20=Payment&L_TYPE21=Authorization&L_TYPE22=Authorization&L_TYPE23=Payment&L_TYPE24=Authorization&L_TYPE25=Payment&L_TYPE26=Authorization&L_TYPE27=Payment&L_TYPE28=Authorization&L_TYPE29=Payment&L_TYPE30=Authorization&L_TYPE31=Authorization&L_TYPE32=Authorization&L_TYPE33=Authorization&L_EMAIL0=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL1=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL2=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL3=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL4=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL5=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL6=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL7=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL8=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL9=jhon%2emacgiver%2dbuyer%2d1%40email%2ecom&L_EMAIL10=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL11=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL12=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL13=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL14=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL15=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL16=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL17=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL18=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL19=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL20=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL21=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL22=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL23=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL24=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL25=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL26=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL27=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL28=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL29=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL30=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL31=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL32=jhon%2ecarter%2dbuyer%40test%2ecom&L_EMAIL33=jhon%2ecarter%2dbuyer%40test%2ecom&L_NAME0=Customer%20Buyer&L_NAME1=Customer%20Buyer&L_NAME2=Customer%20Buyer&L_NAME3=Customer%20Buyer&L_NAME4=Customer%20Buyer&L_NAME5=Customer%20Buyer&L_NAME6=Customer%20Buyer&L_NAME7=Customer%20Buyer&L_NAME8=Customer%20Buyer&L_NAME9=Customer%20Buyer&L_NAME10=test%20buyer&L_NAME11=test%20buyer&L_NAME12=test%20buyer&L_NAME13=test%20buyer&L_NAME14=test%20buyer&L_NAME15=test%20buyer&L_NAME16=test%20buyer&L_NAME17=test%20buyer&L_NAME18=test%20buyer&L_NAME19=test%20buyer&L_NAME20=test%20buyer&L_NAME21=test%20buyer&L_NAME22=test%20buyer&L_NAME23=test%20buyer&L_NAME24=test%20buyer&L_NAME25=test%20buyer&L_NAME26=test%20buyer&L_NAME27=test%20buyer&L_NAME28=test%20buyer&L_NAME29=test%20buyer&L_NAME30=test%20buyer&L_NAME31=test%20buyer&L_NAME32=test%20buyer&L_NAME33=test%20buyer&L_TRANSACTIONID0=3FY20681KU848924J&L_TRANSACTIONID1=787900716V504552T&L_TRANSACTIONID2=99H6242660038953T&L_TRANSACTIONID3=6D026891597748026&L_TRANSACTIONID4=206452923U546154W&L_TRANSACTIONID5=95B886925P526494M&L_TRANSACTIONID6=36509974GM1491032&L_TRANSACTIONID7=4WM61597LP535311D&L_TRANSACTIONID8=446569774X245111W&L_TRANSACTIONID9=1LN0584492626715B&L_TRANSACTIONID10=1S762230NN608862G&L_TRANSACTIONID11=69333230427919150&L_TRANSACTIONID12=4JN35915W37902433&L_TRANSACTIONID13=6SY4058380482594X&L_TRANSACTIONID14=8D376460MR876740H&L_TRANSACTIONID15=42043116RY4025246&L_TRANSACTIONID16=9KB74981W8256320B&L_TRANSACTIONID17=3C367476PA4845904&L_TRANSACTIONID18=47M323815V599663S&L_TRANSACTIONID19=2TN72828VK3748140&L_TRANSACTIONID20=1WS39277P5956532H&L_TRANSACTIONID21=3S744950MV087845U&L_TRANSACTIONID22=4R384182BF967730H&L_TRANSACTIONID23=4KT914520Y243884P&L_TRANSACTIONID24=7BX25368N4576315B&L_TRANSACTIONID25=93J13992PY1168425&L_TRANSACTIONID26=5LF32112F54697325&L_TRANSACTIONID27=9NX78279NS179145V&L_TRANSACTIONID28=11842698RK478191G&L_TRANSACTIONID29=9PT46471AH6480326&L_TRANSACTIONID30=0WS99644T4912682F&L_TRANSACTIONID31=0GT40247KL518083N&L_TRANSACTIONID32=03P70088KV1230723&L_TRANSACTIONID33=6G537087YB4817020&L_STATUS0=Completed&L_STATUS1=Completed&L_STATUS2=Completed&L_STATUS3=Completed&L_STATUS4=Completed&L_STATUS5=Completed&L_STATUS6=Completed&L_STATUS7=Completed&L_STATUS8=Expired&L_STATUS9=Expired&L_STATUS10=Completed&L_STATUS11=Completed&L_STATUS12=Completed&L_STATUS13=Completed&L_STATUS14=Completed&L_STATUS15=Completed&L_STATUS16=Completed&L_STATUS17=Completed&L_STATUS18=Completed&L_STATUS19=Completed&L_STATUS20=Completed&L_STATUS21=Completed&L_STATUS22=Expired&L_STATUS23=Completed&L_STATUS24=Completed&L_STATUS25=Completed&L_STATUS26=Completed&L_STATUS27=Completed&L_STATUS28=Completed&L_STATUS29=Completed&L_STATUS30=Completed&L_STATUS31=Expired&L_STATUS32=Expired&L_STATUS33=Expired&L_AMT0=2009%2e16&L_AMT1=2009%2e16&L_AMT2=6422%2e79&L_AMT3=6422%2e79&L_AMT4=1182%2e33&L_AMT5=1182%2e33&L_AMT6=1227%2e03&L_AMT7=1227%2e03&L_AMT8=1859%2e03&L_AMT9=7228%2e89&L_AMT10=1984%2e37&L_AMT11=1984%2e37&L_AMT12=1984%2e37&L_AMT13=1984%2e37&L_AMT14=1984%2e37&L_AMT15=1984%2e37&L_AMT16=475%2e37&L_AMT17=475%2e37&L_AMT18=1171%2e77&L_AMT19=1171%2e77&L_AMT20=2246%2e84&L_AMT21=2246%2e84&L_AMT22=2620%2e64&L_AMT23=1067%2e14&L_AMT24=1067%2e14&L_AMT25=991%2e38&L_AMT26=991%2e38&L_AMT27=2525%2e84&L_AMT28=2525%2e84&L_AMT29=1374%2e25&L_AMT30=1374%2e25&L_AMT31=2515%2e19&L_AMT32=447%2e85&L_AMT33=409%2e63&L_CURRENCYCODE0=BRL&L_CURRENCYCODE1=BRL&L_CURRENCYCODE2=BRL&L_CURRENCYCODE3=BRL&L_CURRENCYCODE4=BRL&L_CURRENCYCODE5=BRL&L_CURRENCYCODE6=BRL&L_CURRENCYCODE7=BRL&L_CURRENCYCODE8=BRL&L_CURRENCYCODE9=BRL&L_CURRENCYCODE10=BRL&L_CURRENCYCODE11=BRL&L_CURRENCYCODE12=BRL&L_CURRENCYCODE13=BRL&L_CURRENCYCODE14=BRL&L_CURRENCYCODE15=BRL&L_CURRENCYCODE16=BRL&L_CURRENCYCODE17=BRL&L_CURRENCYCODE18=BRL&L_CURRENCYCODE19=BRL&L_CURRENCYCODE20=BRL&L_CURRENCYCODE21=BRL&L_CURRENCYCODE22=BRL&L_CURRENCYCODE23=BRL&L_CURRENCYCODE24=BRL&L_CURRENCYCODE25=BRL&L_CURRENCYCODE26=BRL&L_CURRENCYCODE27=BRL&L_CURRENCYCODE28=BRL&L_CURRENCYCODE29=BRL&L_CURRENCYCODE30=BRL&L_CURRENCYCODE31=BRL&L_CURRENCYCODE32=BRL&L_CURRENCYCODE33=BRL&L_FEEAMT0=%2d68%2e71&L_FEEAMT1=0%2e00&L_FEEAMT2=%2d218%2e77&L_FEEAMT3=0%2e00&L_FEEAMT4=%2d40%2e60&L_FEEAMT5=0%2e00&L_FEEAMT6=%2d42%2e12&L_FEEAMT7=0%2e00&L_FEEAMT8=0%2e00&L_FEEAMT9=0%2e00&L_FEEAMT10=%2d67%2e87&L_FEEAMT11=0%2e00&L_FEEAMT12=%2d67%2e87&L_FEEAMT13=0%2e00&L_FEEAMT14=%2d67%2e87&L_FEEAMT15=0%2e00&L_FEEAMT16=%2d16%2e56&L_FEEAMT17=0%2e00&L_FEEAMT18=%2d40%2e24&L_FEEAMT19=0%2e00&L_FEEAMT20=%2d76%2e79&L_FEEAMT21=0%2e00&L_FEEAMT22=0%2e00&L_FEEAMT23=%2d36%2e68&L_FEEAMT24=0%2e00&L_FEEAMT25=%2d34%2e11&L_FEEAMT26=0%2e00&L_FEEAMT27=%2d86%2e28&L_FEEAMT28=0%2e00&L_FEEAMT29=%2d47%2e12&L_FEEAMT30=0%2e00&L_FEEAMT31=0%2e00&L_FEEAMT32=0%2e00&L_FEEAMT33=0%2e00&L_NETAMT0=1940%2e45&L_NETAMT1=2009%2e16&L_NETAMT2=6204%2e02&L_NETAMT3=6422%2e79&L_NETAMT4=1141%2e73&L_NETAMT5=1182%2e33&L_NETAMT6=1184%2e91&L_NETAMT7=1227%2e03&L_NETAMT8=1859%2e03&L_NETAMT9=7228%2e89&L_NETAMT10=1916%2e50&L_NETAMT11=1984%2e37&L_NETAMT12=1916%2e50&L_NETAMT13=1984%2e37&L_NETAMT14=1916%2e50&L_NETAMT15=1984%2e37&L_NETAMT16=458%2e81&L_NETAMT17=475%2e37&L_NETAMT18=1131%2e53&L_NETAMT19=1171%2e77&L_NETAMT20=2170%2e05&L_NETAMT21=2246%2e84&L_NETAMT22=2620%2e64&L_NETAMT23=1030%2e46&L_NETAMT24=1067%2e14&L_NETAMT25=957%2e27&L_NETAMT26=991%2e38&L_NETAMT27=2439%2e56&L_NETAMT28=2525%2e84&L_NETAMT29=1327%2e13&L_NETAMT30=1374%2e25&L_NETAMT31=2515%2e19&L_NETAMT32=447%2e85&L_NETAMT33=409%2e63&TIMESTAMP=2016%2d02%2d11T18%3a30%3a59Z&CORRELATIONID=460d175a9cc3c&ACK=Success&VERSION=119%2e0&BUILD=18308778 paypal/tests/Mock/RestPurchaseFailure.txt 0000666 00000001361 15165413756 0014570 0 ustar 00 HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=38554 Paypal-Debug-Id: b31c6360606e6 SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=235&TopLevelTxnStartTime=146fc97eb2a&Host=slcsbjm2.slc.paypal.com&pid=14594 CORRELATION-ID: b31c6360606e6 Content-Language: * Date: Thu, 03 Jul 2014 14:19:12 GMT Connection: close Content-Type: application/json Content-Length: 290 Connection: close {"name":"VALIDATION_ERROR","details":[{"field":"payer.funding_instruments[0].credit_card.number","issue":"Value is invalid"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"b31c6360606e6"} paypal/tests/Mock/ExpressPurchaseFailure.txt 0000666 00000000666 15165413756 0015313 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 19:21:05 GMT Server: Apache Content-Length: 292 Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2013%2d02%2d15T19%3a21%3a06Z&CORRELATIONID=2b58be2b8e60e&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10525&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20The%20amount%20to%20be%20charged%20is%20zero%2e&L_SEVERITYCODE0=Error paypal/tests/Mock/ExpressFetchCheckoutSuccess.txt 0000666 00000001406 15165413756 0016272 0 ustar 00 HTTP/1.1 200 OK Date: 05 Apr 2007 23:44:11 GMT Server: Apache Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2007%2d04%2d05T23%3a44%3a11Z&CORRELATIONID=6b174e9bac3b3&ACK=Success&VERSION=XX%2e000000&BUILD=1%2e0006&TOKEN=EC%2d1NK66318YB717835M&EMAIL=YourSandboxBuyerAccountEmail&PAYERID=7AKUSARZ7SAT8&PAYERSTATUS=verified&FIRSTNAME=Bernard&LASTNAME=Black&COUNTRYCODE=UK&BUSINESS=Black%20Books&PAYMENTREQUEST_0_SHIPTONAME=Bernard%20Black&PAYMENTREQUEST_0_SHIPTOSTREET=13%20Little%20Bevan%20Street&PAYMENTREQUEST_0_SHIPTOCITY=London&PAYMENTREQUEST_0_SHIPTOSTATE=&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=UK&PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United%20Kingdom&PAYMENTREQUEST_0_SHIPTOZIP=WC1&PAYMENTREQUEST_0_ADDRESSID=1234&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed paypal/tests/Mock/ExpressFetchCheckoutFailure.txt 0000666 00000000764 15165413756 0016257 0 ustar 00 HTTP/1.1 200 OK Date: 05 Apr 2007 23:44:11 GMT Server: Apache Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2007%2d04%2d05T23%3a44%3a11Z&CORRELATIONID=6b174e9bac3b3&ACK=Failure&VERSION=85.0&BUILD=11235635&L_ERRORCODE0=10414&L_SHORTMESSAGE0=Transaction%20refused%20because%20of%20an%20invalid%20argument.%20See%20additional%20error%20messages%20for%20details.&L_LONGMESSAGE0=The%20amount%20exceeds%20the%20maximum%20amount%20for%20a%20single%20transaction.&L_SEVERITYCODE0=Error paypal/tests/Mock/RestPurchaseSuccess.txt 0000666 00000003203 15165413756 0014606 0 ustar 00 HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=1534 Paypal-Debug-Id: 98cbd3ab19dfe SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=129&TopLevelTxnStartTime=146fc9074ec&Host=slcsbjm3.slc.paypal.com&pid=15797 CORRELATION-ID: 98cbd3ab19dfe Content-Language: * Date: Thu, 03 Jul 2014 14:11:10 GMT Content-Type: application/json Content-Length: 1243 {"id":"PAY-6RT04683U7444573DKO2WI6A","create_time":"2014-07-03T14:11:04Z","update_time":"2014-07-03T14:11:10Z","state":"approved","intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"mastercard","number":"xxxxxxxxxxxx5559","expire_month":"12","expire_year":"2018","first_name":"Betsy","last_name":"Buyer"}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment transaction description.","related_resources":[{"sale":{"id":"44E89981F8714392Y","create_time":"2014-07-03T14:11:04Z","update_time":"2014-07-03T14:11:10Z","state":"completed","amount":{"total":"7.47","currency":"USD"},"parent_payment":"PAY-6RT04683U7444573DKO2WI6A","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/44E89981F8714392Y","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/44E89981F8714392Y/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RT04683U7444573DKO2WI6A","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RT04683U7444573DKO2WI6A","rel":"self","method":"GET"}]} paypal/tests/Mock/ExpressPurchaseSuccess.txt 0000666 00000000432 15165413756 0015323 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 19:19:21 GMT Server: Apache Content-Length: 136 Connection: close Content-Type: text/plain; charset=utf-8 TOKEN=EC%2d42721413K79637829&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305 paypal/tests/Mock/RestExecuteSubscriptionSuccess.txt 0000666 00000001117 15165413756 0017045 0 ustar 00 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=76018 Paypal-Debug-Id: 965491cb1a1e5 SERVER_INFO: paymentsplatformserv:v1.payments.sale&CalThreadId=129&TopLevelTxnStartTime=14701c36ef9&Host=slcsbjm3.slc.paypal.com&pid=15797 CORRELATION-ID: 965491cb1a1e5 Content-Language: * Date: Fri, 04 Jul 2014 14:24:52 GMT Content-Type: application/json { "id": "I-0LN988D3JACS", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS", "rel": "self", "method": "GET" } ] } paypal/tests/Mock/ExpressCompletePurchaseSuccess.txt 0000666 00000001767 15165413756 0017030 0 ustar 00 HTTP/1.1 200 OK Date: Wed, 20 Feb 2013 13:54:27 GMT Server: Apache Content-Length: 869 Connection: close Content-Type: text/plain; charset=utf-8 TOKEN=EC%2d96V667110D1727015&SUCCESSPAGEREDIRECTREQUESTED=true&TIMESTAMP=2013%2d02%2d20T13%3a54%3a28Z&CORRELATIONID=f78b888897f8a&ACK=Success&VERSION=85%2e0&BUILD=5060305&INSURANCEOPTIONSELECTED=false&SHIPPINGOPTIONISDEFAULT=false&PAYMENTINFO_0_TRANSACTIONID=8RM57414KW761861W&PAYMENTINFO_0_RECEIPTID=0368%2d2088%2d8643%2d7560&PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&PAYMENTINFO_0_PAYMENTTYPE=instant&PAYMENTINFO_0_ORDERTIME=2013%2d02%2d20T13%3a54%3a03Z&PAYMENTINFO_0_AMT=10%2e00&PAYMENTINFO_0_FEEAMT=0%2e59&PAYMENTINFO_0_TAXAMT=0%2e00&PAYMENTINFO_0_CURRENCYCODE=USD&PAYMENTINFO_0_PAYMENTSTATUS=Completed&PAYMENTINFO_0_PENDINGREASON=None&PAYMENTINFO_0_REASONCODE=None&PAYMENTINFO_0_PROTECTIONELIGIBILITY=Ineligible&PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=None&PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=VZTRGMSKHHAEW&PAYMENTINFO_0_ERRORCODE=0&PAYMENTINFO_0_ACK=Success paypal/tests/Mock/RestTokenFailure.txt 0000666 00000001001 15165413756 0014065 0 ustar 00 HTTP/1.1 401 Unauthorized Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=3683 Paypal-Debug-Id: f115dd7f08d14 SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=126527&TopLevelTxnStartTime=146fc214a29&Host=slcsbidensectoken502.slc.paypal.com&pid=29059 CORRELATION-ID: f115dd7f08d14 Date: Thu, 03 Jul 2014 12:09:38 GMT Content-Type: application/json Content-Length: 93 {"error":"invalid_client","error_description":"Client secret does not match for this client"} paypal/tests/Mock/ExpressVoidFailure.txt 0000666 00000000432 15165413756 0014431 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 19:19:21 GMT Server: Apache Content-Length: 136 Connection: close Content-Type: text/plain; charset=utf-8 AUTHORIZATIONID=ASDFASDFASDF&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Failure&VERSION=85%2e0&BUILD=5060305 paypal/tests/Mock/RestAuthorizationSuccess.txt 0000666 00000003502 15165413756 0015676 0 ustar 00 HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=3224 Paypal-Debug-Id: 2a1b9202663bc SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=206&TopLevelTxnStartTime=14701b4cb42&Host=slcsbjm1.slc.paypal.com&pid=20119 CORRELATION-ID: 2a1b9202663bc Content-Language: * Date: Fri, 04 Jul 2014 14:09:00 GMT Content-Type: application/json Content-Length: 1435 {"id":"PAY-66G66446716792522KO3LK4Y","create_time":"2014-07-04T14:08:51Z","update_time":"2014-07-04T14:09:01Z","state":"approved","intent":"authorize","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"mastercard","number":"xxxxxxxxxxxx5559","expire_month":"12","expire_year":"2018","first_name":"Betsy","last_name":"Buyer"}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment transaction description.","related_resources":[{"authorization":{"id":"58N7596879166930B","create_time":"2014-07-04T14:08:51Z","update_time":"2014-07-04T14:09:01Z","state":"authorized","amount":{"total":"7.47","currency":"USD"},"parent_payment":"PAY-66G66446716792522KO3LK4Y","valid_until":"2014-08-02T14:08:51Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B/capture","rel":"capture","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B/void","rel":"void","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-66G66446716792522KO3LK4Y","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-66G66446716792522KO3LK4Y","rel":"self","method":"GET"}]} paypal/tests/Mock/ExpressCompletePurchaseFailureRedirect.txt 0000666 00000001034 15165413756 0020454 0 ustar 00 HTTP/1.1 200 OK Date: Wed, 20 Feb 2013 13:55:50 GMT Server: Apache Content-Length: 214 Connection: close Content-Type: text/plain; charset=utf-8 TOKEN=ASDFASDFASDF&SUCCESSPAGEREDIRECTREQUESTED=false&TIMESTAMP=2016%2d09%2d12T14%3a06%3a12Z&CORRELATIONID=31e509fc8f6a8&ACK=Failure&VERSION=119%2e0&BUILD=25037053&L_ERRORCODE0=10486&L_SHORTMESSAGE0=This%20transaction%20couldn%27t%20be%20completed%2e&L_LONGMESSAGE0=This%20transaction%20couldn%27t%20be%20completed%2e%20Please%20redirect%20your%20customer%20to%20PayPal%2e&L_SEVERITYCODE0=Error paypal/tests/Mock/ExpressOrderSuccess.txt 0000666 00000000432 15165413756 0014624 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 19:19:21 GMT Server: Apache Content-Length: 136 Connection: close Content-Type: text/plain; charset=utf-8 TOKEN=EC%2d42721413K79637829&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305 paypal/tests/Mock/RestCompletePurchaseSuccess.txt 0000666 00000004006 15165413756 0016301 0 ustar 00 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=216 Paypal-Debug-Id: 539b1c0678b08 SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=4342&TopLevelTxnStartTime=14b8c84b1f3&Host=slcsbpaymentsplatformserv3002.slc.paypal.com&pid=8929 Content-Language: * Date: Sun, 15 Feb 2015 09:14:43 GMT Content-Type: application/json Content-Length: 1632 {"id":"PAY-4BF374015W374910XKTQGGBZ","create_time":"2015-02-15T09:12:36Z","update_time":"2015-02-15T09:14:43Z","state":"approved","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"email":"test.buyer@example.com","first_name":"Betsy","last_name":"Buyer","payer_id":"Payer12345","shipping_address":{"line1":"test","city":"","state":"","postal_code":"123456","country_code":"US","recipient_name":"Buyer Betsy"}}},"transactions":[{"amount":{"total":"100.00","currency":"USD","details":{"subtotal":"100.00","fee":"3.90"}},"description":"The product description","item_list":{"items":[{"name":"Item 1","price":"100.00","currency":"USD","quantity":"1","description":"Standard Item"}],"shipping_address":{"recipient_name":"Buyer Betsy","line1":"test","city":"","state":"","postal_code":"123456","country_code":"US"}},"related_resources":[{"sale":{"id":"9EA05739TH369572R","create_time":"2015-02-15T09:12:36Z","update_time":"2015-02-15T09:14:43Z","amount":{"total":"100.00","currency":"USD"},"payment_mode":"INSTANT_TRANSFER","state":"completed","protection_eligibility":"INELIGIBLE","parent_payment":"PAY-4BF374015W374910XKTQGGBZ","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/9EA05739TH369572R","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/9EA05739TH369572R/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4BF374015W374910XKTQGGBZ","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4BF374015W374910XKTQGGBZ","rel":"self","method":"GET"}]} paypal/tests/Mock/RestPurchaseWithoutCardSuccess.txt 0000666 00000002450 15165413756 0016767 0 ustar 00 HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=383 Paypal-Debug-Id: b4dc1c6623f68 SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=166&TopLevelTxnStartTime=14b8ca1806f&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=12653 Content-Language: * Date: Sun, 15 Feb 2015 09:46:09 GMT Content-Type: application/json Content-Length: 894 {"id":"PAY-3TJ47806DA028052TKTQGVYI","create_time":"2015-02-15T09:46:09Z","update_time":"2015-02-15T09:46:09Z","state":"created","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"shipping_address":{}}},"transactions":[{"amount":{"total":"199.00","currency":"USD","details":{"subtotal":"199.00"}},"description":"Product 1","item_list":{"items":[{"name":"Item 1","price":"199.00","currency":"USD","quantity":"1","description":"Item Description"}]},"related_resources":[]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3TJ47806DA028052TKTQGVYI","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5KV58254GL528393N","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3TJ47806DA028052TKTQGVYI/execute","rel":"execute","method":"POST"}]} paypal/tests/Mock/RestCaptureSuccess.txt 0000666 00000002174 15165413756 0014445 0 ustar 00 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=127 Paypal-Debug-Id: 030d6a098c7c5 SERVER_INFO: paymentsplatformserv:v1.payments.authorization&CalThreadId=15946&TopLevelTxnStartTime=14701ba0b41&Host=slcsbjm3.slc.paypal.com&pid=15797 CORRELATION-ID: 030d6a098c7c5 Content-Language: * Date: Fri, 04 Jul 2014 14:14:42 GMT Content-Type: application/json Content-Length: 724 {"id":"9EP22596VU4085001","create_time":"2014-07-04T14:14:35Z","update_time":"2014-07-04T14:14:42Z","amount":{"total":"7.47","currency":"USD"},"is_final_capture":false,"state":"completed","parent_payment":"PAY-66G66446716792522KO3LK4Y","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/capture/9EP22596VU4085001","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/capture/9EP22596VU4085001/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B","rel":"authorization","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-66G66446716792522KO3LK4Y","rel":"parent_payment","method":"GET"}]} paypal/tests/Mock/ProPurchaseSuccess.txt 0000666 00000000520 15165413756 0014430 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 18:38:31 GMT Server: Apache Content-Length: 190 Connection: close Content-Type: text/plain; charset=utf-8 TIMESTAMP=2013%2d02%2d15T18%3a38%3a36Z&CORRELATIONID=541737dc565cb&ACK=Success&VERSION=85%2e0&BUILD=5060305&AMT=10%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=96U93778BD657313D paypal/tests/Message/RestSearchTransactionRequestTest.php 0000666 00000002023 15165413756 0017771 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestSearchTransactionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestSearchTransactionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestSearchTransactionRequest($client, $request); $this->request->initialize(array( 'agreementId' => 'ABC-123', 'startDate' => '2015-09-01', 'endDate' => '2015-09-30', )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('2015-09-01', $data['start_date']); $this->assertEquals('2015-09-30', $data['end_date']); } public function testEndpoint() { $this->assertStringEndsWith('/payments/billing-agreements/ABC-123/transactions', $this->request->getEndpoint()); } } paypal/tests/Message/ExpressCompletePurchaseRequestTest.php 0000666 00000007453 15165413756 0020351 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\PayPal\Message\ExpressCompletePurchaseRequest; use Omnipay\Tests\TestCase; class ExpressCompletePurchaseRequestTest extends TestCase { /** * @var \Omnipay\PayPal\Message\ExpressCompletePurchaseRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $request->query->set('PayerID', 'Payer-1234'); $request->query->set('token', 'TOKEN1234'); $this->request = new ExpressCompletePurchaseRequest($client, $request); } public function testGetData() { $this->request->setAmount('1.23'); $this->request->setCurrency('USD'); $this->request->setTransactionId('ABC-123'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $this->request->setDescription('DESC'); $this->request->setNotifyUrl('https://www.example.com/notify'); $this->request->setMaxAmount('0.00'); $this->request->setTaxAmount('0.00'); $this->request->setShippingAmount('0.00'); $this->request->setHandlingAmount('0.00'); $this->request->setShippingDiscount('0.00'); $this->request->setInsuranceAmount('0.00'); $expected = array(); $expected['METHOD'] = 'DoExpressCheckoutPayment'; $expected['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale'; $expected['PAYMENTREQUEST_0_AMT'] = '1.23'; $expected['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'; $expected['PAYMENTREQUEST_0_INVNUM'] = 'ABC-123'; $expected['PAYMENTREQUEST_0_DESC'] = 'DESC'; $expected['PAYMENTREQUEST_0_NOTIFYURL'] = 'https://www.example.com/notify'; $expected['USER'] = 'testuser'; $expected['PWD'] = 'testpass'; $expected['SIGNATURE'] = 'SIG'; $expected['SUBJECT'] = 'SUB'; $expected['VERSION'] = ExpressCompletePurchaseRequest::API_VERSION; $expected['TOKEN'] = 'TOKEN1234'; $expected['PAYERID'] = 'Payer-1234'; $expected['MAXAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_TAXAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_HANDLINGAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00'; $this->assertEquals($expected, $this->request->getData()); } public function testGetDataWithItems() { $this->request->setAmount('50.00'); $this->request->setCurrency('USD'); $this->request->setTransactionId('ABC-123'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $this->request->setDescription('DESC'); $this->request->setItems(array( array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10), array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40), )); $data = $this->request->getData(); $this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']); $this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']); $this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']); $this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']); $this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']); $this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']); $this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']); $this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']); } } paypal/tests/Message/ExpressFetchCheckoutRequestTest.php 0000666 00000004143 15165413756 0017616 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\PayPal\Message\ExpressFetchCheckoutRequest; use Omnipay\Tests\TestCase; class ExpressFetchCheckoutRequestTest extends TestCase { /** * @var \Omnipay\PayPal\Message\ExpressFetchCheckoutRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $request->query->set('token', 'TOKEN1234'); $this->request = new ExpressFetchCheckoutRequest($client, $request); } public function testGetData() { $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $expected = array(); $expected['METHOD'] = 'GetExpressCheckoutDetails'; $expected['USER'] = 'testuser'; $expected['PWD'] = 'testpass'; $expected['SIGNATURE'] = 'SIG'; $expected['SUBJECT'] = null; $expected['VERSION'] = ExpressCompletePurchaseRequest::API_VERSION; $expected['TOKEN'] = 'TOKEN1234'; $this->assertEquals($expected, $this->request->getData()); } public function testGetDataTokenOverride() { $this->request->setToken('TOKEN2000'); $data = $this->request->getData(); $this->assertSame('TOKEN2000', $data['TOKEN']); } public function testSendSuccess() { $this->setMockHttpResponse('ExpressFetchCheckoutSuccess.txt'); $response = $this->request->send(); $this->assertFalse($response->isPending()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); } public function testSendFailure() { $this->setMockHttpResponse('ExpressFetchCheckoutFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('The amount exceeds the maximum amount for a single transaction.', $response->getMessage()); } } paypal/tests/Message/ResponseTest.php 0000666 00000002560 15165413756 0013753 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class ResponseTest extends TestCase { public function testConstruct() { // response should decode URL format data $response = new Response($this->getMockRequest(), 'example=value&foo=bar'); $this->assertEquals(array('example' => 'value', 'foo' => 'bar'), $response->getData()); } public function testProPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('ProPurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isPending()); $this->assertTrue($response->isSuccessful()); $this->assertSame('96U93778BD657313D', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testProPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('ProPurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This transaction cannot be processed. Please enter a valid credit card expiration year.', $response->getMessage()); } } paypal/tests/Message/RestPurchaseRequestTest.php 0000666 00000007411 15165413756 0016136 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class RestPurchaseRequestTest extends TestCase { /** @var RestPurchaseRequest */ private $request; public function testGetData() { $card = new CreditCard($this->getValidCard()); $card->setStartMonth(1); $card->setStartYear(2000); $this->request = new RestPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'USD', 'card' => $card )); $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $this->request->setClientIp('127.0.0.1'); $data = $this->request->getData(); $this->assertSame('sale', $data['intent']); $this->assertSame('credit_card', $data['payer']['payment_method']); $this->assertSame('10.00', $data['transactions'][0]['amount']['total']); $this->assertSame('USD', $data['transactions'][0]['amount']['currency']); $this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']); $this->assertSame($card->getNumber(), $data['payer']['funding_instruments'][0]['credit_card']['number']); $this->assertSame($card->getBrand(), $data['payer']['funding_instruments'][0]['credit_card']['type']); $this->assertSame($card->getExpiryMonth(), $data['payer']['funding_instruments'][0]['credit_card']['expire_month']); $this->assertSame($card->getExpiryYear(), $data['payer']['funding_instruments'][0]['credit_card']['expire_year']); $this->assertSame($card->getCvv(), $data['payer']['funding_instruments'][0]['credit_card']['cvv2']); $this->assertSame($card->getFirstName(), $data['payer']['funding_instruments'][0]['credit_card']['first_name']); $this->assertSame($card->getLastName(), $data['payer']['funding_instruments'][0]['credit_card']['last_name']); $this->assertSame($card->getAddress1(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line1']); $this->assertSame($card->getAddress2(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line2']); $this->assertSame($card->getCity(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['city']); $this->assertSame($card->getState(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['state']); $this->assertSame($card->getPostcode(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['postal_code']); $this->assertSame($card->getCountry(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['country_code']); } public function testGetDataWithCardRef() { $this->request = new RestPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'USD', 'cardReference' => 'CARD-123', )); $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $this->request->setClientIp('127.0.0.1'); $data = $this->request->getData(); $this->assertSame('sale', $data['intent']); $this->assertSame('credit_card', $data['payer']['payment_method']); $this->assertSame('10.00', $data['transactions'][0]['amount']['total']); $this->assertSame('USD', $data['transactions'][0]['amount']['currency']); $this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']); $this->assertSame('CARD-123', $data['payer']['funding_instruments'][0]['credit_card_token']['credit_card_id']); } } paypal/tests/Message/RestCompletePurchaseRequestTest.php 0000666 00000001353 15165413756 0017626 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class RestCompletePurchaseRequestTest extends TestCase { /** * @var RestCompletePurchaseRequest */ private $request; public function setUp() { parent::setUp(); $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestCompletePurchaseRequest($client, $request); $this->request->initialize(array()); } public function testGetData() { $this->request->setTransactionReference('abc123'); $this->request->setPayerId('Payer12345'); $data = $this->request->getData(); $this->assertSame('Payer12345', $data['payer_id']); } } paypal/tests/Message/ProAuthorizeRequestTest.php 0000666 00000004524 15165413756 0016163 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class ProAuthorizeRequestTest extends TestCase { /** * @var ProAuthorizeRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new ProAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'currency' => 'USD', 'card' => $this->getValidCard(), ) ); } public function testGetData() { $card = new CreditCard($this->getValidCard()); $card->setStartMonth(1); $card->setStartYear(2000); $this->request->setCard($card); $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $this->request->setClientIp('127.0.0.1'); $data = $this->request->getData(); $this->assertSame('DoDirectPayment', $data['METHOD']); $this->assertSame('Authorization', $data['PAYMENTACTION']); $this->assertSame('10.00', $data['AMT']); $this->assertSame('USD', $data['CURRENCYCODE']); $this->assertSame('abc123', $data['INVNUM']); $this->assertSame('Sheep', $data['DESC']); $this->assertSame('127.0.0.1', $data['IPADDRESS']); $this->assertSame($card->getNumber(), $data['ACCT']); $this->assertSame($card->getBrand(), $data['CREDITCARDTYPE']); $this->assertSame($card->getExpiryDate('mY'), $data['EXPDATE']); $this->assertSame('012000', $data['STARTDATE']); $this->assertSame($card->getCvv(), $data['CVV2']); $this->assertSame($card->getIssueNumber(), $data['ISSUENUMBER']); $this->assertSame($card->getFirstName(), $data['FIRSTNAME']); $this->assertSame($card->getLastName(), $data['LASTNAME']); $this->assertSame($card->getEmail(), $data['EMAIL']); $this->assertSame($card->getAddress1(), $data['STREET']); $this->assertSame($card->getAddress2(), $data['STREET2']); $this->assertSame($card->getCity(), $data['CITY']); $this->assertSame($card->getState(), $data['STATE']); $this->assertSame($card->getPostcode(), $data['ZIP']); $this->assertSame($card->getCountry(), $data['COUNTRYCODE']); } } paypal/tests/Message/RestCreatePlanRequestTest.php 0000666 00000003277 15165413756 0016410 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestCreatePlanRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestCreatePlanRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestCreatePlanRequest($client, $request); $this->request->initialize(array( 'name' => 'Super Duper Billing Plan', 'description' => 'Test Billing Plan', 'type' => RestGateway::BILLING_PLAN_TYPE_FIXED, 'paymentDefinitions' => array( array( 'name' => 'Monthly Payments', 'type' => RestGateway::PAYMENT_REGULAR, 'frequency' => RestGateway::BILLING_PLAN_FREQUENCY_MONTH, 'frequency_interval' => 1, 'cycles' => 12, 'amount' => array( 'value' => 10.00, 'currency' => 'USD', ) ) ), 'merchantPreferences' => array( 'name' => 'asdf', ), )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('Super Duper Billing Plan', $data['name']); $this->assertEquals(RestGateway::BILLING_PLAN_TYPE_FIXED, $data['type']); $this->assertEquals('Monthly Payments', $data['payment_definitions'][0]['name']); } } paypal/tests/Message/CaptureRequestTest.php 0000666 00000002661 15165413756 0015133 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\PayPal\Message\CaptureRequest; use Omnipay\Tests\TestCase; class CaptureRequestTest extends TestCase { /** * @var \Omnipay\PayPal\Message\CaptureRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new CaptureRequest($client, $request); } public function testGetData() { $this->request->setTransactionReference('ABC-123'); $this->request->setAmount('1.23'); $this->request->setCurrency('USD'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $this->request->setButtonSource('BNCode_PP'); $expected = array(); $expected['METHOD'] = 'DoCapture'; $expected['AUTHORIZATIONID'] = 'ABC-123'; $expected['AMT'] = '1.23'; $expected['CURRENCYCODE'] = 'USD'; $expected['COMPLETETYPE'] = 'Complete'; $expected['USER'] = 'testuser'; $expected['PWD'] = 'testpass'; $expected['SIGNATURE'] = 'SIG'; $expected['SUBJECT'] = 'SUB'; $expected['BUTTONSOURCE'] = 'BNCode_PP'; $expected['VERSION'] = CaptureRequest::API_VERSION; $this->assertEquals($expected, $this->request->getData()); } } paypal/tests/Message/RestResponseTest.php 0000666 00000007206 15165413756 0014613 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class RestResponseTest extends TestCase { public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('RestPurchaseSuccess.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertTrue($response->isSuccessful()); $this->assertSame('44E89981F8714392Y', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('RestPurchaseFailure.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertFalse($response->isSuccessful()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Invalid request - see details', $response->getMessage()); } public function testCompletePurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('RestCompletePurchaseSuccess.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertTrue($response->isSuccessful()); $this->assertSame('9EA05739TH369572R', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testCompletePurchaseFailure() { $httpResponse = $this->getMockHttpResponse('RestCompletePurchaseFailure.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertFalse($response->isSuccessful()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This request is invalid due to the current state of the payment', $response->getMessage()); } public function testTokenFailure() { $httpResponse = $this->getMockHttpResponse('RestTokenFailure.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertFalse($response->isSuccessful()); $this->assertSame('Client secret does not match for this client', $response->getMessage()); } public function testAuthorizeSuccess() { $httpResponse = $this->getMockHttpResponse('RestAuthorizationSuccess.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertTrue($response->isSuccessful()); $this->assertSame('58N7596879166930B', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testCreateCardSuccess() { $httpResponse = $this->getMockHttpResponse('RestCreateCardSuccess.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertTrue($response->isSuccessful()); $this->assertSame('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference()); $this->assertNull($response->getMessage()); } } paypal/tests/Message/RestFetchPurchaseRequestTest.php 0000666 00000001154 15165413756 0017106 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class RestFetchPurchaseRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestFetchPurchaseRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestFetchPurchaseRequest($client, $request); } public function testEndpoint() { $this->request->setTransactionReference('ABC-123'); $this->assertStringEndsWith('/payments/payment/ABC-123', $this->request->getEndpoint()); } } paypal/tests/Message/RestAuthorizeResponseTest.php 0000666 00000001672 15165413756 0016507 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class RestAuthorizeResponseTest extends TestCase { public function testRestPurchaseWithoutCardSuccess() { $httpResponse = $this->getMockHttpResponse('RestPurchaseWithoutCardSuccess.txt'); $data = json_decode($httpResponse->getBody()->getContents(), true); $response = new RestAuthorizeResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode()); $this->assertTrue($response->isSuccessful()); $this->assertSame('PAY-3TJ47806DA028052TKTQGVYI', $response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertNull($response->getRedirectData()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertSame('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5KV58254GL528393N', $response->getRedirectUrl()); } } paypal/tests/Message/ExpressInContextAuthorizeRequestTest.php 0000666 00000035036 15165413756 0020712 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\PayPal\Message\ExpressInContextAuthorizeRequest; use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption; use Omnipay\Tests\TestCase; class ExpressInContextAuthorizeRequestTest extends TestCase { /** * @var ExpressInContextAuthorizeRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new ExpressInContextAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', ) ); } public function testGetDataWithoutCard() { $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'noShipping' => 0, 'localeCode' => 'EN', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Inc.', 'customerServiceNumber' => '1-801-FLOWERS', )); $data = $this->request->getData(); $this->assertSame('10.00', $data['PAYMENTREQUEST_0_AMT']); $this->assertSame('AUD', $data['PAYMENTREQUEST_0_CURRENCYCODE']); $this->assertSame('111', $data['PAYMENTREQUEST_0_INVNUM']); $this->assertSame('Order Description', $data['PAYMENTREQUEST_0_DESC']); $this->assertSame('https://www.example.com/return', $data['RETURNURL']); $this->assertSame('https://www.example.com/cancel', $data['CANCELURL']); $this->assertSame('demo@example.com', $data['SUBJECT']); $this->assertSame('https://www.example.com/header.jpg', $data['HDRIMG']); $this->assertSame(0, $data['NOSHIPPING']); $this->assertSame(0, $data['ALLOWNOTE']); $this->assertSame('EN', $data['LOCALECODE']); $this->assertSame(0, $data['ADDROVERRIDE']); $this->assertSame('Dunder Mifflin Paper Company, Inc.', $data['BRANDNAME']); $this->assertSame('1-801-FLOWERS', $data['CUSTOMERSERVICENUMBER']); } public function testGetDataWithCard() { $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'noShipping' => 2, 'allowNote' => 1, 'addressOverride' => 1, 'brandName' => 'Dunder Mifflin Paper Company, Inc.', 'maxAmount' => 123.45, 'logoImageUrl' => 'https://www.example.com/logo.jpg', 'borderColor' => 'CCCCCC', 'localeCode' => 'EN', 'customerServiceNumber' => '1-801-FLOWERS', 'sellerPaypalAccountId' => 'billing@example.com', )); $card = new CreditCard(array( 'name' => 'John Doe', 'address1' => '123 NW Blvd', 'address2' => 'Lynx Lane', 'city' => 'Topeka', 'state' => 'KS', 'country' => 'USA', 'postcode' => '66605', 'phone' => '555-555-5555', 'email' => 'test@email.com', )); $this->request->setCard($card); $expected = array( 'METHOD' => 'SetExpressCheckout', 'VERSION' => ExpressInContextAuthorizeRequest::API_VERSION, 'USER' => null, 'PWD' => null, 'SIGNATURE' => null, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization', 'SOLUTIONTYPE' => null, 'LANDINGPAGE' => null, 'NOSHIPPING' => 2, 'ALLOWNOTE' => 1, 'ADDROVERRIDE' => 1, 'PAYMENTREQUEST_0_AMT' => '10.00', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'AUD', 'PAYMENTREQUEST_0_INVNUM' => '111', 'PAYMENTREQUEST_0_DESC' => 'Order Description', 'RETURNURL' => 'https://www.example.com/return', 'CANCELURL' => 'https://www.example.com/cancel', 'SUBJECT' => 'demo@example.com', 'HDRIMG' => 'https://www.example.com/header.jpg', 'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe', 'PAYMENTREQUEST_0_SHIPTOSTREET' => '123 NW Blvd', 'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Lynx Lane', 'PAYMENTREQUEST_0_SHIPTOCITY' => 'Topeka', 'PAYMENTREQUEST_0_SHIPTOSTATE' => 'KS', 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA', 'PAYMENTREQUEST_0_SHIPTOZIP' => '66605', 'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '555-555-5555', 'EMAIL' => 'test@email.com', 'BRANDNAME' => 'Dunder Mifflin Paper Company, Inc.', 'MAXAMT' => 123.45, 'PAYMENTREQUEST_0_TAXAMT' => null, 'PAYMENTREQUEST_0_SHIPPINGAMT' => null, 'PAYMENTREQUEST_0_HANDLINGAMT' => null, 'PAYMENTREQUEST_0_SHIPDISCAMT' => null, 'PAYMENTREQUEST_0_INSURANCEAMT' => null, 'LOGOIMG' => 'https://www.example.com/logo.jpg', 'CARTBORDERCOLOR' => 'CCCCCC', 'LOCALECODE' => 'EN', 'CUSTOMERSERVICENUMBER' => '1-801-FLOWERS', 'PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID' => 'billing@example.com', ); $this->assertEquals($expected, $this->request->getData()); } public function testGetDataWithItems() { $this->request->setItems(array( array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10, 'code' => '123456'), array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40), )); $data = $this->request->getData(); $this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']); $this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']); $this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']); $this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']); $this->assertSame('123456', $data['L_PAYMENTREQUEST_0_NUMBER0']); $this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']); $this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']); $this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']); $this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']); $this->assertSame('60.00', $data['PAYMENTREQUEST_0_ITEMAMT']); } public function testGetDataWithExtraOrderDetails() { $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'noShipping' => 0, 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Inc.', 'taxAmount' => '2.00', 'shippingAmount' => '5.00', 'handlingAmount' => '1.00', 'shippingDiscount' => '-1.00', 'insuranceAmount' => '3.00', )); $data = $this->request->getData(); $this->assertSame('2.00', $data['PAYMENTREQUEST_0_TAXAMT']); $this->assertSame('5.00', $data['PAYMENTREQUEST_0_SHIPPINGAMT']); $this->assertSame('1.00', $data['PAYMENTREQUEST_0_HANDLINGAMT']); $this->assertSame('-1.00', $data['PAYMENTREQUEST_0_SHIPDISCAMT']); $this->assertSame('3.00', $data['PAYMENTREQUEST_0_INSURANCEAMT']); } public function testHeaderImageUrl() { $this->assertSame($this->request, $this->request->setHeaderImageUrl('https://www.example.com/header.jpg')); $this->assertSame('https://www.example.com/header.jpg', $this->request->getHeaderImageUrl()); $data = $this->request->getData(); $this->assertEquals('https://www.example.com/header.jpg', $data['HDRIMG']); } public function testMaxAmount() { $this->request->setMaxAmount(321.54); $this->assertSame(321.54, $this->request->getMaxAmount()); $data = $this->request->getData(); $this->assertSame(321.54, $data['MAXAMT']); } public function testDataWithCallback() { $baseData = array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Incy.', ); $shippingOptions = array( new ShippingOption('First Class', 1.20, true, '1-2 days'), new ShippingOption('Second Class', 0.70, false, '3-5 days'), new ShippingOption('International', 3.50), ); // with a default callback timeout $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', 'shippingOptions' => $shippingOptions, ))); $data = $this->request->getData(); $this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']); $this->assertSame(ExpressInContextAuthorizeRequest::DEFAULT_CALLBACK_TIMEOUT, $data['CALLBACKTIMEOUT']); $this->assertSame('First Class', $data['L_SHIPPINGOPTIONNAME0']); $this->assertSame('1.20', $data['L_SHIPPINGOPTIONAMOUNT0']); $this->assertSame('1', $data['L_SHIPPINGOPTIONISDEFAULT0']); $this->assertSame('1-2 days', $data['L_SHIPPINGOPTIONLABEL0']); $this->assertSame('Second Class', $data['L_SHIPPINGOPTIONNAME1']); $this->assertSame('0.70', $data['L_SHIPPINGOPTIONAMOUNT1']); $this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT1']); $this->assertSame('3-5 days', $data['L_SHIPPINGOPTIONLABEL1']); $this->assertSame('International', $data['L_SHIPPINGOPTIONNAME2']); $this->assertSame('3.50', $data['L_SHIPPINGOPTIONAMOUNT2']); $this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT2']); // with a defined callback timeout $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', 'callbackTimeout' => 10, 'shippingOptions' => $shippingOptions, ))); $data = $this->request->getData(); $this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']); $this->assertSame(10, $data['CALLBACKTIMEOUT']); } public function testDataWithCallbackAndNoDefaultShippingOption() { $baseData = array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Incy.', ); $shippingOptions = array( new ShippingOption('First Class', 1.20, false, '1-2 days'), new ShippingOption('Second Class', 0.70, false, '3-5 days'), new ShippingOption('International', 3.50), ); // with a default callback timeout $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', 'shippingOptions' => $shippingOptions, ))); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('One of the supplied shipping options must be set as default'); $this->request->getData(); } public function testNoAmount() { $baseData = array(// nothing here - should cause a certain exception ); $this->request->initialize($baseData); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('The amount parameter is required'); $this->request->getData(); } public function testAmountButNoReturnUrl() { $baseData = array( 'amount' => 10.00, ); $this->request->initialize($baseData); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('The returnUrl parameter is required'); $this->request->getData(); } public function testBadCallbackConfiguration() { $baseData = array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Incy.', ); $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', ))); // from the docblock on this exception - // Thrown when a request is invalid or missing required fields. // callback has been set but no shipping options so expect one of these: $this->expectException(InvalidRequestException::class); $this->request->getData(); } } paypal/tests/Message/RestFetchTransactionRequestTest.php 0000666 00000001465 15165413756 0017626 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class RestFetchTransactionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestFetchTransactionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestFetchTransactionRequest($client, $request); } public function testGetData() { $this->request->setTransactionReference('ABC-123'); $data = $this->request->getData(); $this->assertEquals(array(), $data); } public function testEndpoint() { $this->request->setTransactionReference('ABC-123'); $this->assertStringEndsWith('/payments/sale/ABC-123', $this->request->getEndpoint()); } } paypal/tests/Message/RestAuthorizeRequestTest.php 0000666 00000013777 15165413756 0016352 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class RestAuthorizeRequestTest extends TestCase { /** * @var ProPurchaseRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new RestAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'currency' => 'USD', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', ) ); } public function testGetDataWithoutCard() { $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $data = $this->request->getData(); $this->assertSame('authorize', $data['intent']); $this->assertSame('paypal', $data['payer']['payment_method']); $this->assertSame('10.00', $data['transactions'][0]['amount']['total']); $this->assertSame('USD', $data['transactions'][0]['amount']['currency']); $this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']); // Funding instruments must not be set, otherwise paypal API will give error 500. $this->assertArrayNotHasKey('funding_instruments', $data['payer']); $this->assertSame('https://www.example.com/return', $data['redirect_urls']['return_url']); $this->assertSame('https://www.example.com/cancel', $data['redirect_urls']['cancel_url']); } public function testGetDataWithCard() { $card = new CreditCard($this->getValidCard()); $card->setStartMonth(1); $card->setStartYear(2000); $this->request->setCard($card); $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $this->request->setClientIp('127.0.0.1'); $data = $this->request->getData(); $this->assertSame('authorize', $data['intent']); $this->assertSame('credit_card', $data['payer']['payment_method']); $this->assertSame('10.00', $data['transactions'][0]['amount']['total']); $this->assertSame('USD', $data['transactions'][0]['amount']['currency']); $this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']); $this->assertSame($card->getNumber(), $data['payer']['funding_instruments'][0]['credit_card']['number']); $this->assertSame($card->getBrand(), $data['payer']['funding_instruments'][0]['credit_card']['type']); $this->assertSame($card->getExpiryMonth(), $data['payer']['funding_instruments'][0]['credit_card']['expire_month']); $this->assertSame($card->getExpiryYear(), $data['payer']['funding_instruments'][0]['credit_card']['expire_year']); $this->assertSame($card->getCvv(), $data['payer']['funding_instruments'][0]['credit_card']['cvv2']); $this->assertSame($card->getFirstName(), $data['payer']['funding_instruments'][0]['credit_card']['first_name']); $this->assertSame($card->getLastName(), $data['payer']['funding_instruments'][0]['credit_card']['last_name']); $this->assertSame($card->getAddress1(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line1']); $this->assertSame($card->getAddress2(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line2']); $this->assertSame($card->getCity(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['city']); $this->assertSame($card->getState(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['state']); $this->assertSame($card->getPostcode(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['postal_code']); $this->assertSame($card->getCountry(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['country_code']); } public function testGetDataWithItems() { $this->request->setAmount('50.00'); $this->request->setCurrency('USD'); $this->request->setItems(array( array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10), array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40), )); $data = $this->request->getData(); $transactionData = $data['transactions'][0]; $this->assertSame('Floppy Disk', $transactionData['item_list']['items'][0]['name']); $this->assertSame('MS-DOS', $transactionData['item_list']['items'][0]['description']); $this->assertSame(2, $transactionData['item_list']['items'][0]['quantity']); $this->assertSame('10.00', $transactionData['item_list']['items'][0]['price']); $this->assertSame('CD-ROM', $transactionData['item_list']['items'][1]['name']); $this->assertSame('Windows 95', $transactionData['item_list']['items'][1]['description']); $this->assertSame(1, $transactionData['item_list']['items'][1]['quantity']); $this->assertSame('40.00', $transactionData['item_list']['items'][1]['price']); $this->assertSame('50.00', $transactionData['amount']['total']); $this->assertSame('USD', $transactionData['amount']['currency']); } public function testDescription() { $this->request->setTransactionId(''); $this->request->setDescription(''); $this->assertEmpty($this->request->getDescription()); $this->request->setTransactionId(''); $this->request->setDescription('Sheep'); $this->assertEquals('Sheep', $this->request->getDescription()); $this->request->setTransactionId('abc123'); $this->request->setDescription(''); $this->assertEquals('abc123', $this->request->getDescription()); $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $this->assertEquals('abc123 : Sheep', $this->request->getDescription()); } } paypal/tests/Message/RestCompleteSubscriptionRequestTest.php 0000666 00000001304 15165413756 0020534 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestCompleteSubscriptionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestCompleteSubscriptionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestCompleteSubscriptionRequest($client, $request); $this->request->initialize(array( 'transactionReference' => 'ABC-123', )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals(array(), $data); } } paypal/tests/Message/ExpressAuthorizeResponseTest.php 0000666 00000003670 15165413756 0017223 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\Message\ExpressAuthorizeResponse; class ExpressAuthorizeResponseTest extends TestCase { public function testConstruct() { // response should decode URL format data $response = new ExpressAuthorizeResponse($this->getMockRequest(), 'example=value&foo=bar'); $this->assertEquals(array('example' => 'value', 'foo' => 'bar'), $response->getData()); } public function testExpressPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('ExpressPurchaseSuccess.txt'); $request = $this->getMockRequest(); $request->shouldReceive('getTestMode')->once()->andReturn(true); $response = new ExpressAuthorizeResponse($request, $httpResponse->getBody()); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertSame('EC-42721413K79637829', $response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertNull($response->getRedirectData()); $this->assertSame('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); } public function testExpressPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('ExpressPurchaseFailure.txt'); $response = new ExpressAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage()); } } paypal/tests/Message/RestDeleteCardRequestTest.php 0000666 00000001475 15165413756 0016364 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class RestDeleteCardRequestTest extends TestCase { /** @var RestDeleteCardRequest */ private $request; /** @var CreditCard */ private $card; public function setUp() { parent::setUp(); $this->request = new RestDeleteCardRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array('cardReference' => 'CARD-TEST123')); } public function testGetData() { $data = $this->request->getData(); $this->assertTrue(is_array($data)); $this->assertEmpty($data); } public function testEndpoint() { $this->assertStringEndsWith('/vault/credit-cards/CARD-TEST123', $this->request->getEndpoint()); } } paypal/tests/Message/ExpressTransactionSearchResponseTest.php 0000666 00000003175 15165413756 0020664 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class ExpressTransactionSearchResponseTest extends TestCase { public function testConstruct() { // response should decode URL format data $response = new ExpressTransactionSearchResponse($this->getMockRequest(), 'ACK=Success&BUILD=18308778'); $this->assertEquals( array('ACK' => 'Success', 'BUILD' => '18308778', 'payments' => array()), $response->getData() ); } public function testExpressTransactionSearch() { $httpResponse = $this->getMockHttpResponse('ExpressTransactionSearchResponse.txt'); $response = new ExpressTransactionSearchResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getMessage()); $this->assertArrayHasKey('payments', $response->getData()); foreach ($response->getPayments() as $payment) { $this->assertArrayHasKey('TIMESTAMP', $payment); $this->assertArrayHasKey('TIMEZONE', $payment); $this->assertArrayHasKey('TYPE', $payment); $this->assertArrayHasKey('EMAIL', $payment); $this->assertArrayHasKey('NAME', $payment); $this->assertArrayHasKey('TRANSACTIONID', $payment); $this->assertArrayHasKey('STATUS', $payment); $this->assertArrayHasKey('AMT', $payment); $this->assertArrayHasKey('CURRENCYCODE', $payment); $this->assertArrayHasKey('FEEAMT', $payment); $this->assertArrayHasKey('NETAMT', $payment); } } } paypal/tests/Message/ExpressCompleteAuthorizeRequestTest.php 0000666 00000007471 15165413756 0020551 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\PayPal\Message\ExpressCompleteAuthorizeRequest; use Omnipay\Tests\TestCase; class ExpressCompleteAuthorizeRequestTest extends TestCase { /** * @var \Omnipay\PayPal\Message\ExpressCompleteAuthorizeRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $request->query->set('PayerID', 'Payer-1234'); $request->query->set('token', 'TOKEN1234'); $this->request = new ExpressCompleteAuthorizeRequest($client, $request); } public function testGetData() { $this->request->setAmount('1.23'); $this->request->setCurrency('USD'); $this->request->setTransactionId('ABC-123'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $this->request->setDescription('DESC'); $this->request->setNotifyUrl('https://www.example.com/notify'); $this->request->setMaxAmount('0.00'); $this->request->setTaxAmount('0.00'); $this->request->setShippingAmount('0.00'); $this->request->setHandlingAmount('0.00'); $this->request->setShippingDiscount('0.00'); $this->request->setInsuranceAmount('0.00'); $expected = array(); $expected['METHOD'] = 'DoExpressCheckoutPayment'; $expected['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization'; $expected['PAYMENTREQUEST_0_AMT'] = '1.23'; $expected['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'; $expected['PAYMENTREQUEST_0_INVNUM'] = 'ABC-123'; $expected['PAYMENTREQUEST_0_DESC'] = 'DESC'; $expected['PAYMENTREQUEST_0_NOTIFYURL'] = 'https://www.example.com/notify'; $expected['USER'] = 'testuser'; $expected['PWD'] = 'testpass'; $expected['SIGNATURE'] = 'SIG'; $expected['SUBJECT'] = 'SUB'; $expected['VERSION'] = ExpressCompleteAuthorizeRequest::API_VERSION; $expected['TOKEN'] = 'TOKEN1234'; $expected['PAYERID'] = 'Payer-1234'; $expected['MAXAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_TAXAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_HANDLINGAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00'; $expected['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00'; $this->assertEquals($expected, $this->request->getData()); } public function testGetDataWithItems() { $this->request->setAmount('50.00'); $this->request->setCurrency('USD'); $this->request->setTransactionId('ABC-123'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $this->request->setDescription('DESC'); $this->request->setItems(array( array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10), array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40), )); $data = $this->request->getData(); $this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']); $this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']); $this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']); $this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']); $this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']); $this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']); $this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']); $this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']); } } paypal/tests/Message/RestUpdatePlanRequestTest.php 0000666 00000001441 15165413756 0016416 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestUpdatePlanRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestUpdatePlanRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestUpdatePlanRequest($client, $request); $this->request->initialize(array( 'transactionReference' => 'ABC-123', 'state' => 'ACTIVE', )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('/', $data[0]['path']); $this->assertEquals('ACTIVE', $data[0]['value']['state']); } } paypal/tests/Message/RefundRequestTest.php 0000666 00000003443 15165413756 0014752 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\PayPal\Message\RefundRequest; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase { /** * @var \Omnipay\PayPal\Message\RefundRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RefundRequest($client, $request); } /** * @dataProvider provideRefundTypes */ public function testGetData($type, $amount) { $this->request->setAmount($amount); $this->request->setCurrency('USD'); $this->request->setTransactionReference('ABC-123'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $expected = array(); $expected['REFUNDTYPE'] = $type; $expected['METHOD'] = 'RefundTransaction'; $expected['TRANSACTIONID'] = 'ABC-123'; $expected['USER'] = 'testuser'; $expected['PWD'] = 'testpass'; $expected['SIGNATURE'] = 'SIG'; $expected['SUBJECT'] = 'SUB'; $expected['VERSION'] = RefundRequest::API_VERSION; // $amount will be a formatted string, and '0.00' evaluates to true if ((float)$amount) { $expected['AMT'] = $amount; $expected['CURRENCYCODE'] = 'USD'; } $this->assertEquals($expected, $this->request->getData()); } public function provideRefundTypes() { return array( 'Partial' => array('Partial', '1.23'), // All amounts must include decimals or be a float if the currency supports decimals. 'Full' => array('Full', '0.00'), ); } } paypal/tests/Message/RestReactivateSubscriptionRequestTest.php 0000666 00000001460 15165413756 0021056 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestReactivateSubscriptionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestReactivateSubscriptionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestReactivateSubscriptionRequest($client, $request); $this->request->initialize(array( 'transactionReference' => 'ABC-123', 'description' => 'Reactivate this subscription', )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('Reactivate this subscription', $data['note']); } } paypal/tests/Message/ProPurchaseRequestTest.php 0000666 00000004510 15165413756 0015756 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class ProPurchaseRequestTest extends TestCase { /** * @var ProPurchaseRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new ProPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'currency' => 'USD', 'card' => $this->getValidCard(), ) ); } public function testGetData() { $card = new CreditCard($this->getValidCard()); $card->setStartMonth(1); $card->setStartYear(2000); $this->request->setCard($card); $this->request->setTransactionId('abc123'); $this->request->setDescription('Sheep'); $this->request->setClientIp('127.0.0.1'); $data = $this->request->getData(); $this->assertSame('DoDirectPayment', $data['METHOD']); $this->assertSame('Sale', $data['PAYMENTACTION']); $this->assertSame('10.00', $data['AMT']); $this->assertSame('USD', $data['CURRENCYCODE']); $this->assertSame('abc123', $data['INVNUM']); $this->assertSame('Sheep', $data['DESC']); $this->assertSame('127.0.0.1', $data['IPADDRESS']); $this->assertSame($card->getNumber(), $data['ACCT']); $this->assertSame($card->getBrand(), $data['CREDITCARDTYPE']); $this->assertSame($card->getExpiryDate('mY'), $data['EXPDATE']); $this->assertSame('012000', $data['STARTDATE']); $this->assertSame($card->getCvv(), $data['CVV2']); $this->assertSame($card->getIssueNumber(), $data['ISSUENUMBER']); $this->assertSame($card->getFirstName(), $data['FIRSTNAME']); $this->assertSame($card->getLastName(), $data['LASTNAME']); $this->assertSame($card->getEmail(), $data['EMAIL']); $this->assertSame($card->getAddress1(), $data['STREET']); $this->assertSame($card->getAddress2(), $data['STREET2']); $this->assertSame($card->getCity(), $data['CITY']); $this->assertSame($card->getState(), $data['STATE']); $this->assertSame($card->getPostcode(), $data['ZIP']); $this->assertSame($card->getCountry(), $data['COUNTRYCODE']); } } paypal/tests/Message/ExpressAuthorizeRequestTest.php 0000666 00000040545 15165413756 0017057 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\PayPal\Message\ExpressAuthorizeRequest; use Omnipay\PayPal\Support\InstantUpdateApi\BillingAgreement; use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption; use Omnipay\Tests\TestCase; class ExpressAuthorizeRequestTest extends TestCase { /** * @var ExpressAuthorizeRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new ExpressAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', ) ); } public function testGetDataWithoutCard() { $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'noShipping' => 0, 'localeCode' => 'EN', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Inc.', 'customerServiceNumber' => '1-801-FLOWERS', )); $data = $this->request->getData(); $this->assertSame('10.00', $data['PAYMENTREQUEST_0_AMT']); $this->assertSame('AUD', $data['PAYMENTREQUEST_0_CURRENCYCODE']); $this->assertSame('111', $data['PAYMENTREQUEST_0_INVNUM']); $this->assertSame('Order Description', $data['PAYMENTREQUEST_0_DESC']); $this->assertSame('https://www.example.com/return', $data['RETURNURL']); $this->assertSame('https://www.example.com/cancel', $data['CANCELURL']); $this->assertSame('demo@example.com', $data['SUBJECT']); $this->assertSame('https://www.example.com/header.jpg', $data['HDRIMG']); $this->assertSame(0, $data['NOSHIPPING']); $this->assertSame(0, $data['ALLOWNOTE']); $this->assertSame('EN', $data['LOCALECODE']); $this->assertSame(0, $data['ADDROVERRIDE']); $this->assertSame('Dunder Mifflin Paper Company, Inc.', $data['BRANDNAME']); $this->assertSame('1-801-FLOWERS', $data['CUSTOMERSERVICENUMBER']); } public function testGetDataWithCard() { $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'noShipping' => 2, 'allowNote' => 1, 'addressOverride' => 1, 'brandName' => 'Dunder Mifflin Paper Company, Inc.', 'maxAmount' => 123.45, 'logoImageUrl' => 'https://www.example.com/logo.jpg', 'borderColor' => 'CCCCCC', 'localeCode' => 'EN', 'customerServiceNumber' => '1-801-FLOWERS', 'sellerPaypalAccountId' => 'billing@example.com', )); $card = new CreditCard(array( 'name' => 'John Doe', 'address1' => '123 NW Blvd', 'address2' => 'Lynx Lane', 'city' => 'Topeka', 'state' => 'KS', 'country' => 'USA', 'postcode' => '66605', 'phone' => '555-555-5555', 'email' => 'test@email.com', )); $this->request->setCard($card); $expected = array( 'METHOD' => 'SetExpressCheckout', 'VERSION' => ExpressAuthorizeRequest::API_VERSION, 'USER' => null, 'PWD' => null, 'SIGNATURE' => null, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization', 'SOLUTIONTYPE' => null, 'LANDINGPAGE' => null, 'NOSHIPPING' => 2, 'ALLOWNOTE' => 1, 'ADDROVERRIDE' => 1, 'PAYMENTREQUEST_0_AMT' => '10.00', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'AUD', 'PAYMENTREQUEST_0_INVNUM' => '111', 'PAYMENTREQUEST_0_DESC' => 'Order Description', 'RETURNURL' => 'https://www.example.com/return', 'CANCELURL' => 'https://www.example.com/cancel', 'SUBJECT' => 'demo@example.com', 'HDRIMG' => 'https://www.example.com/header.jpg', 'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe', 'PAYMENTREQUEST_0_SHIPTOSTREET' => '123 NW Blvd', 'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Lynx Lane', 'PAYMENTREQUEST_0_SHIPTOCITY' => 'Topeka', 'PAYMENTREQUEST_0_SHIPTOSTATE' => 'KS', 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA', 'PAYMENTREQUEST_0_SHIPTOZIP' => '66605', 'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '555-555-5555', 'EMAIL' => 'test@email.com', 'BRANDNAME' => 'Dunder Mifflin Paper Company, Inc.', 'MAXAMT' => 123.45, 'PAYMENTREQUEST_0_TAXAMT' => null, 'PAYMENTREQUEST_0_SHIPPINGAMT' => null, 'PAYMENTREQUEST_0_HANDLINGAMT' => null, 'PAYMENTREQUEST_0_SHIPDISCAMT' => null, 'PAYMENTREQUEST_0_INSURANCEAMT' => null, 'LOGOIMG' => 'https://www.example.com/logo.jpg', 'CARTBORDERCOLOR' => 'CCCCCC', 'LOCALECODE' => 'EN', 'CUSTOMERSERVICENUMBER' => '1-801-FLOWERS', 'PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID' => 'billing@example.com', ); $this->assertEquals($expected, $this->request->getData()); } public function testGetDataWithItems() { $this->request->setItems(array( array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10, 'code' => '123456'), array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40), )); $data = $this->request->getData(); $this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']); $this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']); $this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']); $this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']); $this->assertSame('123456', $data['L_PAYMENTREQUEST_0_NUMBER0']); $this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']); $this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']); $this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']); $this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']); $this->assertSame('60.00', $data['PAYMENTREQUEST_0_ITEMAMT']); } public function testGetDataWithExtraOrderDetails() { $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'noShipping' => 0, 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Inc.', 'taxAmount' => '2.00', 'shippingAmount' => '5.00', 'handlingAmount' => '1.00', 'shippingDiscount' => '-1.00', 'insuranceAmount' => '3.00', )); $data = $this->request->getData(); $this->assertSame('2.00', $data['PAYMENTREQUEST_0_TAXAMT']); $this->assertSame('5.00', $data['PAYMENTREQUEST_0_SHIPPINGAMT']); $this->assertSame('1.00', $data['PAYMENTREQUEST_0_HANDLINGAMT']); $this->assertSame('-1.00', $data['PAYMENTREQUEST_0_SHIPDISCAMT']); $this->assertSame('3.00', $data['PAYMENTREQUEST_0_INSURANCEAMT']); } public function testHeaderImageUrl() { $this->assertSame($this->request, $this->request->setHeaderImageUrl('https://www.example.com/header.jpg')); $this->assertSame('https://www.example.com/header.jpg', $this->request->getHeaderImageUrl()); $data = $this->request->getData(); $this->assertEquals('https://www.example.com/header.jpg', $data['HDRIMG']); } public function testMaxAmount() { $this->request->setMaxAmount(321.54); $this->assertSame(321.54, $this->request->getMaxAmount()); $data = $this->request->getData(); $this->assertSame(321.54, $data['MAXAMT']); } public function testDataWithCallback() { $baseData = array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Incy.', ); $shippingOptions = array( new ShippingOption('First Class', 1.20, true, '1-2 days'), new ShippingOption('Second Class', 0.70, false, '3-5 days'), new ShippingOption('International', 3.50), ); // with a default callback timeout $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', 'shippingOptions' => $shippingOptions, ))); $data = $this->request->getData(); $this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']); $this->assertSame(ExpressAuthorizeRequest::DEFAULT_CALLBACK_TIMEOUT, $data['CALLBACKTIMEOUT']); $this->assertSame('First Class', $data['L_SHIPPINGOPTIONNAME0']); $this->assertSame('1.20', $data['L_SHIPPINGOPTIONAMOUNT0']); $this->assertSame('1', $data['L_SHIPPINGOPTIONISDEFAULT0']); $this->assertSame('1-2 days', $data['L_SHIPPINGOPTIONLABEL0']); $this->assertSame('Second Class', $data['L_SHIPPINGOPTIONNAME1']); $this->assertSame('0.70', $data['L_SHIPPINGOPTIONAMOUNT1']); $this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT1']); $this->assertSame('3-5 days', $data['L_SHIPPINGOPTIONLABEL1']); $this->assertSame('International', $data['L_SHIPPINGOPTIONNAME2']); $this->assertSame('3.50', $data['L_SHIPPINGOPTIONAMOUNT2']); $this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT2']); // with a defined callback timeout $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', 'callbackTimeout' => 10, 'shippingOptions' => $shippingOptions, ))); $data = $this->request->getData(); $this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']); $this->assertSame(10, $data['CALLBACKTIMEOUT']); } public function testDataWithCallbackAndNoDefaultShippingOption() { $baseData = array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Incy.', ); $shippingOptions = array( new ShippingOption('First Class', 1.20, false, '1-2 days'), new ShippingOption('Second Class', 0.70, false, '3-5 days'), new ShippingOption('International', 3.50), ); // with a default callback timeout $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', 'shippingOptions' => $shippingOptions, ))); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('One of the supplied shipping options must be set as default'); $this->request->getData(); } public function testNoAmount() { $baseData = array(// nothing here - should cause a certain exception ); $this->request->initialize($baseData); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('The amount parameter is required'); $this->request->getData(); } public function testAmountButNoReturnUrl() { $baseData = array( 'amount' => 10.00, ); $this->request->initialize($baseData); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('The returnUrl parameter is required'); $this->request->getData(); } public function testBadCallbackConfiguration() { $baseData = array( 'amount' => '10.00', 'currency' => 'AUD', 'transactionId' => '111', 'description' => 'Order Description', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'subject' => 'demo@example.com', 'headerImageUrl' => 'https://www.example.com/header.jpg', 'allowNote' => 0, 'addressOverride' => 0, 'brandName' => 'Dunder Mifflin Paper Company, Incy.', ); $this->request->initialize(array_merge($baseData, array( 'callback' => 'https://www.example.com/calculate-shipping', ))); // from the docblock on this exception - // Thrown when a request is invalid or missing required fields. // callback has been set but no shipping options so expect one of these: $this->expectException(InvalidRequestException::class); $this->request->getData(); } public function testGetDataWithSingleBillingAgreement() { $billingAgreement = new BillingAgreement(false, 'Some Stuff'); $this->request->setBillingAgreement($billingAgreement); $data = $this->request->getData(); $this->assertSame('MerchantInitiatedBillingSingleAgreement', $data['L_BILLINGTYPE0']); $this->assertSame('Some Stuff', $data['L_BILLINGAGREEMENTDESCRIPTION0']); } public function testGetDataWithRecurringBillingAgreement() { $billingAgreement = new BillingAgreement(true, 'Some Stuff'); $this->request->setBillingAgreement($billingAgreement); $data = $this->request->getData(); $this->assertSame('MerchantInitiatedBilling', $data['L_BILLINGTYPE0']); $this->assertSame('Some Stuff', $data['L_BILLINGAGREEMENTDESCRIPTION0']); } public function testGetDataWithBillingAgreementOptionalParameters() { $billingAgreement = new BillingAgreement(true, 'Some Stuff', 'InstantOnly', 'Some custom annotation'); $this->request->setBillingAgreement($billingAgreement); $data = $this->request->getData(); $this->assertSame('MerchantInitiatedBilling', $data['L_BILLINGTYPE0']); $this->assertSame('Some Stuff', $data['L_BILLINGAGREEMENTDESCRIPTION0']); $this->assertSame('InstantOnly', $data['L_PAYMENTTYPE0']); $this->assertSame('Some custom annotation', $data['L_BILLINGAGREEMENTCUSTOM0']); } /** * */ public function testGetDataWithBillingAgreementWrongPaymentType() { $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage("The 'paymentType' parameter can be only 'Any' or 'InstantOnly'"); $billingAgreement = new BillingAgreement(false, 'Some Stuff', 'BadType', 'Some custom annotation'); } } paypal/tests/Message/RestCreateCardRequestTest.php 0000666 00000003220 15165413756 0016353 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class RestCreateCardRequestTest extends TestCase { /** @var RestCreateCardRequest */ protected $request; /** @var CreditCard */ protected $card; public function setUp() { parent::setUp(); $this->request = new RestCreateCardRequest($this->getHttpClient(), $this->getHttpRequest()); $card = $this->getValidCard(); $this->card = new CreditCard($card); $this->request->initialize(array('card' => $card)); } public function testGetData() { $card = $this->card; $data = $this->request->getData(); $this->assertSame($card->getNumber(), $data['number']); $this->assertSame($card->getBrand(), $data['type']); $this->assertSame($card->getExpiryMonth(), $data['expire_month']); $this->assertSame($card->getExpiryYear(), $data['expire_year']); $this->assertSame($card->getCvv(), $data['cvv2']); $this->assertSame($card->getFirstName(), $data['first_name']); $this->assertSame($card->getLastName(), $data['last_name']); $this->assertSame($card->getAddress1(), $data['billing_address']['line1']); $this->assertSame($card->getAddress2(), $data['billing_address']['line2']); $this->assertSame($card->getCity(), $data['billing_address']['city']); $this->assertSame($card->getState(), $data['billing_address']['state']); $this->assertSame($card->getPostcode(), $data['billing_address']['postal_code']); $this->assertSame($card->getCountry(), $data['billing_address']['country_code']); } } paypal/tests/Message/FetchTransactionRequestTest.php 0000666 00000002244 15165413756 0016764 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\PayPal\Message\FetchTransactionRequest; use Omnipay\Tests\TestCase; class FetchTransactionRequestTest extends TestCase { /** * @var \Omnipay\PayPal\Message\FetchTransactionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new FetchTransactionRequest($client, $request); } public function testGetData() { $this->request->setTransactionReference('ABC-123'); $this->request->setUsername('testuser'); $this->request->setPassword('testpass'); $this->request->setSignature('SIG'); $this->request->setSubject('SUB'); $expected = array(); $expected['METHOD'] = 'GetTransactionDetails'; $expected['TRANSACTIONID'] = 'ABC-123'; $expected['USER'] = 'testuser'; $expected['PWD'] = 'testpass'; $expected['SIGNATURE'] = 'SIG'; $expected['SUBJECT'] = 'SUB'; $expected['VERSION'] = RefundRequest::API_VERSION; $this->assertEquals($expected, $this->request->getData()); } } paypal/tests/Message/ExpressInContextAuthorizeResponseTest.php 0000666 00000003713 15165413756 0021055 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse; class ExpressInContextAuthorizeResponseTest extends TestCase { public function testConstruct() { // response should decode URL format data $response = new ExpressInContextAuthorizeResponse($this->getMockRequest(), 'example=value&foo=bar'); $this->assertEquals(array('example' => 'value', 'foo' => 'bar'), $response->getData()); } public function testExpressPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('ExpressPurchaseSuccess.txt'); $request = $this->getMockRequest(); $request->shouldReceive('getTestMode')->once()->andReturn(true); $response = new ExpressInContextAuthorizeResponse($request, $httpResponse->getBody()); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertSame('EC-42721413K79637829', $response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertNull($response->getRedirectData()); $this->assertSame('https://www.sandbox.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); } public function testExpressPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('ExpressPurchaseFailure.txt'); $response = new ExpressInContextAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isPending()); $this->assertFalse($response->isSuccessful()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getTransactionReference()); $this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage()); } } paypal/tests/Message/RestCreateSubscriptionRequestTest.php 0000666 00000002355 15165413756 0020176 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestCreateSubscriptionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestCreateSubscriptionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestCreateSubscriptionRequest($client, $request); $this->request->initialize(array( 'name' => 'Test Subscription', 'description' => 'Test Billing Subscription', 'startDate' => new \DateTime('now', new \DateTimeZone('UTC')), 'planId' => 'ABC-123', 'payerDetails' => array( 'payment_method' => 'paypal', ), )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('Test Subscription', $data['name']); $this->assertEquals('Test Billing Subscription', $data['description']); $this->assertEquals('ABC-123', $data['plan']['id']); $this->assertEquals('paypal', $data['payer']['payment_method']); } } paypal/tests/Message/ExpressVoidRequestTest.php 0000666 00000001342 15165413756 0015776 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\CreditCard; use Omnipay\Tests\TestCase; class ExpressVoidRequestTest extends TestCase { /** * @var ExpressVoidRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new ExpressVoidRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'transactionReference' => 'ASDFASDFASDF', ) ); } public function testGetData() { $data = $this->request->getData(); $this->assertSame('ASDFASDFASDF', $data['AUTHORIZATIONID']); $this->assertSame('DoVoid', $data['METHOD']); } } paypal/tests/Message/RestCancelSubscriptionRequestTest.php 0000666 00000001434 15165413756 0020155 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestCancelSubscriptionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestCancelSubscriptionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestCancelSubscriptionRequest($client, $request); $this->request->initialize(array( 'transactionReference' => 'ABC-123', 'description' => 'Cancel this subscription', )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('Cancel this subscription', $data['note']); } } paypal/tests/Message/RestListPlanRequestTest.php 0000666 00000001513 15165413756 0016107 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; class RestListPlanRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestListPlanRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestListPlanRequest($client, $request); } public function testGetData() { $data = $this->request->getData(); $this->assertArrayHasKey('page',$data); $this->assertArrayHasKey('status',$data); $this->assertArrayHasKey('page_size',$data); $this->assertArrayHasKey('total_required',$data); } public function testEndpoint() { $this->assertStringEndsWith('/payments/billing-plans', $this->request->getEndpoint()); } } paypal/tests/Message/RestSuspendSubscriptionRequestTest.php 0000666 00000001441 15165413756 0020407 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Tests\TestCase; use Omnipay\PayPal\RestGateway; class RestSuspendSubscriptionRequestTest extends TestCase { /** @var \Omnipay\PayPal\Message\RestSuspendSubscriptionRequest */ private $request; public function setUp() { $client = $this->getHttpClient(); $request = $this->getHttpRequest(); $this->request = new RestSuspendSubscriptionRequest($client, $request); $this->request->initialize(array( 'transactionReference' => 'ABC-123', 'description' => 'Suspend this subscription', )); } public function testGetData() { $data = $this->request->getData(); $this->assertEquals('Suspend this subscription', $data['note']); } } paypal/tests/Message/ExpressTransactionSearchRequestTest.php 0000666 00000006127 15165413756 0020516 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Tests\TestCase; class ExpressTransactionSearchRequestTest extends TestCase { /** * @var ExpressTransactionSearchRequest */ private $request; public function setUp() { parent::setUp(); $this->request = new ExpressTransactionSearchRequest($this->getHttpClient(), $this->getHttpRequest()); } public function testGetData() { $startDate = '2015-01-01'; $endDate = '2016-01-01'; $this->request->initialize(array( 'amount' => '10.00', 'currency' => 'USD', 'startDate' => $startDate, 'endDate' => $endDate, 'salutation' => 'Mr.', 'firstName' => 'Jhon', 'middleName' => 'Carter', 'lastName' => 'Macgiver', 'suffix' => 'Jh', 'email' => 'test@email.com', 'receiver' => 'Patt Doret', 'receiptId' => '1111', 'transactionId' => 'XKCD', 'invoiceNumber' => '123456789', 'card' => array('number' => '376449047333005'), 'auctionItemNumber' => '321564', 'transactionClass' => 'Received', 'status' => 'Success', 'profileId' => '00000000000' )); $data = $this->request->getData(); $startDate = new \DateTime($startDate); $endDate = new \DateTime($endDate); $this->assertSame('10.00', $data['AMT']); $this->assertSame('USD', $data['CURRENCYCODE']); $this->assertSame($startDate->format(\DateTime::ISO8601), $data['STARTDATE']); $this->assertSame($endDate->format(\DateTime::ISO8601), $data['ENDDATE']); $this->assertSame('Mr.', $data['SALUTATION']); $this->assertSame('Jhon', $data['FIRSTNAME']); $this->assertSame('Carter', $data['MIDDLENAME']); $this->assertSame('Macgiver', $data['LASTNAME']); $this->assertSame('Jh', $data['SUFFIX']); $this->assertSame('test@email.com', $data['EMAIL']); $this->assertSame('XKCD', $data['TRANSACTIONID']); $this->assertSame('123456789', $data['INVNUM']); $this->assertSame('376449047333005', $data['ACCT']); $this->assertSame('321564', $data['AUCTIONITEMNUMBER']); $this->assertSame('Received', $data['TRANSACTIONCLASS']); $this->assertSame('Success', $data['STATUS']); $this->assertSame('00000000000', $data['PROFILEID']); } public function testWithoutStartDate() { $this->request->initialize(array()); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('The startDate parameter is required'); $this->request->getData(); } public function testAmountWithoutCurrency() { $this->request->setStartDate('2015-01-01'); $this->request->setAmount(150.00); $this->expectException(InvalidRequestException::class); $this->expectExceptionMessage('The currency parameter is required'); $this->request->getData(); } } paypal/CONTRIBUTING.md 0000666 00000001040 15165413756 0010277 0 ustar 00 # Contributing Guidelines * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. * Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) style and that all tests pass. * Send the pull request. * Check that the Travis CI build passed. If not, rinse and repeat. paypal/src/ExpressInContextGateway.php 0000666 00000001100 15165413756 0014152 0 ustar 00 <?php namespace Omnipay\PayPal; /** * PayPal Express In-Context Class */ class ExpressInContextGateway extends ExpressGateway { public function getName() { return 'PayPal Express In-Context'; } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressInContextAuthorizeRequest', $parameters); } public function order(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressInContextOrderRequest', $parameters); } } paypal/src/Support/InstantUpdateApi/BillingAgreement.php 0000666 00000004237 15165413756 0017462 0 ustar 00 <?php namespace Omnipay\PayPal\Support\InstantUpdateApi; use Omnipay\Common\Exception\InvalidRequestException; class BillingAgreement { /** * Billing agreement types for single or recurring payment * * @var array */ protected $types = array( 'single' => 'MerchantInitiatedBillingSingleAgreement', 'recurring' => 'MerchantInitiatedBilling', ); /** @var string */ private $type; /** @var string */ private $description; /** @var string */ private $paymentType; /** @var string */ private $customAnnotation; /** * @param bool $recurring L_BILLINGTYPE0 * @param string $description L_BILLINGAGREEMENTDESCRIPTION0 * @param null|string $paymentType L_PAYMENTTYPE0 * @param null|string $customAnnotation L_BILLINGAGREEMENTCUSTOM0 * @throws \Exception */ public function __construct($recurring, $description, $paymentType = null, $customAnnotation = null) { if (!$recurring && !is_null($paymentType) && !in_array($paymentType, array('Any', 'InstantOnly'))) { throw new InvalidRequestException("The 'paymentType' parameter can be only 'Any' or 'InstantOnly'"); } $this->type = $recurring ? $this->types['recurring'] : $this->types['single']; $this->description = $description; $this->customAnnotation = $customAnnotation; $this->paymentType = $paymentType; } /** * @return string */ public function getType() { return $this->type; } /** * @return string */ public function getDescription() { return $this->description; } /** * @return bool */ public function hasPaymentType() { return !is_null($this->paymentType); } /** * @return string */ public function getPaymentType() { return $this->paymentType; } /** * @return bool */ public function hasCustomAnnotation() { return !is_null($this->customAnnotation); } /** * @return string */ public function getCustomAnnotation() { return $this->customAnnotation; } } paypal/src/Support/InstantUpdateApi/ShippingOption.php 0000666 00000002434 15165413756 0017221 0 ustar 00 <?php namespace Omnipay\PayPal\Support\InstantUpdateApi; class ShippingOption { /** @var string */ private $name; /** @var float */ private $amount; /** @var bool */ private $isDefault; /** @var string */ private $label; /** * @param string $name L_SHIPPINGOPTIONNAME0 * @param float $amount L_SHIPPINGOPTIONAMOUNT0 * @param bool $isDefault L_SHIPPINGOPTIONISDEFAULT0 * @param string $label L_SHIPPINGOPTIONLABEL0 */ public function __construct($name, $amount, $isDefault = false, $label = null) { $this->name = $name; $this->amount = $amount; $this->isDefault = $isDefault; $this->label = $label; } /** * @return bool */ public function hasLabel() { return !is_null($this->label); } /** * @return string */ public function getName() { return $this->name; } /** * @return float */ public function getAmount() { return $this->amount; } /** * @return boolean */ public function isDefault() { return $this->isDefault; } /** * @return string */ public function getLabel() { return $this->label; } } paypal/src/ProGateway.php 0000666 00000003532 15165413756 0011440 0 ustar 00 <?php namespace Omnipay\PayPal; use Omnipay\Common\AbstractGateway; /** * PayPal Pro Class */ class ProGateway extends AbstractGateway { public function getName() { return 'PayPal Pro'; } public function getDefaultParameters() { return array( 'username' => '', 'password' => '', 'signature' => '', 'testMode' => false, ); } public function getUsername() { return $this->getParameter('username'); } public function setUsername($value) { return $this->setParameter('username', $value); } public function getPassword() { return $this->getParameter('password'); } public function setPassword($value) { return $this->setParameter('password', $value); } public function getSignature() { return $this->getParameter('signature'); } public function setSignature($value) { return $this->setParameter('signature', $value); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ProAuthorizeRequest', $parameters); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ProPurchaseRequest', $parameters); } public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\CaptureRequest', $parameters); } public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RefundRequest', $parameters); } public function fetchTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\FetchTransactionRequest', $parameters); } } paypal/src/PayPalItemBag.php 0000666 00000001134 15165413756 0011771 0 ustar 00 <?php /** * PayPal Item bag */ namespace Omnipay\PayPal; use Omnipay\Common\ItemBag; use Omnipay\Common\ItemInterface; /** * Class PayPalItemBag * * @package Omnipay\PayPal */ class PayPalItemBag extends ItemBag { /** * Add an item to the bag * * @see Item * * @param ItemInterface|array $item An existing item, or associative array of item parameters */ public function add($item) { if ($item instanceof ItemInterface) { $this->items[] = $item; } else { $this->items[] = new PayPalItem($item); } } } paypal/src/RestGateway.php 0000666 00000063720 15165413756 0011622 0 ustar 00 <?php /** * PayPal Pro Class using REST API */ namespace Omnipay\PayPal; use Omnipay\Common\AbstractGateway; use Omnipay\PayPal\Message\ProAuthorizeRequest; use Omnipay\PayPal\Message\CaptureRequest; use Omnipay\PayPal\Message\RefundRequest; /** * PayPal Pro Class using REST API * * This class forms the gateway class for PayPal REST requests via the PayPal REST APIs. * * The PayPal API uses HTTP verbs and a RESTful endpoint structure. OAuth 2.0 is used * as the API Authorization framework. Request and response payloads are formatted as JSON. * * The PayPal REST APIs are supported in two environments. Use the Sandbox environment * for testing purposes, then move to the live environment for production processing. * When testing, generate an access token with your test credentials to make calls to * the Sandbox URIs. When you’re set to go live, use the live credentials assigned to * your app to generate a new access token to be used with the live URIs. * * ### Test Mode * * In order to use this for testing in sandbox mode you will need at least two sandbox * test accounts. One will need to be a business account, and one will need to be a * personal account with credit card details. To create these you will need to go to * the sandbox accounts section of the PayPal developer dashboard, here: * https://developer.paypal.com/webapps/developer/applications/accounts * On that page click "Create Account" and follow the prompts. When you are creating the * Personal account, ensure that it is created with a credit card -- either Visa or * MasterCard or one of the other types. When you are testing in the sandbox, use the * credit card details you will receive for this Personal account rather than any other * commonly used test credit card numbers (e.g. visa card 4111111111111111 or 4444333322221111 * both of which will result in Error 500 / INTERNAL_SERVICE_ERROR type errors from the * PayPal gateway). * * With each API call, you’ll need to set request headers, including an OAuth 2.0 * access token. Get an access token by using the OAuth 2.0 client_credentials token * grant type with your clientId:secret as your Basic Auth credentials. For more * information, see Make your first call (link). This class sets all of the headers * associated with the API call for you, including making preliminary calls to create * or update the OAuth 2.0 access token before each call you make, if required. All * you need to do is provide the clientId and secret when you initialize the gateway, * or use the set*() calls to set them after creating the gateway object. * * ### Credentials * * To create production and sandbox credentials for your PayPal account: * * * Log into your PayPal account. * * Navigate to your Sandbox accounts at https://developer.paypal.com/webapps/developer/applications/accounts * to ensure that you have a valid sandbox account to use for testing. If you don't already have a sandbox * account, one can be created on this page. You will actually need 2 accounts, a personal account and a * business account, the business account is the one you need to use for creating API applications. * * Check your account status on https://developer.paypal.com/webapps/developer/account/status to ensure * that it is valid for live transactions. * * Navigate to the My REST apps page: https://developer.paypal.com/webapps/developer/applications/myapps * * Click *Create App* * * On the next page, enter an App name and select the sandbox account to use, then click *Create app*. * * On the next page the sandbox account, endpoint, Client ID and Secret should be displayed. * Record these. The Sandbox account should match the one that you selected on the previous * page, and the sandbox endpoint should be ai.sandbox.paypal.com * * Adjacent to *Live credentials* click *Show* to display your live credentials. The endpoint * for these should be api.paypal.com, there should also be a Client ID and Secret. * * You can create additional REST APIs apps for other websites -- because the webhooks are * stored per app then it pays to have one API app per website that you are using (and an * additional one for things like command line testing, etc). * * ### Example * * #### Initialize Gateway * * <code> * // Create a gateway for the PayPal RestGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * </code> * * #### Direct Credit Card Payment * * <code> * // Create a credit card object * // DO NOT USE THESE CARD VALUES -- substitute your own * // see the documentation in the class header. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'User', * 'number' => '4111111111111111', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * try { * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test purchase transaction.', * 'card' => $card, * )); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway purchase response data == " . print_r($data, true) . "\n"; * * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * } * } catch (\Exception $e) { * echo "Exception caught while attempting authorize.\n"; * echo "Exception type == " . get_class($e) . "\n"; * echo "Message == " . $e->getMessage() . "\n"; * } * </code> * * ### Dashboard * * Once you have processed some payments you can go to the PayPal sandbox site, * at https://www.sandbox.paypal.com/ and log in with the email address and password * of your PayPal sandbox business test account. You will then see the result * of those transactions on the "My recent activity" list under the My Account * tab. * * @link https://developer.paypal.com/docs/api/ * @link https://devtools-paypal.com/integrationwizard/ * @link http://paypal.github.io/sdk/ * @link https://developer.paypal.com/docs/integration/direct/rest_api_payment_country_currency_support/ * @link https://developer.paypal.com/docs/faq/ * @link https://developer.paypal.com/docs/integration/direct/make-your-first-call/ * @link https://developer.paypal.com/docs/integration/web/accept-paypal-payment/ * @link https://developer.paypal.com/docs/api/#authentication--headers * @see Omnipay\PayPal\Message\AbstractRestRequest */ class RestGateway extends AbstractGateway { // Constants used in plan creation const BILLING_PLAN_TYPE_FIXED = 'FIXED'; const BILLING_PLAN_TYPE_INFINITE = 'INFINITE'; const BILLING_PLAN_FREQUENCY_DAY = 'DAY'; const BILLING_PLAN_FREQUENCY_WEEK = 'WEEK'; const BILLING_PLAN_FREQUENCY_MONTH = 'MONTH'; const BILLING_PLAN_FREQUENCY_YEAR = 'YEAR'; const BILLING_PLAN_STATE_CREATED = 'CREATED'; const BILLING_PLAN_STATE_ACTIVE = 'ACTIVE'; const BILLING_PLAN_STATE_INACTIVE = 'INACTIVE'; const BILLING_PLAN_STATE_DELETED = 'DELETED'; const PAYMENT_TRIAL = 'TRIAL'; const PAYMENT_REGULAR = 'REGULAR'; public function getName() { return 'PayPal REST'; } public function getDefaultParameters() { return array( 'clientId' => '', 'secret' => '', 'token' => '', 'testMode' => false, ); } // // Tokens -- methods to set up, store and retrieve the OAuth 2.0 access token. // // @link https://developer.paypal.com/docs/api/#authentication--headers // /** * Get OAuth 2.0 client ID for the access token. * * Get an access token by using the OAuth 2.0 client_credentials * token grant type with your clientId:secret as your Basic Auth * credentials. * * @return string */ public function getClientId() { return $this->getParameter('clientId'); } /** * Set OAuth 2.0 client ID for the access token. * * Get an access token by using the OAuth 2.0 client_credentials * token grant type with your clientId:secret as your Basic Auth * credentials. * * @param string $value * @return RestGateway provides a fluent interface */ public function setClientId($value) { return $this->setParameter('clientId', $value); } /** * Get OAuth 2.0 secret for the access token. * * Get an access token by using the OAuth 2.0 client_credentials * token grant type with your clientId:secret as your Basic Auth * credentials. * * @return string */ public function getSecret() { return $this->getParameter('secret'); } /** * Set OAuth 2.0 secret for the access token. * * Get an access token by using the OAuth 2.0 client_credentials * token grant type with your clientId:secret as your Basic Auth * credentials. * * @param string $value * @return RestGateway provides a fluent interface */ public function setSecret($value) { return $this->setParameter('secret', $value); } /** * Get OAuth 2.0 access token. * * @param bool $createIfNeeded [optional] - If there is not an active token present, should we create one? * @return string */ public function getToken($createIfNeeded = true) { if ($createIfNeeded && !$this->hasToken()) { $response = $this->createToken()->send(); if ($response->isSuccessful()) { $data = $response->getData(); if (isset($data['access_token'])) { $this->setToken($data['access_token']); $this->setTokenExpires(time() + $data['expires_in']); } } } return $this->getParameter('token'); } /** * Create OAuth 2.0 access token request. * * @return \Omnipay\PayPal\Message\RestTokenRequest */ public function createToken() { return $this->createRequest('\Omnipay\PayPal\Message\RestTokenRequest', array()); } /** * Set OAuth 2.0 access token. * * @param string $value * @return RestGateway provides a fluent interface */ public function setToken($value) { return $this->setParameter('token', $value); } /** * Get OAuth 2.0 access token expiry time. * * @return integer */ public function getTokenExpires() { return $this->getParameter('tokenExpires'); } /** * Set OAuth 2.0 access token expiry time. * * @param integer $value * @return RestGateway provides a fluent interface */ public function setTokenExpires($value) { return $this->setParameter('tokenExpires', $value); } /** * Is there a bearer token and is it still valid? * * @return bool */ public function hasToken() { $token = $this->getParameter('token'); $expires = $this->getTokenExpires(); if (!empty($expires) && !is_numeric($expires)) { $expires = strtotime($expires); } return !empty($token) && time() < $expires; } /** * Create Request * * This overrides the parent createRequest function ensuring that the OAuth * 2.0 access token is passed along with the request data -- unless the * request is a RestTokenRequest in which case no token is needed. If no * token is available then a new one is created (e.g. if there has been no * token request or the current token has expired). * * @param string $class * @param array $parameters * @return \Omnipay\PayPal\Message\AbstractRestRequest */ public function createRequest($class, array $parameters = array()) { if (!$this->hasToken() && $class != '\Omnipay\PayPal\Message\RestTokenRequest') { // This will set the internal token parameter which the parent // createRequest will find when it calls getParameters(). $this->getToken(true); } return parent::createRequest($class, $parameters); } // // Payments -- Create payments or get details of one or more payments. // // @link https://developer.paypal.com/docs/api/#payments // /** * Create a purchase request. * * PayPal provides various payment related operations using the /payment * resource and related sub-resources. Use payment for direct credit card * payments and PayPal account payments. You can also use sub-resources * to get payment related details. * * @link https://developer.paypal.com/docs/api/#create-a-payment * @param array $parameters * @return \Omnipay\PayPal\Message\RestPurchaseRequest */ public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestPurchaseRequest', $parameters); } /** * Fetch a purchase request. * * Use this call to get details about payments that have not completed, * such as payments that are created and approved, or if a payment has failed. * * @link https://developer.paypal.com/docs/api/#look-up-a-payment-resource * @param array $parameters * @return \Omnipay\PayPal\Message\RestFetchPurchaseRequest */ public function fetchPurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestFetchPurchaseRequest', $parameters); } /** * List purchase requests. * * Use this call to get a list of payments in any state (created, approved, * failed, etc.). The payments returned are the payments made to the merchant * making the call. * * @link https://developer.paypal.com/docs/api/#list-payment-resources * @param array $parameters * @return \Omnipay\PayPal\Message\RestListPurchaseRequest */ public function listPurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestListPurchaseRequest', $parameters); } /** * Completes a purchase request. * * @link https://developer.paypal.com/docs/api/#execute-an-approved-paypal-payment * @param array $parameters * @return Message\AbstractRestRequest */ public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCompletePurchaseRequest', $parameters); } // TODO: Update a payment resource https://developer.paypal.com/docs/api/#update-a-payment-resource // // Authorizations -- Capture, reauthorize, void and look up authorizations. // // @link https://developer.paypal.com/docs/api/#authorizations // @link https://developer.paypal.com/docs/integration/direct/capture-payment/ // /** * Create an authorization request. * * To collect payment at a later time, first authorize a payment using the /payment resource. * You can then capture the payment to complete the sale and collect payment. * * @link https://developer.paypal.com/docs/integration/direct/capture-payment/#authorize-the-payment * @link https://developer.paypal.com/docs/api/#authorizations * @param array $parameters * @return \Omnipay\PayPal\Message\RestAuthorizeRequest */ public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestAuthorizeRequest', $parameters); } /** * Void an authorization. * * To to void a previously authorized payment. * * @link https://developer.paypal.com/docs/api/#void-an-authorization * @param array $parameters * @return \Omnipay\PayPal\Message\RestVoidRequest */ public function void(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestVoidRequest', $parameters); } /** * Capture an authorization. * * Use this resource to capture and process a previously created authorization. * To use this resource, the original payment call must have the intent set to * authorize. * * @link https://developer.paypal.com/docs/api/#capture-an-authorization * @param array $parameters * @return \Omnipay\PayPal\Message\RestCaptureRequest */ public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCaptureRequest', $parameters); } // TODO: Authorizations with payment_method == paypal. /** * Refund a Captured Payment * * To refund captured payments (authorization transaction) created by a authorize request. * * @link https://developer.paypal.com/docs/api/#refund-a-captured-payment * @param array $parameters * @return \Omnipay\PayPal\Message\RestRefundCaptureRequest */ public function refundCapture(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestRefundCaptureRequest', $parameters); } // // Sale Transactions -- Get and refund completed payments (sale transactions). // @link https://developer.paypal.com/docs/api/#sale-transactions // /** * Fetch a Sale Transaction * * To get details about completed payments (sale transaction) created by a payment request * or to refund a direct sale transaction, PayPal provides the /sale resource and related * sub-resources. * * @link https://developer.paypal.com/docs/api/#sale-transactions * @param array $parameters * @return \Omnipay\PayPal\Message\RestFetchTransactionRequest */ public function fetchTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestFetchTransactionRequest', $parameters); } /** * Refund a Sale Transaction * * To get details about completed payments (sale transaction) created by a payment request * or to refund a direct sale transaction, PayPal provides the /sale resource and related * sub-resources. * * @link https://developer.paypal.com/docs/api/#sale-transactions * @param array $parameters * @return \Omnipay\PayPal\Message\RestRefundRequest */ public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestRefundRequest', $parameters); } // // Vault: Store customer credit cards securely. // // @link https://developer.paypal.com/docs/api/#vault // /** * Store a credit card in the vault * * You can currently use the /vault API to store credit card details * with PayPal instead of storing them on your own server. After storing * a credit card, you can then pass the credit card id instead of the * related credit card details to complete a payment. * * @link https://developer.paypal.com/docs/api/#store-a-credit-card * @param array $parameters * @return \Omnipay\PayPal\Message\RestCreateCardRequest */ public function createCard(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCreateCardRequest', $parameters); } /** * Delete a credit card from the vault. * * Updating a card in the vault is no longer supported -- see * http://stackoverflow.com/questions/20858910/paypal-rest-api-update-a-stored-credit-card * Therefore the only way to update a card is to remove it using deleteCard and * then re-add it using createCard. * * @link https://developer.paypal.com/docs/api/#delete-a-stored-credit-card * @param array $parameters * @return \Omnipay\PayPal\Message\RestDeleteCardRequest */ public function deleteCard(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestDeleteCardRequest', $parameters); } // // Billing Plans and Agreements -- Set up recurring payments. // @link https://developer.paypal.com/docs/api/#billing-plans-and-agreements // /** * Create a billing plan. * * You can create an empty billing plan and add a trial period and/or regular * billing. Alternatively, you can create a fully loaded plan that includes * both a trial period and regular billing. Note: By default, a created billing * plan is in a CREATED state. A user cannot subscribe to the billing plan * unless it has been set to the ACTIVE state. * * @link https://developer.paypal.com/docs/api/#create-a-plan * @param array $parameters * @return \Omnipay\PayPal\Message\RestCreatePlanRequest */ public function createPlan(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCreatePlanRequest', $parameters); } /** * Update a billing plan. * * You can update the information for an existing billing plan. The state of a plan * must be active before a billing agreement is created. * * @link https://developer.paypal.com/docs/api/#update-a-plan * @param array $parameters * @return \Omnipay\PayPal\Message\RestUpdatePlanRequest */ public function updatePlan(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestUpdatePlanRequest', $parameters); } // TODO: Retrieve a plan /** * List billing plans. * * Use this call to get a list of plans in any state (CREATED, ACTIVE, etc.). * The plans returned are the plans made by the merchant making the call. * * @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list * @param array $parameters * @return \Omnipay\PayPal\Message\RestListPlanRequest */ public function listPlan(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestListPlanRequest', $parameters); } /** * Create a subscription. * * Use this call to create a billing agreement for the buyer. * * @link https://developer.paypal.com/docs/api/#create-an-agreement * @param array $parameters * @return \Omnipay\PayPal\Message\RestCreateSubscriptionRequest */ public function createSubscription(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCreateSubscriptionRequest', $parameters); } /** * Complete (execute) a subscription. * * Use this call to execute an agreement after the buyer approves it. * * @link https://developer.paypal.com/docs/api/#execute-an-agreement * @param array $parameters * @return \Omnipay\PayPal\Message\RestCompleteSubscriptionRequest */ public function completeSubscription(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCompleteSubscriptionRequest', $parameters); } /** * Cancel a subscription. * * Use this call to cancel an agreement. * * @link https://developer.paypal.com/docs/api/#cancel-an-agreement * @param array $parameters * @return \Omnipay\PayPal\Message\RestCancelSubscriptionRequest */ public function cancelSubscription(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestCancelSubscriptionRequest', $parameters); } /** * Suspend a subscription. * * Use this call to suspend an agreement. * * @link https://developer.paypal.com/docs/api/#suspend-an-agreement * @param array $parameters * @return \Omnipay\PayPal\Message\RestSuspendSubscriptionRequest */ public function suspendSubscription(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestSuspendSubscriptionRequest', $parameters); } /** * Reactivate a suspended subscription. * * Use this call to reactivate or un-suspend an agreement. * * @link https://developer.paypal.com/docs/api/#reactivate-an-agreement * @param array $parameters * @return \Omnipay\PayPal\Message\RestReactivateSubscriptionRequest */ public function reactivateSubscription(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestReactivateSubscriptionRequest', $parameters); } /** * Search for transactions. * * Use this call to search for the transactions within a billing agreement. * Note that this is not a generic transaction search function -- for that * see RestListPurchaseRequest. It only searches for transactions within * a billing agreement. * * This should be used on a regular basis to determine the success / failure * state of transactions on active billing agreements. * * @link https://developer.paypal.com/docs/api/#search-for-transactions * @param array $parameters * @return \Omnipay\PayPal\Message\RestCompleteSubscriptionRequest */ public function searchTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\RestSearchTransactionRequest', $parameters); } // TODO: Update an agreement // TODO: Retrieve an agreement // TODO: Set outstanding agreement amounts // TODO: Bill outstanding agreement amounts } paypal/src/Message/ExpressVoidRequest.php 0000666 00000000606 15165413756 0014565 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Void Request */ class ExpressVoidRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); $data = $this->getBaseData(); $data['METHOD'] = 'DoVoid'; $data['AUTHORIZATIONID'] = $this->getTransactionReference(); return $data; } } paypal/src/Message/RestDeleteCardRequest.php 0000666 00000003433 15165413756 0015145 0 ustar 00 <?php /** * PayPal REST Delete Card Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Delete Card Request * * PayPal offers merchants a /vault API to store sensitive details * like credit card related details. * * You can currently use the /vault API to store credit card details * with PayPal instead of storing them on your own server. After storing * a credit card, you can then pass the credit card id instead of the * related credit card details to complete a payment. * * Direct credit card payment and related features are restricted in * some countries. * As of January 2015 these transactions are only supported in the UK * and in the USA. * * Example. This example assumes that the card has already been created * using a RestCreateCardRequest call and that the card ID has been stored * in $card_id. See RestCreateCardRequest for the details of the first * part of this process. * * <code> * $transaction = $gateway->deleteCard(); * $transaction->setCardReference($card_id); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Gateway deleteCard was successful.\n"; * } else { * echo "Gateway deleteCard failed.\n"; * } * </code> * * @link https://developer.paypal.com/docs/api/#vault * @link https://developer.paypal.com/docs/api/#delete-a-stored-credit-card * @link http://bit.ly/1wUQ33R * @see RestCreateCardRequest */ class RestDeleteCardRequest extends AbstractRestRequest { public function getHttpMethod() { return 'DELETE'; } public function getData() { $this->validate('cardReference'); return array(); } public function getEndpoint() { return parent::getEndpoint() . '/vault/credit-cards/' . $this->getCardReference(); } } paypal/src/Message/RestListPlanRequest.php 0000666 00000013050 15165413756 0014673 0 ustar 00 <?php /** * PayPal REST List Plans Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST List Plans Request * * Use this call to get a list of plans in any state (CREATED, ACTIVE, etc.). * The plans returned are the plans made by the merchant making the call. * * * ### Example * * #### Initialize Gateway * * <code> * // Create a gateway for the PayPal RestGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * </code> * * #### List all plans that have state CREATED * <code> * * // List all billing plans * $transaction = $gateway->listPlan([ * 'state' => CREATED, * ]); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway listPlan response data == " . print_r($data, true) . "\n"; * </code> * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=3&status=ACTIVE&page=1\ * -H "Content-Type:application/json" \ * -H "Authorization: Bearer Access-Token" * </code> * * ### Response Sample * * This is from the PayPal web site: * * <code> * { * "total_items": "166", * "total_pages": "83", * "plans": [ * { * "id": "P-7DC96732KA7763723UOPKETA", * "state": "ACTIVE", * "name": "Plan with Regular and Trial Payment Definitions", * "description": "Plan with regular and trial billing payment definitions.", * "type": "FIXED", * "create_time": "2017-08-22T04:41:52.836Z", * "update_time": "2017-08-22T04:41:53.169Z", * "links": [ * { * "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA", * "rel": "self", * "method": "GET" * } * ] * }, * { * "id": "P-1TV69435N82273154UPWDU4I", * "state": "ACTIVE", * "name": "Plan with Regular Payment Definition", * "description": "Plan with one regular payment definition, minimal merchant preferences, and no shipping fee", * "type": "INFINITE", * "create_time": "2017-08-22T04:41:55.623Z", * "update_time": "2017-08-22T04:41:56.055Z", * "links": [ * { * "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-1TV69435N82273154UPWDU4I", * "rel": "self", * "method": "GET" * } * ] * } * ], * "links": [ * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=1&start=3&status=active", * "rel": "start", * "method": "GET" * }, * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=0&status=active", * "rel": "previous_page", * "method": "GET" * }, * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=2&status=active", * "rel": "next_page", * "method": "GET" * }, * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=82&status=active", * "rel": "last", * "method": "GET" * } * ] * } * * </code> * * @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list */ class RestListPlanRequest extends AbstractRestRequest { /** * * Get the request page * * @return integer */ public function getPage() { return $this->getParameter('page'); } /** * Set the request page * * @param integer $value * @return AbstractRestRequest provides a fluent interface. */ public function setPage($value) { return $this->setParameter('page', $value); } /** * Get the request status * * @return string */ public function getStatus() { return $this->getParameter('status'); } /** * Set the request status * * @param string $value * @return AbstractRestRequest provides a fluent interface. */ public function setStatus($value) { return $this->setParameter('status', $value); } /** * Get the request page size * * @return string */ public function getPageSize() { return $this->getParameter('pageSize'); } /** * Set the request page size * * @param string $value * @return AbstractRestRequest provides a fluent interface. */ public function setPageSize($value) { return $this->setParameter('pageSize', $value); } /** * Get the request total required * * @return string */ public function getTotalRequired() { return $this->getParameter('totalRequired'); } /** * Set the request total required * * @param string $value * @return AbstractRestRequest provides a fluent interface. */ public function setTotalRequired($value) { return $this->setParameter('totalRequired', $value); } public function getData() { return array( 'page' => $this->getPage(), 'status' => $this->getStatus(), 'page_size' => $this->getPageSize(), 'total_required' => $this->getTotalRequired() ); } /** * Get HTTP Method. * * The HTTP method for list plans requests must be GET. * * @return string */ protected function getHttpMethod() { return 'GET'; } public function getEndpoint() { return parent::getEndpoint() . '/payments/billing-plans'; } } paypal/src/Message/RestRefundRequest.php 0000666 00000004552 15165413756 0014377 0 ustar 00 <?php /** * PayPal REST Refund Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Refund Request * * To get details about completed payments (sale transaction) created by a payment request * or to refund a direct sale transaction, PayPal provides the /sale resource and related * sub-resources. * * TODO: There might be a problem here, in that refunding a capture requires a different URL. * * TODO: Yes I know. The gateway doesn't yet support looking up or refunding captured * transactions. That will require adding additional message classes because the URLs * are all different. * * A non-zero amount can be provided for the refund using setAmount(), if this is not * provided (or is zero) then a full refund is made. * * Example -- note this example assumes that the purchase has been successful * and that the transaction ID returned from the purchase is held in $sale_id. * See RestPurchaseRequest for the first part of this example transaction: * * <code> * $transaction = $gateway->refund(array( * 'amount' => '10.00', * 'currency' => 'AUD', * )); * $transaction->setTransactionReference($sale_id); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Refund transaction was successful!\n"; * $data = $response->getData(); * echo "Gateway refund response data == " . print_r($data, true) . "\n"; * } * </code> * * ### Known Issues * * PayPal subscription payments cannot be refunded. PayPal is working on this functionality * for their future API release. In order to refund a PayPal subscription payment, you will * need to use the PayPal web interface to refund it manually. * * @see RestPurchaseRequest */ class RestRefundRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference'); if ($this->getAmount() > 0) { return array( 'amount' => array( 'currency' => $this->getCurrency(), 'total' => $this->getAmount(), ), 'description' => $this->getDescription(), ); } else { return new \stdClass(); } } public function getEndpoint() { return parent::getEndpoint() . '/payments/sale/' . $this->getTransactionReference() . '/refund'; } } paypal/src/Message/RestListPurchaseRequest.php 0000666 00000020334 15165413756 0015556 0 ustar 00 <?php /** * PayPal REST List Purchase Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST List Purchase Request * * Use this call to get a list of payments in any state (created, approved, * failed, etc.). The payments returned are the payments made to the merchant * making the call. * * ### Example * * See RestPurchaseRequest for the first part of this example transaction: * * <code> * // Make some DateTimes for start and end times * $start_time = new \DateTime('yesterday'); * $end_time = new \DateTime('now'); * * // List the transaction so that details can be found for refund, etc. * $transaction = $gateway->listPurchase( * 'startTime' => $start_time, * 'endTime => $end_time * ); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway listPurchase response data == " . print_r($data, true) . "\n"; * </code> * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment? * sort_order=asc&sort_by=update_time \ * -H "Content-Type:application/json" \ * -H "Authorization: Bearer <Access-Token>" * </code> * * ### Response Sample * * This is from the PayPal web site: * * <code> * { * "payments": [ * { * "id": "PAY-4D099447DD202993VKEFMRJQ", * "create_time": "2013-01-31T19:40:22Z", * "update_time": "2013-01-31T19:40:24Z", * "state": "approved", * "intent": "sale", * "payer": { * "payment_method": "credit_card", * "funding_instruments": [ * { * "credit_card": { * "type": "visa", * "number": "xxxxxxxxxxxx0331", * "expire_month": "10", * "expire_year": "2018", * "first_name": "Betsy", * "last_name": "Buyer", * "billing_address": { * "line1": "111 First Street", * "city": "Saratoga", * "state": "CA", * "postal_code": "95070", * "country_code": "US" * } * } * } * ] * }, * "transactions": [ * { * "amount": { * "total": "110.54", * "currency": "USD" * }, * "description": "This is the payment transaction description.", * "related_resources": [ * { * "sale": { * "id": "1D971400A7097562W", * "create_time": "2013-01-31T19:40:23Z", * "update_time": "2013-01-31T19:40:25Z", * "state": "completed", * "amount": { * "total": "110.54", * "currency": "USD" * }, * "parent_payment": "PAY-4D099447DD202993VKEFMRJQ", * "links": [ * { * "href": * "https://api.sandbox.paypal.com/v1/payments/sale/1D971400A7097562W", * "rel": "self", * "method": "GET" * }, * { * "href": * "https://api.sandbox.paypal.com/v1/payments/sale/1D971400A7097562W/refund", * "rel": "refund", * "method": "POST" * }, * { * "href": * "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4D099447DD202993VKEFMRJQ", * "rel": "parent_payment", * "method": "GET" * } * ] * } * } * ] * } * ], * "links": [ * { * "href": * "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4D099447DD202993VKEFMRJQ", * "rel": "self", * "method": "GET" * } * ] * } * ] * } * </code> * * @see RestPurchaseRequest * @link https://developer.paypal.com/docs/api/#list-payment-resources */ class RestListPurchaseRequest extends AbstractRestRequest { /** * Get the request count * * @return integer */ public function getCount() { return $this->getParameter('count'); } /** * Set the request count * * @param integer $value * @return AbstractRestRequest provides a fluent interface. */ public function setCount($value) { return $this->setParameter('count', $value); } /** * Get the request startId * * @return string */ public function getStartId() { return $this->getParameter('startId'); } /** * Set the request startId * * @param string $value * @return AbstractRestRequest provides a fluent interface. */ public function setStartId($value) { return $this->setParameter('startId', $value); } /** * Get the request startIndex * * @return integer */ public function getStartIndex() { return $this->getParameter('startIndex'); } /** * Set the request startIndex * * @param integer $value * @return AbstractRestRequest provides a fluent interface. */ public function setStartIndex($value) { return $this->setParameter('startIndex', $value); } /** * Get the request startTime * * @return string */ public function getStartTime() { return $this->getParameter('startTime'); } /** * Set the request startTime * * @param string|\DateTime $value * @return AbstractRestRequest provides a fluent interface. */ public function setStartTime($value) { if ($value instanceof \DateTime) { $value->setTimezone(new \DateTimeZone('UTC')); $value = $value->format('Y-m-d\TH:i:s\Z'); } return $this->setParameter('startTime', $value); } /** * Get the request endTime * * @return string */ public function getEndTime() { return $this->getParameter('endTime'); } /** * Set the request endTime * * @param string|\DateTime $value * @return AbstractRestRequest provides a fluent interface. */ public function setEndTime($value) { if ($value instanceof \DateTime) { $value->setTimezone(new \DateTimeZone('UTC')); $value = $value->format('Y-m-d\TH:i:s\Z'); } return $this->setParameter('endTime', $value); } public function getData() { return array( 'count' => $this->getCount(), 'start_id' => $this->getStartId(), 'start_index' => $this->getStartIndex(), 'start_time' => $this->getStartTime(), 'end_time' => $this->getEndTime(), ); } /** * Get HTTP Method. * * The HTTP method for listPurchase requests must be GET. * * @return string */ protected function getHttpMethod() { return 'GET'; } public function getEndpoint() { return parent::getEndpoint() . '/payments/payment'; } } paypal/src/Message/ExpressCompleteOrderRequest.php 0000666 00000000510 15165413756 0016422 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Complete Order Request */ class ExpressCompleteOrderRequest extends ExpressCompleteAuthorizeRequest { public function getData() { $data = parent::getData(); $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Order'; return $data; } } paypal/src/Message/RefundRequest.php 0000666 00000001162 15165413756 0013533 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Refund Request */ class RefundRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); $data = $this->getBaseData(); $data['METHOD'] = 'RefundTransaction'; $data['TRANSACTIONID'] = $this->getTransactionReference(); $data['REFUNDTYPE'] = 'Full'; if ($this->getAmount() > 0) { $data['REFUNDTYPE'] = 'Partial'; $data['AMT'] = $this->getAmount(); $data['CURRENCYCODE'] = $this->getCurrency(); } return $data; } } paypal/src/Message/RestSearchTransactionRequest.php 0000666 00000012726 15165413756 0016571 0 ustar 00 <?php /** * PayPal REST Search Transaction Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Search Transaction Request * * Use this call to search for the transactions within a billing agreement. * Note that this is not a generic transaction search function -- for that * see RestListPurchaseRequest. It only searches for transactions within * a billing agreement. * * This should be used on a regular basis to determine the success / failure * state of transactions on active billing agreements. * * ### Example * * <code> * // List the transactions for a billing agreement. * $transaction = $gateway->listPurchase(); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway listPurchase response data == " . print_r($data, true) . "\n"; * </code> * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v GET https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/transactions \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' * </code> * * ### Response Sample * * This is from the PayPal web site: * * <code> * { * "agreement_transaction_list": [ * { * "transaction_id": "I-0LN988D3JACS", * "status": "Created", * "transaction_type": "Recurring Payment", * "payer_email": "bbuyer@example.com", * "payer_name": "Betsy Buyer", * "time_stamp": "2014-06-09T09:29:36Z", * "time_zone": "GMT" * }, * { * "transaction_id": "928415314Y5640008", * "status": "Completed", * "transaction_type": "Recurring Payment", * "amount": { * "currency": "USD", * "value": "1.00" * }, * "fee_amount": { * "currency": "USD", * "value": "-0.33" * }, * "net_amount": { * "currency": "USD", * "value": "0.67" * }, * "payer_email": "bbuyer@example.com", * "payer_name": "Betsy Buyer", * "time_stamp": "2014-06-09T09:42:47Z", * "time_zone": "GMT" * }, * { * "transaction_id": "I-0LN988D3JACS", * "status": "Suspended", * "transaction_type": "Recurring Payment", * "payer_email": "bbuyer@example.com", * "payer_name": "Betsy Buyer", * "time_stamp": "2014-06-09T11:18:34Z", * "time_zone": "GMT" * }, * { * "transaction_id": "I-0LN988D3JACS", * "status": "Reactivated", * "transaction_type": "Recurring Payment", * "payer_email": "bbuyer@example.com", * "payer_name": "Betsy Buyer", * "time_stamp": "2014-06-09T11:18:48Z", * "time_zone": "GMT" * } * ] * } * </code> * * ### Known Issues * * PayPal subscription payments cannot be refunded. PayPal is working on this functionality * for their future API release. In order to refund a PayPal subscription payment, you will * need to use the PayPal web interface to refund it manually. * * @see RestCreateSubscriptionRequest * @link https://developer.paypal.com/docs/api/#search-for-transactions */ class RestSearchTransactionRequest extends AbstractRestRequest { /** * Get the agreement ID * * @return string */ public function getAgreementId() { return $this->getParameter('agreementId'); } /** * Set the agreement ID * * @param string $value * @return RestSearchTransactionRequest provides a fluent interface. */ public function setAgreementId($value) { return $this->setParameter('agreementId', $value); } /** * Get the request startDate * * @return string */ public function getStartDate() { return $this->getParameter('startDate'); } /** * Set the request startDate * * @param string|DateTime $value * @return RestSearchTransactionRequest provides a fluent interface. */ public function setStartDate($value) { return $this->setParameter('startDate', is_string($value) ? new \DateTime($value) : $value); } /** * Get the request endDate * * @return string */ public function getEndDate() { return $this->getParameter('endDate'); } /** * Set the request endDate * * @param string|DateTime $value * @return RestSearchTransactionRequest provides a fluent interface. */ public function setEndDate($value) { return $this->setParameter('endDate', is_string($value) ? new \DateTime($value) : $value); } public function getData() { $this->validate('agreementId', 'startDate', 'endDate'); return array( 'start_date' => $this->getStartDate()->format('Y-m-d'), 'end_date' => $this->getEndDate()->format('Y-m-d'), ); } /** * Get HTTP Method. * * The HTTP method for searchTransaction requests must be GET. * * @return string */ protected function getHttpMethod() { return 'GET'; } public function getEndpoint() { return parent::getEndpoint() . '/payments/billing-agreements/' . $this->getAgreementId() . '/transactions'; } } paypal/src/Message/ExpressAuthorizeResponse.php 0000666 00000002701 15165413756 0016002 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\Message\RedirectResponseInterface; /** * PayPal Express Authorize Response */ class ExpressAuthorizeResponse extends Response implements RedirectResponseInterface { protected $liveCheckoutEndpoint = 'https://www.paypal.com/cgi-bin/webscr'; protected $testCheckoutEndpoint = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; public function isSuccessful() { return false; } public function isRedirect() { return isset($this->data['ACK']) && in_array($this->data['ACK'], array('Success', 'SuccessWithWarning')); } public function getRedirectUrl() { return $this->getCheckoutEndpoint().'?'.http_build_query($this->getRedirectQueryParameters(), '', '&'); } public function getTransactionReference() { return isset($this->data['TOKEN']) ? $this->data['TOKEN'] : null; } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return null; } protected function getRedirectQueryParameters() { return array( 'cmd' => '_express-checkout', 'useraction' => 'commit', 'token' => $this->getTransactionReference(), ); } protected function getCheckoutEndpoint() { return $this->getRequest()->getTestMode() ? $this->testCheckoutEndpoint : $this->liveCheckoutEndpoint; } } paypal/src/Message/RestResponse.php 0000666 00000003436 15165413756 0013401 0 ustar 00 <?php /** * PayPal REST Response */ namespace Omnipay\PayPal\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; /** * PayPal REST Response */ class RestResponse extends AbstractResponse { protected $statusCode; public function __construct(RequestInterface $request, $data, $statusCode = 200) { parent::__construct($request, $data); $this->statusCode = $statusCode; } public function isSuccessful() { return empty($this->data['error']) && $this->getCode() < 400; } public function getTransactionReference() { // This is usually correct for payments, authorizations, etc if (!empty($this->data['transactions']) && !empty($this->data['transactions'][0]['related_resources'])) { foreach (array('sale', 'authorization') as $type) { if (!empty($this->data['transactions'][0]['related_resources'][0][$type])) { return $this->data['transactions'][0]['related_resources'][0][$type]['id']; } } } // This is a fallback, but is correct for fetch transaction and possibly others if (!empty($this->data['id'])) { return $this->data['id']; } return null; } public function getMessage() { if (isset($this->data['error_description'])) { return $this->data['error_description']; } if (isset($this->data['message'])) { return $this->data['message']; } return null; } public function getCode() { return $this->statusCode; } public function getCardReference() { if (isset($this->data['id'])) { return $this->data['id']; } } } paypal/src/Message/ExpressAuthorizeRequest.php 0000666 00000015265 15165413756 0015645 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption; use Omnipay\PayPal\Support\InstantUpdateApi\BillingAgreement; /** * PayPal Express Authorize Request */ class ExpressAuthorizeRequest extends AbstractRequest { const DEFAULT_CALLBACK_TIMEOUT = 5; public function setCallback($callback) { return $this->setParameter('callback', $callback); } public function getCallback() { return $this->getParameter('callback'); } public function setCallbackTimeout($callbackTimeout) { return $this->setParameter('callbackTimeout', $callbackTimeout); } public function getCallbackTimeout() { return $this->getParameter('callbackTimeout'); } /** * @param ShippingOption[] $data */ public function setShippingOptions($data) { $this->setParameter('shippingOptions', $data); } /** * @return ShippingOption[] */ public function getShippingOptions() { return $this->getParameter('shippingOptions'); } /** * @param BillingAgreement $data */ public function setBillingAgreement($data) { $this->setParameter('billingAgreement', $data); } /** * @return BillingAgreement */ public function getBillingAgreement() { return $this->getParameter('billingAgreement'); } protected function validateCallback() { $callback = $this->getCallback(); if (!empty($callback)) { $shippingOptions = $this->getShippingOptions(); if (empty($shippingOptions)) { throw new InvalidRequestException( 'When setting a callback for the Instant Update API you must set shipping options' ); } else { $hasDefault = false; foreach ($shippingOptions as $shippingOption) { if ($shippingOption->isDefault()) { $hasDefault = true; continue; } } if (!$hasDefault) { throw new InvalidRequestException( 'One of the supplied shipping options must be set as default' ); } } } } public function getData() { $this->validate('amount', 'returnUrl', 'cancelUrl'); $this->validateCallback(); $data = $this->getBaseData(); $data['METHOD'] = 'SetExpressCheckout'; $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization'; $data['PAYMENTREQUEST_0_AMT'] = $this->getAmount(); $data['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->getCurrency(); $data['PAYMENTREQUEST_0_INVNUM'] = $this->getTransactionId(); $data['PAYMENTREQUEST_0_DESC'] = $this->getDescription(); // pp express specific fields $data['SOLUTIONTYPE'] = $this->getSolutionType(); $data['LANDINGPAGE'] = $this->getLandingPage(); $data['RETURNURL'] = $this->getReturnUrl(); $data['CANCELURL'] = $this->getCancelUrl(); $data['HDRIMG'] = $this->getHeaderImageUrl(); $data['BRANDNAME'] = $this->getBrandName(); $data['NOSHIPPING'] = $this->getNoShipping(); $data['ALLOWNOTE'] = $this->getAllowNote(); $data['ADDROVERRIDE'] = $this->getAddressOverride(); $data['LOGOIMG'] = $this->getLogoImageUrl(); $data['CARTBORDERCOLOR'] = $this->getBorderColor(); $data['LOCALECODE'] = $this->getLocaleCode(); $data['CUSTOMERSERVICENUMBER'] = $this->getCustomerServiceNumber(); $callback = $this->getCallback(); if (!empty($callback)) { $data['CALLBACK'] = $callback; // callback timeout MUST be included and > 0 $timeout = $this->getCallbackTimeout(); $data['CALLBACKTIMEOUT'] = $timeout > 0 ? $timeout : self::DEFAULT_CALLBACK_TIMEOUT; // if you're using a callback you MUST set shipping option(s) $shippingOptions = $this->getShippingOptions(); if (!empty($shippingOptions)) { foreach ($shippingOptions as $index => $shipping) { $data['L_SHIPPINGOPTIONNAME' . $index] = $shipping->getName(); $data['L_SHIPPINGOPTIONAMOUNT' . $index] = number_format($shipping->getAmount(), 2); $data['L_SHIPPINGOPTIONISDEFAULT' . $index] = $shipping->isDefault() ? '1' : '0'; if ($shipping->hasLabel()) { $data['L_SHIPPINGOPTIONLABEL' . $index] = $shipping->getLabel(); } } } } $data['MAXAMT'] = $this->getMaxAmount(); $data['PAYMENTREQUEST_0_TAXAMT'] = $this->getTaxAmount(); $data['PAYMENTREQUEST_0_SHIPPINGAMT'] = $this->getShippingAmount(); $data['PAYMENTREQUEST_0_HANDLINGAMT'] = $this->getHandlingAmount(); $data['PAYMENTREQUEST_0_SHIPDISCAMT'] = $this->getShippingDiscount(); $data['PAYMENTREQUEST_0_INSURANCEAMT'] = $this->getInsuranceAmount(); $data['PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID'] = $this->getSellerPaypalAccountId(); $card = $this->getCard(); if ($card) { $data['PAYMENTREQUEST_0_SHIPTONAME'] = $card->getName(); $data['PAYMENTREQUEST_0_SHIPTOSTREET'] = $card->getAddress1(); $data['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $card->getAddress2(); $data['PAYMENTREQUEST_0_SHIPTOCITY'] = $card->getCity(); $data['PAYMENTREQUEST_0_SHIPTOSTATE'] = $card->getState(); $data['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $card->getCountry(); $data['PAYMENTREQUEST_0_SHIPTOZIP'] = $card->getPostcode(); $data['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $card->getPhone(); $data['EMAIL'] = $card->getEmail(); } $billingAgreement = $this->getBillingAgreement(); if ($billingAgreement) { $data['L_BILLINGTYPE0'] = $billingAgreement->getType(); $data['L_BILLINGAGREEMENTDESCRIPTION0'] = $billingAgreement->getDescription(); if ($billingAgreement->hasPaymentType()) { $data['L_PAYMENTTYPE0'] = $billingAgreement->getPaymentType(); } if ($billingAgreement->hasCustomAnnotation()) { $data['L_BILLINGAGREEMENTCUSTOM0'] = $billingAgreement->getCustomAnnotation(); } } $data = array_merge($data, $this->getItemData()); return $data; } protected function createResponse($data) { return $this->response = new ExpressAuthorizeResponse($this, $data); } } paypal/src/Message/RestFetchPurchaseRequest.php 0000666 00000002643 15165413756 0015677 0 ustar 00 <?php /** * PayPal REST Fetch Purchase Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Fetch Purchase Request * * Use this call to get details about payments that have not completed, such * as payments that are created and approved, or if a payment has failed. * * ### Example * * See RestPurchaseRequest for the first part of this example transaction: * * <code> * // Fetch the transaction so that details can be found for refund, etc. * $transaction = $gateway->fetchPurchase(); * $transaction->setTransactionReference($sale_id); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway fetchTransaction response data == " . print_r($data, true) . "\n"; * </code> * * @see RestPurchaseRequest * @link https://developer.paypal.com/docs/api/#look-up-a-payment-resource */ class RestFetchPurchaseRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference'); return array(); } /** * Get HTTP Method. * * The HTTP method for fetchTransaction requests must be GET. * Using POST results in an error 500 from PayPal. * * @return string */ protected function getHttpMethod() { return 'GET'; } public function getEndpoint() { return parent::getEndpoint() . '/payments/payment/' . $this->getTransactionReference(); } } paypal/src/Message/RestVoidRequest.php 0000666 00000001221 15165413756 0014043 0 ustar 00 <?php /** * PayPal REST Void an authorization */ namespace Omnipay\PayPal\Message; /** * PayPal REST Void an authorization * * Use this call to void a previously authorized payment. * Note: A fully captured authorization cannot be voided. * * @link https://developer.paypal.com/docs/api/#void-an-authorization * @see RestAuthorizeRequest */ class RestVoidRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference'); } public function getEndpoint() { return parent::getEndpoint() . '/payments/authorization/' . $this->getTransactionReference() . '/void'; } } paypal/src/Message/ExpressFetchCheckoutRequest.php 0000666 00000001145 15165413756 0016402 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Fetch Checkout Details Request */ class ExpressFetchCheckoutRequest extends AbstractRequest { public function getData() { $this->validate(); $data = $this->getBaseData(); $data['METHOD'] = 'GetExpressCheckoutDetails'; // token can either be specified directly, or inferred from the GET parameters if ($this->getToken()) { $data['TOKEN'] = $this->getToken(); } else { $data['TOKEN'] = $this->httpRequest->query->get('token'); } return $data; } } paypal/src/Message/FetchTransactionRequest.php 0000666 00000000637 15165413756 0015555 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Fetch Transaction Request */ class FetchTransactionRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); $data = $this->getBaseData(); $data['METHOD'] = 'GetTransactionDetails'; $data['TRANSACTIONID'] = $this->getTransactionReference(); return $data; } } paypal/src/Message/ExpressCompletePurchaseRequest.php 0000666 00000000733 15165413756 0017130 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Complete Purchase Request */ class ExpressCompletePurchaseRequest extends ExpressCompleteAuthorizeRequest { public function getData() { $data = parent::getData(); $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale'; return $data; } protected function createResponse($data) { return $this->response = new ExpressCompletePurchaseResponse($this, $data); } } paypal/src/Message/RestCreateCardRequest.php 0000666 00000007430 15165413756 0015147 0 ustar 00 <?php /** * PayPal REST Create Card Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Create Card Request * * PayPal offers merchants a /vault API to store sensitive details * like credit card related details. * * You can currently use the /vault API to store credit card details * with PayPal instead of storing them on your own server. After storing * a credit card, you can then pass the credit card id instead of the * related credit card details to complete a payment. * * Direct credit card payment and related features are restricted in * some countries. * As of January 2015 these transactions are only supported in the UK * and in the USA. * * Example: * * <code> * // Create a gateway for the PayPal RestGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Create a credit card object * // DO NOT USE THESE CARD VALUES -- substitute your own * // see the documentation in the class header. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'User', * 'number' => '4111111111111111', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a create card transaction on the gateway * $transaction = $gateway->createCard(array( * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Create card transaction was successful!\n"; * // Find the card ID * $card_id = $response->getTransactionReference(); * } * </code> * * @link https://developer.paypal.com/docs/api/#vault * @link https://developer.paypal.com/docs/api/#store-a-credit-card * @link http://bit.ly/1wUQ33R */ class RestCreateCardRequest extends AbstractRestRequest { public function getData() { $this->validate('card'); $this->getCard()->validate(); $data = array( 'number' => $this->getCard()->getNumber(), 'type' => $this->getCard()->getBrand(), 'expire_month' => $this->getCard()->getExpiryMonth(), 'expire_year' => $this->getCard()->getExpiryYear(), 'cvv2' => $this->getCard()->getCvv(), 'first_name' => $this->getCard()->getFirstName(), 'last_name' => $this->getCard()->getLastName(), 'billing_address' => array( 'line1' => $this->getCard()->getAddress1(), //'line2' => $this->getCard()->getAddress2(), 'city' => $this->getCard()->getCity(), 'state' => $this->getCard()->getState(), 'postal_code' => $this->getCard()->getPostcode(), 'country_code' => strtoupper($this->getCard()->getCountry()), ) ); // There's currently a quirk with the REST API that requires line2 to be // non-empty if it's present. Jul 14, 2014 $line2 = $this->getCard()->getAddress2(); if (!empty($line2)) { $data['billing_address']['line2'] = $line2; } return $data; } protected function getEndpoint() { return parent::getEndpoint() . '/vault/credit-cards'; } } paypal/src/Message/RestAuthorizeRequest.php 0000666 00000032607 15165413756 0015130 0 ustar 00 <?php /** * PayPal REST Authorize Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Authorize Request * * To collect payment at a later time, first authorize a payment using the /payment resource. * You can then capture the payment to complete the sale and collect payment. * * This looks exactly like a RestPurchaseRequest object except that the intent is * set to "authorize" (to authorize a payment to be captured later) rather than * "sale" (which is used to capture a payment immediately). * * ### Example * * #### Initialize Gateway * * <code> * // Create a gateway for the PayPal RestGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * </code> * * #### Direct Credit Card Authorize * * This is for the use case where a customer has presented their * credit card details and you intend to use the PayPal REST gateway * for processing a transaction using that credit card data. * * This does not require the customer to have a PayPal account. * * </code> * // Create a credit card object * // DO NOT USE THESE CARD VALUES -- substitute your own * // see the documentation in the class header. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'User', * 'number' => '4111111111111111', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do an authorisation transaction on the gateway * $transaction = $gateway->authorize(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test authorize transaction.', * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Authorize transaction was successful!\n"; * // Find the authorization ID * $auth_id = $response->getTransactionReference(); * } * </code> * * Direct credit card payment and related features are restricted in * some countries. * As of January 2015 these transactions are only supported in the UK * and in the USA. * * #### PayPal Account Authorization * * This is for the use case where the customer intends to pay using their * PayPal account. Note that no credit card details are provided, instead * both a return URL and a cancel URL are required. * * The optimal solution here is to provide a unique return URL and cancel * URL per transaction. That way your code will know what transaction is * being returned or cancelled by PayPal. * * So step 1 is to store some transaction data somewhere on your system so * that you have an ID when your transaction returns. How you do this of * course depends on what framework, database layer, etc, you are using but * for this step let's assume that you have a class set up that can save * a transaction and return the object, and that you can retrieve the ID * of that saved object using some call like getId() on the object. Most * ORMs such as Doctrine ORM, Propel or Eloquent will have some methods * that will allow you to do this or something similar. * * <code> * $transaction = MyClass::saveTransaction($some_data); * $txn_id = $transaction->getId(); * </code> * * Step 2 is to send the purchase request. * * </code> * // Do a purchase transaction on the gateway * try { * $transaction = $gateway->authorize(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test authorize transaction.', * 'returnUrl' => 'http://mysite.com/paypal/return/?txn_id=' . $txn_id, * 'cancelUrl' => 'http://mysite.com/paypal/return/?txn_id=' . $txn_id, * )); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway purchase response data == " . print_r($data, true) . "\n"; * * if ($response->isSuccessful()) { * echo "Step 2 was successful!\n"; * } * * } catch (\Exception $e) { * echo "Exception caught while attempting authorize.\n"; * echo "Exception type == " . get_class($e) . "\n"; * echo "Message == " . $e->getMessage() . "\n"; * } * </code> * * Step 3 is where your code needs to redirect the customer to the PayPal * gateway so that the customer can sign in to their PayPal account and * agree to authorize the payment. The response will implement an interface * called RedirectResponseInterface from which the redirect URL can be obtained. * * How you do this redirect is up to your platform, code or framework at * this point. For the below example I will assume that there is a * function called redirectTo() which can handle it for you. * * </code> * if ($response->isRedirect()) { * // Redirect the customer to PayPal so that they can sign in and * // authorize the payment. * echo "The transaction is a redirect"; * redirectTo($response->getRedirectUrl()); * } * </code> * * Step 4 is where the customer returns to your site. This will happen on * either the returnUrl or the cancelUrl, that you provided in the purchase() * call. * * If the cancelUrl is called then you can assume that the customer has not * authorized the payment, therefore you can cancel the transaction. * * If the returnUrl is called, then you need to complete the transaction via * a further call to PayPal. * * Note this example assumes that the authorize has been successful. * * The payer ID and the payment ID returned from the callback after the authorize * will be passed to the return URL as GET parameters payerId and paymentId * respectively. * * <code> * $paymentId = $_GET['paymentId']; * $payerId = $_GET['payerId']; * * // Once the transaction has been approved, we need to complete it. * $transaction = $gateway->completePurchase(array( * 'payer_id' => $payer_id, * 'transactionReference' => $sale_id, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * // The customer has successfully paid. * echo "Step 4 was successful!\n"; * } else { * // There was an error returned by completePurchase(). You should * // check the error code and message from PayPal, which may be something * // like "card declined", etc. * } * </code> * * #### Note on Handling Error Messages * * PayPal account payments are a 2 step process. Firstly the customer needs to * authorize the payment from PayPal to your application. Secondly, assuming that * the customer does not have enough balance to pay the invoice from their PayPal * balance, PayPal needs to transfer the funds from the customer's credit card to * their PayPal account. This transaction is between PayPal and the customer, and * not between the customer and you. * * If the second transaction fails then a call to completePurchase() will return * an error. However this error message will be fairly generic. For privacy * reasons, PayPal will not disclose to the merchant the full reason for the * failure, they will only disclose this to the customer. * * Therefore on a failed completeAuthorize() call you could display an error message * like this one: * * "PayPal failed to process the transaction from your card. For privacy reasons, * PayPal are unable to disclose to us the reason for this failure. You should try * a different payment method, a different card within PayPal, or contact PayPal * support if you need to understand the reason for the failed transaction. PayPal * may advise you to use a different card if the particular card is rejected * by the card issuer." * * @link https://developer.paypal.com/docs/integration/direct/capture-payment/#authorize-the-payment * @link https://developer.paypal.com/docs/api/#authorizations * @link http://bit.ly/1wUQ33R * @see RestCaptureRequest * @see RestPurchaseRequest */ class RestAuthorizeRequest extends AbstractRestRequest { public function getData() { $data = array( 'intent' => 'authorize', 'payer' => array( 'payment_method' => 'credit_card', 'funding_instruments' => array() ), 'transactions' => array( array( 'description' => $this->getDescription(), 'amount' => array( 'total' => $this->getAmount(), 'currency' => $this->getCurrency(), ), 'invoice_number' => $this->getTransactionId() ) ), 'experience_profile_id' => $this->getExperienceProfileId() ); $items = $this->getItems(); if ($items) { $itemList = array(); foreach ($items as $n => $item) { $itemList[] = array( 'name' => $item->getName(), 'description' => $item->getDescription(), 'quantity' => $item->getQuantity(), 'price' => $this->formatCurrency($item->getPrice()), 'currency' => $this->getCurrency() ); } $data['transactions'][0]['item_list']["items"] = $itemList; } if ($this->getCardReference()) { $this->validate('amount'); $data['payer']['funding_instruments'][] = array( 'credit_card_token' => array( 'credit_card_id' => $this->getCardReference(), ), ); } elseif ($this->getCard()) { $this->validate('amount', 'card'); $this->getCard()->validate(); $data['payer']['funding_instruments'][] = array( 'credit_card' => array( 'number' => $this->getCard()->getNumber(), 'type' => $this->getCard()->getBrand(), 'expire_month' => $this->getCard()->getExpiryMonth(), 'expire_year' => $this->getCard()->getExpiryYear(), 'cvv2' => $this->getCard()->getCvv(), 'first_name' => $this->getCard()->getFirstName(), 'last_name' => $this->getCard()->getLastName(), 'billing_address' => array( 'line1' => $this->getCard()->getAddress1(), //'line2' => $this->getCard()->getAddress2(), 'city' => $this->getCard()->getCity(), 'state' => $this->getCard()->getState(), 'postal_code' => $this->getCard()->getPostcode(), 'country_code' => strtoupper($this->getCard()->getCountry()), ) ) ); // There's currently a quirk with the REST API that requires line2 to be // non-empty if it's present. Jul 14, 2014 $line2 = $this->getCard()->getAddress2(); if (!empty($line2)) { $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line2'] = $line2; } } else { $this->validate('amount', 'returnUrl', 'cancelUrl'); unset($data['payer']['funding_instruments']); $data['payer']['payment_method'] = 'paypal'; $data['redirect_urls'] = array( 'return_url' => $this->getReturnUrl(), 'cancel_url' => $this->getCancelUrl(), ); } return $data; } /** * Get the experience profile id * * @return string */ public function getExperienceProfileId() { return $this->getParameter('experienceProfileId'); } /** * Set the experience profile id * * @param string $value * @return RestAuthorizeRequest provides a fluent interface. */ public function setExperienceProfileId($value) { return $this->setParameter('experienceProfileId', $value); } /** * Get transaction description. * * The REST API does not currently have support for passing an invoice number * or transaction ID. * * @return string */ public function getDescription() { $id = $this->getTransactionId(); $desc = parent::getDescription(); if (empty($id)) { return $desc; } elseif (empty($desc)) { return $id; } else { return "$id : $desc"; } } /** * Get transaction endpoint. * * Authorization of payments is done using the /payment resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/payment'; } protected function createResponse($data, $statusCode) { return $this->response = new RestAuthorizeResponse($this, $data, $statusCode); } } paypal/src/Message/ExpressInContextAuthorizeRequest.php 0000666 00000000473 15165413756 0017474 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express In-Context Authorize Request */ class ExpressInContextAuthorizeRequest extends ExpressAuthorizeRequest { protected function createResponse($data) { return $this->response = new ExpressInContextAuthorizeResponse($this, $data); } } paypal/src/Message/RestCreateSubscriptionRequest.php 0000666 00000034576 15165413756 0016775 0 ustar 00 <?php /** * PayPal REST Create Subscription Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Create Subscription Request * * Use this call to create a billing agreement for the buyer. The response * for this call includes these HATEOAS links: an approval_url link and an * execute link. Each returned link includes the token for the agreement. * * For PayPal payments: * * * After successfully creating the agreement, direct the user to the * approval_url on the PayPal site so that the user can approve the agreement. * * Call the execute link to execute the billing agreement. * * Note: Billing agreements for credit card payments execute automatically * when created. There is no need for the user to approve the agreement or * to execute the agreement. * * ### Request Data * * Pass the agreement details in the body of a POST call, including the * following agreement object properties: * * * name (string). Required. * * description (string). Required. * * start_date (string). Format yyyy-MM-dd z, as defined in ISO8601. Required. * * agreement_details (array) * * payer (array). Required * * shipping_address (array). Should be provided if it is different to the * default address. * * override_merchant_preferences (array). * * override_charge_models (array). * * plan (array). Required. * * ### Example * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Do a create plan transaction on the gateway * $transaction = $gateway->createPlan(array( * 'name' => 'Test Plan', * 'description' => 'A plan created for testing', * 'type' => $gateway::BILLING_PLAN_TYPE_FIXED, * 'paymentDefinitions' => [ * [ * 'name' => 'Monthly Payments for 12 months', * 'type' => $gateway::PAYMENT_TRIAL, * 'frequency' => $gateway::BILLING_PLAN_FREQUENCY_MONTH, * 'frequency_interval' => 1, * 'cycles' => 12, * 'amount' => ['value' => 10.00, 'currency' => 'USD'], * ], * ], * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Create Plan transaction was successful!\n"; * $plan_id = $response->getTransactionReference(); * echo "Plan reference = " . $plan_id . "\n"; * } * * // Do a create subscription transaction on the gateway * $transaction = $gateway->createSubscription(array( * 'name' => 'Test Subscription', * 'description' => 'A subscription created for testing', * 'startDate' => new \DateTime(), // now * 'planId' => $plan_id, * 'payerDetails => ['payment_method' => 'paypal'], * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Create Subscription transaction was successful!\n"; * if ($response->isRedirect()) { * echo "Response is a redirect\n"; * echo "Redirect URL = " . $response->getRedirectUrl(); * $subscription_id = $response->getTransactionReference(); * echo "Subscription reference = " . $subscription_id; * } * } * </code> * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-agreements \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' \ * -d '{ * "name": "T-Shirt of the Month Club Agreement", * "description": "Agreement for T-Shirt of the Month Club Plan", * "start_date": "2015-02-19T00:37:04Z", * "plan": { * "id": "P-94458432VR012762KRWBZEUA" * }, * "payer": { * "payment_method": "paypal" * }, * "shipping_address": { * "line1": "111 First Street", * "city": "Saratoga", * "state": "CA", * "postal_code": "95070", * "country_code": "US" * } * }' * }' * </code> * * ### Response Sample * * This is from the PayPal web site: * * <code> * { * "name": "T-Shirt of the Month Club Agreement", * "description": "Agreement for T-Shirt of the Month Club Plan", * "plan": { * "id": "P-94458432VR012762KRWBZEUA", * "state": "ACTIVE", * "name": "T-Shirt of the Month Club Plan", * "description": "Template creation.", * "type": "FIXED", * "payment_definitions": [ * { * "id": "PD-50606817NF8063316RWBZEUA", * "name": "Regular Payments", * "type": "REGULAR", * "frequency": "Month", * "amount": { * "currency": "USD", * "value": "100" * }, * "charge_models": [ * { * "id": "CHM-92S85978TN737850VRWBZEUA", * "type": "TAX", * "amount": { * "currency": "USD", * "value": "12" * } * }, * { * "id": "CHM-55M5618301871492MRWBZEUA", * "type": "SHIPPING", * "amount": { * "currency": "USD", * "value": "10" * } * } * ], * "cycles": "12", * "frequency_interval": "2" * } * ], * "merchant_preferences": { * "setup_fee": { * "currency": "USD", * "value": "1" * }, * "max_fail_attempts": "0", * "return_url": "http://www.return.com", * "cancel_url": "http://www.cancel.com", * "auto_bill_amount": "YES", * "initial_fail_amount_action": "CONTINUE" * } * }, * "links": [ * { * "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-0JP008296V451950C", * "rel": "approval_url", * "method": "REDIRECT" * }, * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-0JP008296V451950C/agreement-execute", * "rel": "execute", * "method": "POST" * } * ], * "start_date": "2015-02-19T00:37:04Z" * } * </code> * * ### Known Issues * * PayPal subscription payments cannot be refunded. PayPal is working on this functionality * for their future API release. In order to refund a PayPal subscription payment, you will * need to use the PayPal web interface to refund it manually. * * @link https://developer.paypal.com/docs/api/#create-an-agreement * @see RestCreatePlanRequest * @see Omnipay\PayPal\RestGateway */ class RestCreateSubscriptionRequest extends AbstractRestRequest { /** * Get the agreement name * * @return string */ public function getName() { return $this->getParameter('name'); } /** * Set the agreement name * * @param string $value * @return RestCreateSubscriptionRequest provides a fluent interface. */ public function setName($value) { return $this->setParameter('name', $value); } /** * Get the plan ID * * @return string */ public function getPlanId() { return $this->getParameter('planId'); } /** * Set the plan ID * * @param string $value * @return RestCreateSubscriptionRequest provides a fluent interface. */ public function setPlanId($value) { return $this->setParameter('planId', $value); } /** * Get the agreement start date * * @return \DateTime */ public function getStartDate() { return $this->getParameter('startDate'); } /** * Set the agreement start date * * @param \DateTime $value * @return RestCreateSubscriptionRequest provides a fluent interface. */ public function setStartDate(\DateTime $value) { return $this->setParameter('startDate', $value); } /** * Get the agreement details * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#agreementdetails-object */ public function getAgreementDetails() { return $this->getParameter('agreementDetails'); } /** * Set the agreement details * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreateSubscriptionRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#agreementdetails-object */ public function setAgreementDetails(array $value) { return $this->setParameter('agreementDetails', $value); } /** * Get the payer details * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#payer-object */ public function getPayerDetails() { return $this->getParameter('payerDetails'); } /** * Set the payer details * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreateSubscriptionRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#payer-object */ public function setPayerDetails(array $value) { return $this->setParameter('payerDetails', $value); } /** * Get the shipping address * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#address-object */ public function getShippingAddress() { return $this->getParameter('shippingAddress'); } /** * Set the shipping address * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreateSubscriptionRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#address-object */ public function setShippingAddress(array $value) { return $this->setParameter('shippingAddress', $value); } /** * Get preferences to override the plan merchant preferences * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#merchantpreferences-object */ public function getMerchantPreferences() { return $this->getParameter('merchantPreferences'); } /** * Set preferences to override the plan merchant preferences * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreateSubscriptionRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#merchantpreferences-object */ public function setMerchantPreferences(array $value) { return $this->setParameter('merchantPreferences', $value); } /** * Get charge model to override the plan charge model * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#overridechargemodel-object */ public function getChargeModel() { return $this->getParameter('chargeModel'); } /** * Set preferences to override the plan merchant preferences * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreateSubscriptionRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#merchantpreferences-object */ public function setChargeModel(array $value) { return $this->setParameter('chargeModel', $value); } public function getData() { $this->validate('name', 'description', 'startDate', 'payerDetails', 'planId'); $data = array( 'name' => $this->getName(), 'description' => $this->getDescription(), 'start_date' => $this->getStartDate()->format('c'), 'agreement_details' => $this->getAgreementDetails(), 'payer' => $this->getPayerDetails(), 'plan' => array( 'id' => $this->getPlanId(), ), 'shipping_address' => $this->getShippingAddress(), 'override_merchant_preferences' => $this->getMerchantPreferences(), 'override_charge_models' => $this->getChargeModel(), ); return $data; } /** * Get transaction endpoint. * * Subscriptions are created using the /billing-agreements resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-agreements'; } protected function createResponse($data, $statusCode) { return $this->response = new RestAuthorizeResponse($this, $data, $statusCode); } } paypal/src/Message/ExpressOrderRequest.php 0000666 00000000457 15165413756 0014743 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Order Request */ class ExpressOrderRequest extends ExpressAuthorizeRequest { public function getData() { $data = parent::getData(); $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Order'; return $data; } } paypal/src/Message/RestReactivateSubscriptionRequest.php 0000666 00000005515 15165413756 0017650 0 ustar 00 <?php /** * PayPal REST Reactivate Subscription Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Reactivate Subscription Request * * Use this call to reactivate an agreement. * * ### Request Data * * Pass the agreement id in the URI of a POST call. Also include a description, * which is the reason for reactivating the subscription. * * ### Example * * To create the agreement, see the code example in RestCreateSubscriptionRequest. * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Do a reactivate subscription transaction on the gateway * $transaction = $gateway->reactivateSubscription(array( * 'transactionReference' => $subscription_id, * 'description' => "Reactivating the agreement.", * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Reactivate Subscription transaction was successful!\n"; * } * </code> * * Note that the subscription_id that you get from calling the response's * getTransactionReference() method at the end of the completeSubscription * call will be different to the one that you got after calling the response's * getTransactionReference() method at the end of the createSubscription * call. The one that you get from completeSubscription is the correct * one to use going forwards (e.g. for cancelling or updating the subscription). * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/re-activate \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' \ * -d '{ * "note": "Reactivating the agreement." * }' * </code> * * @link https://developer.paypal.com/docs/api/#reactivate-an-agreement * @see RestCreateSubscriptionRequest * @see Omnipay\PayPal\RestGateway */ class RestReactivateSubscriptionRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference', 'description'); $data = array( 'note' => $this->getDescription(), ); return $data; } /** * Get transaction endpoint. * * Subscriptions are executed using the /billing-agreements resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-agreements/' . $this->getTransactionReference() . '/re-activate'; } } paypal/src/Message/RestUpdatePlanRequest.php 0000666 00000006233 15165413756 0015207 0 ustar 00 <?php /** * PayPal REST Update Plan Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Update Plan Request * * You can update the information for an existing billing plan. The state * of a plan must be active before a billing agreement is created. * * ### Request Data * * Pass the billing plan id in the URI of a PATCH call, including the replace * operation in the body. Other operations in the patch_request object will * throw validation exceptions. * * ### Example * * To create the billing plan, see the code example in RestCreatePlanRequest. * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Update the billing plan * $transaction = $gateway->updatePlan(array( * 'transactionReference' => $plan_id, * 'state' => $gateway::BILLING_PLAN_STATE_ACTIVE, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Update Plan transaction was successful!\n"; * } * </code> * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v -k -X PATCH 'https://api.sandbox.paypal.com/v1/payments/billing-plans/P-94458432VR012762KRWBZEUA' \ * -H "Content-Type: application/json" \ * -H "Authorization: Bearer <Access-Token>" \ * -d '[ * { * "path": "/", * "value": { * "state": "ACTIVE" * }, * "op": "replace" * } * ]' * </code> * * ### Response * * Returns the HTTP status of 200 if the call is successful. * * @link https://developer.paypal.com/docs/api/#update-a-plan * @see RestCreateSubscriptionRequest * @see Omnipay\PayPal\RestGateway */ class RestUpdatePlanRequest extends AbstractRestRequest { /** * Get the plan state * * @return string */ public function getState() { return $this->getParameter('state'); } /** * Set the plan state * * @param string $value * @return RestUpdatePlanRequest provides a fluent interface. */ public function setState($value) { return $this->setParameter('state', $value); } public function getData() { $this->validate('transactionReference', 'state'); $data = array(array( 'path' => '/', 'value' => array( 'state' => $this->getState(), ), 'op' => 'replace' )); return $data; } /** * Get transaction endpoint. * * Billing plans are managed using the /billing-plans resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-plans/' . $this->getTransactionReference(); } protected function getHttpMethod() { return 'PATCH'; } } paypal/src/Message/CaptureRequest.php 0000666 00000001031 15165413756 0013706 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Capture Request */ class CaptureRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference', 'amount'); $data = $this->getBaseData(); $data['METHOD'] = 'DoCapture'; $data['AMT'] = $this->getAmount(); $data['CURRENCYCODE'] = $this->getCurrency(); $data['AUTHORIZATIONID'] = $this->getTransactionReference(); $data['COMPLETETYPE'] = 'Complete'; return $data; } } paypal/src/Message/Response.php 0000666 00000002217 15165413756 0012537 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; /** * PayPal Response */ class Response extends AbstractResponse { public function __construct(RequestInterface $request, $data) { $this->request = $request; parse_str($data, $this->data); } public function isPending() { return isset($this->data['PAYMENTINFO_0_PAYMENTSTATUS']) && $this->data['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Pending'; } public function isSuccessful() { return isset($this->data['ACK']) && in_array($this->data['ACK'], array('Success', 'SuccessWithWarning')); } public function getTransactionReference() { foreach (array('REFUNDTRANSACTIONID', 'TRANSACTIONID', 'PAYMENTINFO_0_TRANSACTIONID', 'AUTHORIZATIONID') as $key) { if (isset($this->data[$key])) { return $this->data[$key]; } } } public function getMessage() { return isset($this->data['L_LONGMESSAGE0']) ? $this->data['L_LONGMESSAGE0'] : null; } } paypal/src/Message/AbstractRestRequest.php 0000666 00000013475 15165413756 0014723 0 ustar 00 <?php /** * PayPal Abstract REST Request */ namespace Omnipay\PayPal\Message; use Omnipay\Common\Exception\InvalidResponseException; /** * PayPal Abstract REST Request * * This class forms the base class for PayPal REST requests via the PayPal REST APIs. * * A complete REST operation is formed by combining an HTTP method (or “verb”) with * the full URI to the resource you’re addressing. For example, here is the operation * to create a new payment: * * <code> * POST https://api.paypal.com/v1/payments/payment * </code> * * To create a complete request, combine the operation with the appropriate HTTP headers * and any required JSON payload. * * @link https://developer.paypal.com/docs/api/ * @link https://devtools-paypal.com/integrationwizard/ * @link http://paypal.github.io/sdk/ * @see Omnipay\PayPal\RestGateway */ abstract class AbstractRestRequest extends \Omnipay\Common\Message\AbstractRequest { const API_VERSION = 'v1'; /** * Sandbox Endpoint URL * * The PayPal REST APIs are supported in two environments. Use the Sandbox environment * for testing purposes, then move to the live environment for production processing. * When testing, generate an access token with your test credentials to make calls to * the Sandbox URIs. When you’re set to go live, use the live credentials assigned to * your app to generate a new access token to be used with the live URIs. * * @var string URL */ protected $testEndpoint = 'https://api.sandbox.paypal.com'; /** * Live Endpoint URL * * When you’re set to go live, use the live credentials assigned to * your app to generate a new access token to be used with the live URIs. * * @var string URL */ protected $liveEndpoint = 'https://api.paypal.com'; /** * PayPal Payer ID * * @var string PayerID */ protected $payerId = null; public function getClientId() { return $this->getParameter('clientId'); } public function setClientId($value) { return $this->setParameter('clientId', $value); } public function getSecret() { return $this->getParameter('secret'); } public function setSecret($value) { return $this->setParameter('secret', $value); } public function getToken() { return $this->getParameter('token'); } public function setToken($value) { return $this->setParameter('token', $value); } public function getPayerId() { return $this->getParameter('payerId'); } public function setPayerId($value) { return $this->setParameter('payerId', $value); } /** * Get HTTP Method. * * This is nearly always POST but can be over-ridden in sub classes. * * @return string */ protected function getHttpMethod() { return 'POST'; } protected function getEndpoint() { $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; return $base . '/' . self::API_VERSION; } public function sendData($data) { // Guzzle HTTP Client createRequest does funny things when a GET request // has attached data, so don't send the data if the method is GET. if ($this->getHttpMethod() == 'GET') { $requestUrl = $this->getEndpoint() . '?' . http_build_query($data); $body = null; } else { $body = $this->toJSON($data); $requestUrl = $this->getEndpoint(); } // Might be useful to have some debug code here, PayPal especially can be // a bit fussy about data formats and ordering. Perhaps hook to whatever // logging engine is being used. // echo "Data == " . json_encode($data) . "\n"; try { $httpResponse = $this->httpClient->request( $this->getHttpMethod(), $this->getEndpoint(), array( 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->getToken(), 'Content-type' => 'application/json', ), $body ); // Empty response body should be parsed also as and empty array $body = (string) $httpResponse->getBody()->getContents(); $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array(); return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); } catch (\Exception $e) { throw new InvalidResponseException( 'Error communicating with payment gateway: ' . $e->getMessage(), $e->getCode() ); } } /** * Returns object JSON representation required by PayPal. * The PayPal REST API requires the use of JSON_UNESCAPED_SLASHES. * * Adapted from the official PayPal REST API PHP SDK. * (https://github.com/paypal/PayPal-PHP-SDK/blob/master/lib/PayPal/Common/PayPalModel.php) * * @param int $options http://php.net/manual/en/json.constants.php * @return string */ public function toJSON($data, $options = 0) { // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option // Instead we would use the str_replace command for now. // TODO: Replace this code with return json_encode($this->toArray(), $options | 64); once we support PHP >= 5.4 if (version_compare(phpversion(), '5.4.0', '>=') === true) { return json_encode($data, $options | 64); } return str_replace('\\/', '/', json_encode($data, $options)); } protected function createResponse($data, $statusCode) { return $this->response = new RestResponse($this, $data, $statusCode); } } paypal/src/Message/RestCancelSubscriptionRequest.php 0000666 00000005470 15165413756 0016746 0 ustar 00 <?php /** * PayPal REST Cancel Subscription Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Cancel Subscription Request * * Use this call to cancel an agreement after the buyer approves it. * * ### Request Data * * Pass the agreement id in the URI of a POST call. Also include a description, * which is the reason for cancelling the subscription. * * ### Example * * To create the agreement, see the code example in RestCreateSubscriptionRequest. * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Do a cancel subscription transaction on the gateway * $transaction = $gateway->cancelSubscription(array( * 'transactionReference' => $subscription_id, * 'description' => "Cancelling the agreement.", * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Cancel Subscription transaction was successful!\n"; * } * </code> * * Note that the subscription_id that you get from calling the response's * getTransactionReference() method at the end of the completeSubscription * call will be different to the one that you got after calling the response's * getTransactionReference() method at the end of the createSubscription * call. The one that you get from completeSubscription is the correct * one to use going forwards (e.g. for cancelling or updating the subscription). * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/cancel \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' \ * -d '{ * "note": "Canceling the agreement." * }' * </code> * * @link https://developer.paypal.com/docs/api/#cancel-an-agreement * @see RestCreateSubscriptionRequest * @see Omnipay\PayPal\RestGateway */ class RestCancelSubscriptionRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference', 'description'); $data = array( 'note' => $this->getDescription(), ); return $data; } /** * Get transaction endpoint. * * Subscriptions are executed using the /billing-agreements resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-agreements/' . $this->getTransactionReference() . '/cancel'; } } paypal/src/Message/ProAuthorizeRequest.php 0000666 00000003112 15165413756 0014740 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Pro Authorize Request */ class ProAuthorizeRequest extends AbstractRequest { public function getData() { $this->validate('amount', 'card'); $this->getCard()->validate(); $data = $this->getBaseData(); $data['METHOD'] = 'DoDirectPayment'; $data['PAYMENTACTION'] = 'Authorization'; $data['AMT'] = $this->getAmount(); $data['CURRENCYCODE'] = $this->getCurrency(); $data['INVNUM'] = $this->getTransactionId(); $data['DESC'] = $this->getDescription(); // add credit card details $data['ACCT'] = $this->getCard()->getNumber(); $data['CREDITCARDTYPE'] = $this->getCard()->getBrand(); $data['EXPDATE'] = $this->getCard()->getExpiryDate('mY'); $data['STARTDATE'] = $this->getCard()->getStartDate('mY'); $data['CVV2'] = $this->getCard()->getCvv(); $data['ISSUENUMBER'] = $this->getCard()->getIssueNumber(); $data['IPADDRESS'] = $this->getClientIp(); $data['FIRSTNAME'] = $this->getCard()->getFirstName(); $data['LASTNAME'] = $this->getCard()->getLastName(); $data['EMAIL'] = $this->getCard()->getEmail(); $data['STREET'] = $this->getCard()->getAddress1(); $data['STREET2'] = $this->getCard()->getAddress2(); $data['CITY'] = $this->getCard()->getCity(); $data['STATE'] = $this->getCard()->getState(); $data['ZIP'] = $this->getCard()->getPostcode(); $data['COUNTRYCODE'] = strtoupper($this->getCard()->getCountry()); return $data; } } paypal/src/Message/RestFetchTransactionRequest.php 0000666 00000003136 15165413756 0016410 0 ustar 00 <?php /** * PayPal REST Fetch Transaction Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Fetch Transaction Request * * To get details about completed payments (sale transaction) created by a payment request * or to refund a direct sale transaction, PayPal provides the /sale resource and related * sub-resources. * * Example -- note this example assumes that the purchase has been successful * and that the transaction ID returned from the purchase is held in $sale_id. * See RestPurchaseRequest for the first part of this example transaction: * * <code> * // Fetch the transaction so that details can be found for refund, etc. * $transaction = $gateway->fetchTransaction(); * $transaction->setTransactionReference($sale_id); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway fetchTransaction response data == " . print_r($data, true) . "\n"; * </code> * * @see RestPurchaseRequest * @link https://developer.paypal.com/docs/api/#sale-transactions */ class RestFetchTransactionRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference'); return array(); } /** * Get HTTP Method. * * The HTTP method for fetchTransaction requests must be GET. * Using POST results in an error 500 from PayPal. * * @return string */ protected function getHttpMethod() { return 'GET'; } public function getEndpoint() { return parent::getEndpoint() . '/payments/sale/' . $this->getTransactionReference(); } } paypal/src/Message/RestAuthorizeResponse.php 0000666 00000005020 15165413756 0015263 0 ustar 00 <?php /** * PayPal REST Authorize Response */ namespace Omnipay\PayPal\Message; use Omnipay\Common\Message\RedirectResponseInterface; /** * PayPal REST Authorize Response */ class RestAuthorizeResponse extends RestResponse implements RedirectResponseInterface { public function isSuccessful() { return empty($this->data['error']) && $this->getCode() == 201; } public function isRedirect() { return $this->getRedirectUrl() !== null; } public function getRedirectUrl() { if (isset($this->data['links']) && is_array($this->data['links'])) { foreach ($this->data['links'] as $key => $value) { if ($value['rel'] == 'approval_url') { return $value['href']; } } } return null; } /** * Get the URL to complete (execute) the purchase or agreement. * * The URL is embedded in the links section of the purchase or create * subscription request response. * * @return string */ public function getCompleteUrl() { if (isset($this->data['links']) && is_array($this->data['links'])) { foreach ($this->data['links'] as $key => $value) { if ($value['rel'] == 'execute') { return $value['href']; } } } return null; } public function getTransactionReference() { // The transaction reference for a paypal purchase request or for a // paypal create subscription request ends up in the execute URL // in the links section of the response. $completeUrl = $this->getCompleteUrl(); if (empty($completeUrl)) { return parent::getTransactionReference(); } $urlParts = explode('/', $completeUrl); // The last element of the URL should be "execute" $execute = end($urlParts); if (!in_array($execute, array('execute', 'agreement-execute'))) { return parent::getTransactionReference(); } // The penultimate element should be the transaction reference return prev($urlParts); } /** * Get the required redirect method (either GET or POST). * * @return string */ public function getRedirectMethod() { return 'GET'; } /** * Gets the redirect form data array, if the redirect method is POST. * * @return null */ public function getRedirectData() { return null; } } paypal/src/Message/ExpressInContextAuthorizeResponse.php 0000666 00000001020 15165413756 0017627 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express In-Context Authorize Response */ class ExpressInContextAuthorizeResponse extends ExpressAuthorizeResponse { protected $liveCheckoutEndpoint = 'https://www.paypal.com/checkoutnow'; protected $testCheckoutEndpoint = 'https://www.sandbox.paypal.com/checkoutnow'; protected function getRedirectQueryParameters() { return array( 'useraction' => 'commit', 'token' => $this->getTransactionReference(), ); } } paypal/src/Message/RestTokenRequest.php 0000666 00000003045 15165413756 0014230 0 ustar 00 <?php /** * PayPal REST Token Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Token Request * * With each API call, you’ll need to set request headers, including * an OAuth 2.0 access token. Get an access token by using the OAuth * 2.0 client_credentials token grant type with your clientId:secret * as your Basic Auth credentials. * * @link https://developer.paypal.com/docs/integration/direct/make-your-first-call/ * @link https://developer.paypal.com/docs/api/#authentication--headers */ class RestTokenRequest extends AbstractRestRequest { public function getData() { return array('grant_type' => 'client_credentials'); } protected function getEndpoint() { return parent::getEndpoint() . '/oauth2/token'; } public function sendData($data) { $body = $data ? http_build_query($data, '', '&') : null; $httpResponse = $this->httpClient->request( $this->getHttpMethod(), $this->getEndpoint(), array( 'Accept' => 'application/json', 'Authorization' => 'Basic ' . base64_encode("{$this->getClientId()}:{$this->getSecret()}"), ), $body ); // Empty response body should be parsed also as and empty array $body = (string) $httpResponse->getBody()->getContents(); $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array(); return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode()); } } paypal/src/Message/ExpressCompletePurchaseResponse.php 0000666 00000002352 15165413756 0017275 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Complete Payment Response */ class ExpressCompletePurchaseResponse extends ExpressAuthorizeResponse { /* * Is this complete purchase response successful? Will not be successful if it's a redirect response. * * @return bool */ public function isSuccessful() { $success = isset($this->data['ACK']) && in_array($this->data['ACK'], array('Success', 'SuccessWithWarning')); return !$this->isRedirect() && $success; } /** * The complete purchase response can be in error where it wants to have your customer return to paypal. * * @return bool */ public function isRedirect() { return isset($this->data['L_ERRORCODE0']) && in_array($this->data['L_ERRORCODE0'], array('10486')); } /** * The transaction reference obtained from the purchase() call can't be used to refund a purchase. * * @return string */ public function getTransactionReference() { if ($this->isSuccessful() && isset($this->data['PAYMENTINFO_0_TRANSACTIONID'])) { return $this->data['PAYMENTINFO_0_TRANSACTIONID']; } return parent::getTransactionReference(); } } paypal/src/Message/RestPurchaseRequest.php 0000666 00000021661 15165413756 0014726 0 ustar 00 <?php /** * PayPal REST Purchase Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Purchase Request * * PayPal provides various payment related operations using * the /payment resource and related sub-resources. Use payment * for direct credit card payments and PayPal account payments. * You can also use sub-resources to get payment related details. * * Note that a PayPal Purchase Request looks exactly like a PayPal * Authorize request except that the 'intent' is set to 'sale' for * immediate payment. This class takes advantage of that by * extending the RestAuthorizeRequest class and simply over-riding * the getData() function to set the intent to sale. * * ### Example * * #### Initialize Gateway * * <code> * // Create a gateway for the PayPal RestGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * </code> * * #### Direct Credit Card Payment * * This is for the use case where a customer has presented their * credit card details and you intend to use the PayPal REST gateway * for processing a transaction using that credit card data. * * This does not require the customer to have a PayPal account. * * <code> * // Create a credit card object * // DO NOT USE THESE CARD VALUES -- substitute your own * // see the documentation in the class header. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'User', * 'number' => '4111111111111111', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * try { * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test purchase transaction.', * 'card' => $card, * )); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway purchase response data == " . print_r($data, true) . "\n"; * * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * } * } catch (\Exception $e) { * echo "Exception caught while attempting authorize.\n"; * echo "Exception type == " . get_class($e) . "\n"; * echo "Message == " . $e->getMessage() . "\n"; * } * </code> * * Direct credit card payment and related features are restricted in * some countries. * As of January 2015 these transactions are only supported in the UK * and in the USA. * * #### PayPal Account Payment * * This is for the use case where the customer intends to pay using their * PayPal account. Note that no credit card details are provided, instead * both a return URL and a cancel URL are required. * * The optimal solution here is to provide a unique return URL and cancel * URL per transaction. That way your code will know what transaction is * being returned or cancelled by PayPal. * * So step 1 is to store some transaction data somewhere on your system so * that you have an ID when your transaction returns. How you do this of * course depends on what framework, database layer, etc, you are using but * for this step let's assume that you have a class set up that can save * a transaction and return the object, and that you can retrieve the ID * of that saved object using some call like getId() on the object. Most * ORMs such as Doctrine ORM, Propel or Eloquent will have some methods * that will allow you to do this or something similar. * * <code> * $transaction = MyClass::saveTransaction($some_data); * $txn_id = $transaction->getId(); * </code> * * Step 2 is to send the purchase request. * * <code> * // Do a purchase transaction on the gateway * try { * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test purchase transaction.', * 'returnUrl' => 'http://mysite.com/paypal/return/?txn_id=' . $txn_id, * 'cancelUrl' => 'http://mysite.com/paypal/return/?txn_id=' . $txn_id, * )); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway purchase response data == " . print_r($data, true) . "\n"; * * if ($response->isSuccessful()) { * echo "Step 2 was successful!\n"; * } * * } catch (\Exception $e) { * echo "Exception caught while attempting purchase.\n"; * echo "Exception type == " . get_class($e) . "\n"; * echo "Message == " . $e->getMessage() . "\n"; * } * </code> * * Step 3 is where your code needs to redirect the customer to the PayPal * gateway so that the customer can sign in to their PayPal account and * agree to authorize the payment. The response will implement an interface * called RedirectResponseInterface from which the redirect URL can be obtained. * * How you do this redirect is up to your platform, code or framework at * this point. For the below example I will assume that there is a * function called redirectTo() which can handle it for you. * * <code> * if ($response->isRedirect()) { * // Redirect the customer to PayPal so that they can sign in and * // authorize the payment. * echo "The transaction is a redirect"; * redirectTo($response->getRedirectUrl()); * } * </code> * * Step 4 is where the customer returns to your site. This will happen on * either the returnUrl or the cancelUrl, that you provided in the purchase() * call. * * If the cancelUrl is called then you can assume that the customer has not * authorized the payment, therefore you can cancel the transaction. * * If the returnUrl is called, then you need to complete the transaction via * a further call to PayPal. * * Note this example assumes that the purchase has been successful. * * The payer ID and the payment ID returned from the callback after the purchase * will be passed to the return URL as GET parameters payerId and paymentId * respectively. * * <code> * $paymentId = $_GET['paymentId']; * $payerId = $_GET['payerId']; * * // Once the transaction has been approved, we need to complete it. * $transaction = $gateway->completePurchase(array( * 'payer_id' => $payer_id, * 'transactionReference' => $sale_id, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * // The customer has successfully paid. * echo "Step 4 was successful!\n"; * } else { * // There was an error returned by completePurchase(). You should * // check the error code and message from PayPal, which may be something * // like "card declined", etc. * } * </code> * * #### Note on Handling Error Messages * * PayPal account payments are a 2 step process. Firstly the customer needs to * authorize the payment from PayPal to your application. Secondly, assuming that * the customer does not have enough balance to pay the invoice from their PayPal * balance, PayPal needs to transfer the funds from the customer's credit card to * their PayPal account. This transaction is between PayPal and the customer, and * not between the customer and you. * * If the second transaction fails then a call to completePurchase() will return * an error. However this error message will be fairly generic. For privacy * reasons, PayPal will not disclose to the merchant the full reason for the * failure, they will only disclose this to the customer. * * Therefore on a failed completePurchase() call you could display an error message * like this one: * * "PayPal failed to process the transaction from your card. For privacy reasons, * PayPal are unable to disclose to us the reason for this failure. You should try * a different payment method, a different card within PayPal, or contact PayPal * support if you need to understand the reason for the failed transaction. PayPal * may advise you to use a different card if the particular card is rejected * by the card issuer." * * @link https://developer.paypal.com/docs/api/#create-a-payment * @see RestAuthorizeRequest */ class RestPurchaseRequest extends RestAuthorizeRequest { public function getData() { $data = parent::getData(); $data['intent'] = 'sale'; return $data; } } paypal/src/Message/ExpressInContextOrderRequest.php 0000666 00000000514 15165413756 0016571 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express In-Context Order Request */ class ExpressInContextOrderRequest extends ExpressInContextAuthorizeRequest { public function getData() { $data = parent::getData(); $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Order'; return $data; } } paypal/src/Message/RestSuspendSubscriptionRequest.php 0000666 00000005447 15165413756 0017206 0 ustar 00 <?php /** * PayPal REST Suspend Subscription Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Suspend Subscription Request * * Use this call to suspend an agreement. * * ### Request Data * * Pass the agreement id in the URI of a POST call. Also include a description, * which is the reason for suspending the subscription. * * ### Example * * To create the agreement, see the code example in RestCreateSubscriptionRequest. * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Do a suspend subscription transaction on the gateway * $transaction = $gateway->suspendSubscription(array( * 'transactionReference' => $subscription_id, * 'description' => "Suspending the agreement.", * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Suspend Subscription transaction was successful!\n"; * } * </code> * * Note that the subscription_id that you get from calling the response's * getTransactionReference() method at the end of the completeSubscription * call will be different to the one that you got after calling the response's * getTransactionReference() method at the end of the createSubscription * call. The one that you get from completeSubscription is the correct * one to use going forwards (e.g. for cancelling or updating the subscription). * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/suspend \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' \ * -d '{ * "note": "Suspending the agreement." * }' * </code> * * @link https://developer.paypal.com/docs/api/#suspend-an-agreement * @see RestCreateSubscriptionRequest * @see Omnipay\PayPal\RestGateway */ class RestSuspendSubscriptionRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference', 'description'); $data = array( 'note' => $this->getDescription(), ); return $data; } /** * Get transaction endpoint. * * Subscriptions are executed using the /billing-agreements resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-agreements/' . $this->getTransactionReference() . '/suspend'; } } paypal/src/Message/RestCompletePurchaseRequest.php 0000666 00000004177 15165413756 0016422 0 ustar 00 <?php /** * PayPal REST Complete Purchase Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Complete Purchase Request * * Use this message to execute (complete) a PayPal payment that has been * approved by the payer. You can optionally update transaction information * when executing the payment by passing in one or more transactions. * * This call only works after a buyer has approved the payment using the * provided PayPal approval URL. * * ### Example * * The payer ID and the payment ID returned from the callback after the purchase * will be passed to the return URL as GET parameters payerId and paymentId * respectively. * * See RestPurchaseRequest for the first part of this example transaction: * * <code> * $paymentId = $_GET['paymentId']; * $payerId = $_GET['payerId']; * * // Once the transaction has been approved, we need to complete it. * $transaction = $gateway->completePurchase(array( * 'payer_id' => $payerId, * 'transactionReference' => $paymentId, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * // The customer has successfully paid. * } else { * // There was an error returned by completePurchase(). You should * // check the error code and message from PayPal, which may be something * // like "card declined", etc. * } * </code> * * @see RestPurchaseRequest * @link https://developer.paypal.com/docs/api/#execute-an-approved-paypal-payment */ class RestCompletePurchaseRequest extends AbstractRestRequest { /** * Get the raw data array for this message. The format of this varies from gateway to * gateway, but will usually be either an associative array, or a SimpleXMLElement. * * @return mixed */ public function getData() { $this->validate('transactionReference', 'payerId'); $data = array( 'payer_id' => $this->getPayerId() ); return $data; } public function getEndpoint() { return parent::getEndpoint() . '/payments/payment/' . $this->getTransactionReference() . '/execute'; } } paypal/src/Message/ExpressCompleteAuthorizeRequest.php 0000666 00000003175 15165413756 0017333 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Express Complete Authorize Request */ class ExpressCompleteAuthorizeRequest extends AbstractRequest { public function getData() { $this->validate('amount'); $data = $this->getBaseData(); $data['METHOD'] = 'DoExpressCheckoutPayment'; $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization'; $data['PAYMENTREQUEST_0_AMT'] = $this->getAmount(); $data['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->getCurrency(); $data['PAYMENTREQUEST_0_INVNUM'] = $this->getTransactionId(); $data['PAYMENTREQUEST_0_DESC'] = $this->getDescription(); $data['PAYMENTREQUEST_0_NOTIFYURL'] = $this->getNotifyUrl(); $data['MAXAMT'] = $this->getMaxAmount(); $data['PAYMENTREQUEST_0_TAXAMT'] = $this->getTaxAmount(); $data['PAYMENTREQUEST_0_SHIPPINGAMT'] = $this->getShippingAmount(); $data['PAYMENTREQUEST_0_HANDLINGAMT'] = $this->getHandlingAmount(); $data['PAYMENTREQUEST_0_SHIPDISCAMT'] = $this->getShippingDiscount(); $data['PAYMENTREQUEST_0_INSURANCEAMT'] = $this->getInsuranceAmount(); $data['TOKEN'] = $this->getToken() ? $this->getToken() : $this->httpRequest->query->get('token'); $data['PAYERID'] = $this->getPayerID() ? $this->getPayerID() : $this->httpRequest->query->get('PayerID'); $data = array_merge($data, $this->getItemData()); return $data; } public function getPayerID() { return $this->getParameter('payerID'); } public function setPayerID($value) { return $this->setParameter('payerID', $value); } } paypal/src/Message/ExpressTransactionSearchResponse.php 0000666 00000001453 15165413756 0017446 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use Omnipay\Common\Message\RequestInterface; /** * Response for Transaction Search request */ class ExpressTransactionSearchResponse extends Response { public function __construct(RequestInterface $request, $data) { parent::__construct($request, $data); $payments = array(); foreach ($this->data as $key => $value) { if ($this->isSuccessful() && preg_match('/(L_)?(?<key>[A-Za-z]+)(?<n>[0-9]+)/', $key, $matches) ) { $payments[$matches['n']][$matches['key']] = $value; unset($this->data[$key]); } } $this->data['payments'] = $payments; } public function getPayments() { return $this->data['payments']; } } paypal/src/Message/RestCreatePlanRequest.php 0000666 00000023200 15165413756 0015161 0 ustar 00 <?php /** * PayPal REST Create Plan Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Create Plan Request * * PayPal offers merchants a /billing-plans resource for providing billing plans * to users for recurring payments. * * After the billing plan is created, the /billing-agreements resource provides * billing agreements so that users can agree to be billed for the plans. * * You can create an empty billing plan and add a trial period and/or regular * billing. Alternatively, you can create a fully loaded plan that includes both * a trial period and regular billing. Note: By default, a created billing plan * is in a CREATED state. A user cannot subscribe to the billing plan unless it * has been set to the ACTIVE state. * * ### Request Data * * In order to create a new billing plan you must submit the following details: * * * name (string). Required. * * description (string). Required. * * type (string). Allowed values: FIXED, INFINITE. Required. * * payment_definitions (array) * * merchant_preferences (object) * * ### Example * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Do a create plan transaction on the gateway * $transaction = $gateway->createPlan(array( * 'name' => 'Test Plan', * 'description' => 'A plan created for testing', * 'type' => $gateway::BILLING_PLAN_TYPE_FIXED, * 'paymentDefinitions' => [ * [ * 'name' => 'Monthly Payments for 12 months', * 'type' => $gateway::PAYMENT_TRIAL, * 'frequency' => $gateway::BILLING_PLAN_FREQUENCY_MONTH, * 'frequency_interval' => 1, * 'cycles' => 12, * 'amount' => ['value' => 10.00, 'currency' => 'USD'], * ], * ], * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Create Plan transaction was successful!\n"; * $plan_id = $response->getTransactionReference(); * echo "Plan reference = " . $plan_id . "\n"; * } * </code> * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-plans \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' \ * -d '{ * "name": "T-Shirt of the Month Club Plan", * "description": "Template creation.", * "type": "fixed", * "payment_definitions": [ * { * "name": "Regular Payments", * "type": "REGULAR", * "frequency": "MONTH", * "frequency_interval": "2", * "amount": { * "value": "100", * "currency": "USD" * }, * "cycles": "12", * "charge_models": [ * { * "type": "SHIPPING", * "amount": { * "value": "10", * "currency": "USD" * } * }, * { * "type": "TAX", * "amount": { * "value": "12", * "currency": "USD" * } * } * ] * } * ], * "merchant_preferences": { * "setup_fee": { * "value": "1", * "currency": "USD" * }, * "return_url": "http://www.return.com", * "cancel_url": "http://www.cancel.com", * "auto_bill_amount": "YES", * "initial_fail_amount_action": "CONTINUE", * "max_fail_attempts": "0" * } * }' * </code> * * ### Response Sample * * This is from the PayPal web site: * * <code> * { * "id": "P-94458432VR012762KRWBZEUA", * "state": "CREATED", * "name": "T-Shirt of the Month Club Plan", * "description": "Template creation.", * "type": "FIXED", * "payment_definitions": [ * { * "id": "PD-50606817NF8063316RWBZEUA", * "name": "Regular Payments", * "type": "REGULAR", * "frequency": "Month", * "amount": { * "currency": "USD", * "value": "100" * }, * "charge_models": [ * { * "id": "CHM-55M5618301871492MRWBZEUA", * "type": "SHIPPING", * "amount": { * "currency": "USD", * "value": "10" * } * }, * { * "id": "CHM-92S85978TN737850VRWBZEUA", * "type": "TAX", * "amount": { * "currency": "USD", * "value": "12" * } * } * ], * "cycles": "12", * "frequency_interval": "2" * } * ], * "merchant_preferences": { * "setup_fee": { * "currency": "USD", * "value": "1" * }, * "max_fail_attempts": "0", * "return_url": "http://www.return.com", * "cancel_url": "http://www.cancel.com", * "auto_bill_amount": "YES", * "initial_fail_amount_action": "CONTINUE" * }, * "create_time": "2014-07-31T17:41:55.920Z", * "update_time": "2014-07-31T17:41:55.920Z", * "links": [ * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans/P-94458432VR012762KRWBZEUA", * "rel": "self", * "method": "GET" * } * ] * } * </code> * * @link https://developer.paypal.com/docs/api/#create-a-plan * @see Omnipay\PayPal\RestGateway */ class RestCreatePlanRequest extends AbstractRestRequest { /** * Get the plan name * * @return string */ public function getName() { return $this->getParameter('name'); } /** * Set the plan name * * @param string $value * @return RestCreatePlanRequest provides a fluent interface. */ public function setName($value) { return $this->setParameter('name', $value); } /** * Get the plan type * * @return string */ public function getType() { return $this->getParameter('type'); } /** * Set the plan type * * @param string $value either RestGateway::BILLING_PLAN_TYPE_FIXED * or RestGateway::BILLING_PLAN_TYPE_INFINITE * @return RestCreatePlanRequest provides a fluent interface. */ public function setType($value) { return $this->setParameter('type', $value); } /** * Get the plan payment definitions * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#paymentdefinition-object */ public function getPaymentDefinitions() { return $this->getParameter('paymentDefinitions'); } /** * Set the plan payment definitions * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreatePlanRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#paymentdefinition-object */ public function setPaymentDefinitions(array $value) { return $this->setParameter('paymentDefinitions', $value); } /** * Get the plan merchant preferences * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @return array * @link https://developer.paypal.com/docs/api/#merchantpreferences-object */ public function getMerchantPreferences() { return $this->getParameter('merchantPreferences'); } /** * Set the plan merchant preferences * * See the class documentation and the PayPal REST API documentation for * a description of the array elements. * * @param array $value * @return RestCreatePlanRequest provides a fluent interface. * @link https://developer.paypal.com/docs/api/#merchantpreferences-object */ public function setMerchantPreferences(array $value) { return $this->setParameter('merchantPreferences', $value); } public function getData() { $this->validate('name', 'description', 'type'); $data = array( 'name' => $this->getName(), 'description' => $this->getDescription(), 'type' => $this->getType(), 'payment_definitions' => $this->getPaymentDefinitions(), 'merchant_preferences' => $this->getMerchantPreferences(), ); return $data; } /** * Get transaction endpoint. * * Billing plans are created using the /billing-plans resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-plans'; } } paypal/src/Message/ExpressTransactionSearchRequest.php 0000666 00000020456 15165413756 0017304 0 ustar 00 <?php namespace Omnipay\PayPal\Message; use DateTime; /** * Paypal Express Checkout - Transaction Search * * @see https://developer.paypal.com/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/ * @see https://developer.paypal.com/docs/classic/express-checkout/ht_searchRetrieveTransactionData-curl-etc/ * * pt_BR: * @see https://www.paypal-brasil.com.br/desenvolvedores/tutorial/criando-relatorios-customizados-via-api/ */ class ExpressTransactionSearchRequest extends AbstractRequest { public function getData() { $data = $this->getBaseData(); $data['METHOD'] = 'TransactionSearch'; $this->validate('startDate'); $data['STARTDATE'] = $this->getStartDate()->format(DateTime::ISO8601); if ($this->getEndDate()) { $data['ENDDATE'] = $this->getEndDate()->format(DateTime::ISO8601); } if ($this->getSalutation()) { $data['SALUTATION'] = $this->getSalutation(); } if ($this->getFirstName()) { $data['FIRSTNAME'] = $this->getFirstName(); } if ($this->getMiddleName()) { $data['MIDDLENAME'] = $this->getMiddleName(); } if ($this->getLastName()) { $data['LASTNAME'] = $this->getLastName(); } if ($this->getSuffix()) { $data['SUFFIX'] = $this->getSuffix(); } if ($this->getEmail()) { $data['EMAIL'] = $this->getEmail(); } if ($this->getReceiver()) { $data['RECEIVER'] = $this->getReceiver(); } if ($this->getReceiptId()) { $data['RECEIPTID'] = $this->getReceiptId(); } if ($this->getTransactionId()) { $data['TRANSACTIONID'] = $this->getTransactionId(); } if ($this->getInvoiceNumber()) { $data['INVNUM'] = $this->getInvoiceNumber(); } if ($this->getCard()) { $data['ACCT'] = $this->getCard()->getNumber(); } if ($this->getAuctionItemNumber()) { $data['AUCTIONITEMNUMBER'] = $this->getAuctionItemNumber(); } if ($this->getTransactionClass()) { $data['TRANSACTIONCLASS'] = $this->getTransactionClass(); } if ($this->getAmount()) { $this->validate('currency'); $data['AMT'] = $this->getAmount(); $data['CURRENCYCODE'] = $this->getCurrency(); } if ($this->getStatus()) { $data['STATUS'] = $this->getStatus(); } if ($this->getProfileId()) { $data['PROFILEID'] = $this->getProfileId(); } return $data; } /** * @return DateTime|null */ public function getStartDate() { return $this->getParameter('startDate'); } /** * @param DateTime|string $date * @return \Omnipay\Common\Message\AbstractRequest */ public function setStartDate($date) { if (! $date instanceof DateTime) { $date = new DateTime($date); } return $this->setParameter('startDate', $date); } /** * @return DateTime|null */ public function getEndDate() { return $this->getParameter('endDate'); } /** * @param DateTime|string $date * @return \Omnipay\Common\Message\AbstractRequest */ public function setEndDate($date) { if (! $date instanceof DateTime) { $date = new DateTime($date); } return $this->setParameter('endDate', $date); } /** * @return string */ public function getSalutation() { return $this->getParameter('salutation'); } /** * @param string $salutation * @return \Omnipay\Common\Message\AbstractRequest */ public function setSalutation($salutation) { return $this->setParameter('salutation', $salutation); } /** * @return string */ public function getFirstName() { return $this->getParameter('firstName'); } /** * @param string $firstName * @return \Omnipay\Common\Message\AbstractRequest */ public function setFirstName($firstName) { return $this->setParameter('firstName', $firstName); } /** * @return string */ public function getMiddleName() { return $this->getParameter('middleName'); } /** * @param string $middleName * @return \Omnipay\Common\Message\AbstractRequest */ public function setMiddleName($middleName) { return $this->setParameter('middleName', $middleName); } /** * @return string */ public function getLastName() { return $this->getParameter('lastName'); } /** * @param string $lastName * @return \Omnipay\Common\Message\AbstractRequest */ public function setLastName($lastName) { return $this->setParameter('lastName', $lastName); } /** * @return string */ public function getSuffix() { return $this->getParameter('suffix'); } /** * @param string $suffix * @return \Omnipay\Common\Message\AbstractRequest */ public function setSuffix($suffix) { return $this->setParameter('suffix', $suffix); } /** * @return string */ public function getEmail() { return $this->getParameter('email'); } /** * @param string $email * @return \Omnipay\Common\Message\AbstractRequest */ public function setEmail($email) { return $this->setParameter('email', $email); } /** * @return string */ public function getReceiver() { return $this->getParameter('receiver'); } /** * @param string $receiver * @return \Omnipay\Common\Message\AbstractRequest */ public function setReceiver($receiver) { return $this->setParameter('receiver', $receiver); } /** * @return string */ public function getReceiptId() { return $this->getParameter('receiptId'); } /** * @param string $receiptId * @return \Omnipay\Common\Message\AbstractRequest */ public function setReceiptId($receiptId) { return $this->setParameter('receiptId', $receiptId); } /** * @return string */ public function getInvoiceNumber() { return $this->getParameter('invoiceNumber'); } /** * @param string $invoiceNumber * @return \Omnipay\Common\Message\AbstractRequest */ public function setInvoiceNumber($invoiceNumber) { return $this->setParameter('invoiceNumber', $invoiceNumber); } /** * @return string */ public function getAuctionItemNumber() { return $this->getParameter('auctionItemNumber'); } /** * @param string $auctionItemNumber * @return \Omnipay\Common\Message\AbstractRequest */ public function setAuctionItemNumber($auctionItemNumber) { return $this->setParameter('auctionItemNumber', $auctionItemNumber); } /** * @return string */ public function getTransactionClass() { return $this->getParameter('transactionClass'); } /** * @param string $transactionClass * @return \Omnipay\Common\Message\AbstractRequest */ public function setTransactionClass($transactionClass) { return $this->setParameter('transactionClass', $transactionClass); } /** * @return string */ public function getStatus() { return $this->getParameter('status'); } /** * @param string $status * @return \Omnipay\Common\Message\AbstractRequest */ public function setStatus($status) { return $this->setParameter('status', $status); } /** * @return string */ public function getProfileId() { return $this->getParameter('profileId'); } /** * @param string $profileId * @return \Omnipay\Common\Message\AbstractRequest */ public function setProfileId($profileId) { return $this->setParameter('profileId', $profileId); } /** * @return ExpressTransactionSearchResponse */ public function createResponse($data) { return $this->response = new ExpressTransactionSearchResponse($this, $data); } } paypal/src/Message/AbstractRequest.php 0000666 00000022330 15165413756 0014053 0 ustar 00 <?php /** * PayPal Abstract Request */ namespace Omnipay\PayPal\Message; use Omnipay\Common\ItemBag; use Omnipay\PayPal\PayPalItem; use Omnipay\PayPal\PayPalItemBag; /** * PayPal Abstract Request * * This class forms the base class for PayPal Express Checkout and Pro Checkout * requests. These are also known as "Payflow Gateway" requests and also * "PayPal Classic APIs". * * According to the PayPal documentation: * * * This is the recommended way to integrate when you want to accept payments * with a completely customizable solution. This integration method leverages * the PayPal Payflow Gateway to transmit payments your PayPal Internet Merchant * Account; it also gives the merchant the flexibility to change payment * processors without having to re-do their technical integration. When using * PayPal Payments Pro (Payflow Edition) using Payflow Gateway integration, * merchants can use Transparent Redirect feature to help manage PCI compliance. * * @link https://developer.paypal.com/docs/classic/products/payflow-gateway/ * @link https://developer.paypal.com/docs/classic/express-checkout/gs_expresscheckout/ * @link https://developer.paypal.com/docs/classic/products/ppp-payflow-edition/ * @link https://devtools-paypal.com/integrationwizard/ * @link http://paypal.github.io/sdk/ */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { const API_VERSION = '119.0'; protected $liveEndpoint = 'https://api-3t.paypal.com/nvp'; protected $testEndpoint = 'https://api-3t.sandbox.paypal.com/nvp'; /** * @var bool */ protected $negativeAmountAllowed = true; public function getUsername() { return $this->getParameter('username'); } public function setUsername($value) { return $this->setParameter('username', $value); } public function getPassword() { return $this->getParameter('password'); } public function setPassword($value) { return $this->setParameter('password', $value); } public function getSignature() { return $this->getParameter('signature'); } public function setSignature($value) { return $this->setParameter('signature', $value); } public function getSubject() { return $this->getParameter('subject'); } public function setSubject($value) { return $this->setParameter('subject', $value); } public function getSolutionType() { return $this->getParameter('solutionType'); } public function setSolutionType($value) { return $this->setParameter('solutionType', $value); } public function getLandingPage() { return $this->getParameter('landingPage'); } public function setLandingPage($value) { return $this->setParameter('landingPage', $value); } public function getHeaderImageUrl() { return $this->getParameter('headerImageUrl'); } public function setHeaderImageUrl($value) { return $this->setParameter('headerImageUrl', $value); } public function getLogoImageUrl() { return $this->getParameter('logoImageUrl'); } public function setLogoImageUrl($value) { return $this->setParameter('logoImageUrl', $value); } public function getBorderColor() { return $this->getParameter('borderColor'); } public function setBorderColor($value) { return $this->setParameter('borderColor', $value); } public function getBrandName() { return $this->getParameter('brandName'); } public function setBrandName($value) { return $this->setParameter('brandName', $value); } public function getNoShipping() { return $this->getParameter('noShipping'); } public function setNoShipping($value) { return $this->setParameter('noShipping', $value); } public function getAllowNote() { return $this->getParameter('allowNote'); } public function setAllowNote($value) { return $this->setParameter('allowNote', $value); } public function getAddressOverride() { return $this->getParameter('addressOverride'); } public function setAddressOverride($value) { return $this->setParameter('addressOverride', $value); } public function getMaxAmount() { return $this->getParameter('maxAmount'); } public function setMaxAmount($value) { return $this->setParameter('maxAmount', $value); } public function getTaxAmount() { return $this->getParameter('taxAmount'); } public function setTaxAmount($value) { return $this->setParameter('taxAmount', $value); } public function getShippingAmount() { return $this->getParameter('shippingAmount'); } public function setShippingAmount($value) { return $this->setParameter('shippingAmount', $value); } public function getHandlingAmount() { return $this->getParameter('handlingAmount'); } public function setHandlingAmount($value) { return $this->setParameter('handlingAmount', $value); } public function getShippingDiscount() { return $this->getParameter('shippingDiscount'); } public function setShippingDiscount($value) { return $this->setParameter('shippingDiscount', $value); } public function getInsuranceAmount() { return $this->getParameter('insuranceAmount'); } public function setInsuranceAmount($value) { return $this->setParameter('insuranceAmount', $value); } public function getLocaleCode() { return $this->getParameter('localeCode'); } /* * Used to change the locale of PayPal pages. * Accepts 2 or 5 character language codes as described here: * https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/ * * If no value/invalid value is passed, the gateway will default it for you */ public function setLocaleCode($value) { return $this->setParameter('localeCode', $value); } public function setCustomerServiceNumber($value) { return $this->setParameter('customerServiceNumber', $value); } public function getCustomerServiceNumber() { return $this->getParameter('customerServiceNumber'); } public function setSellerPaypalAccountId($value) { return $this->setParameter('sellerPaypalAccountId', $value); } public function getSellerPaypalAccountId() { return $this->getParameter('sellerPaypalAccountId'); } /** * The Button Source (BN Code) is for PayPal Partners taking payments for a 3rd party */ public function setButtonSource($value) { return $this->setParameter('ButtonSource', $value); } public function getButtonSource() { return $this->getParameter('ButtonSource'); } protected function getBaseData() { $data = array(); $data['VERSION'] = static::API_VERSION; $data['USER'] = $this->getUsername(); $data['PWD'] = $this->getPassword(); $data['SIGNATURE'] = $this->getSignature(); $data['SUBJECT'] = $this->getSubject(); $bnCode = $this->getButtonSource(); if (!empty($bnCode)) { $data['BUTTONSOURCE'] = $bnCode; } return $data; } protected function getItemData() { $data = array(); $items = $this->getItems(); if ($items) { $data["PAYMENTREQUEST_0_ITEMAMT"] = 0; foreach ($items as $n => $item) { $data["L_PAYMENTREQUEST_0_NAME$n"] = $item->getName(); $data["L_PAYMENTREQUEST_0_DESC$n"] = $item->getDescription(); $data["L_PAYMENTREQUEST_0_QTY$n"] = $item->getQuantity(); $data["L_PAYMENTREQUEST_0_AMT$n"] = $this->formatCurrency($item->getPrice()); if ($item instanceof PayPalItem) { $data["L_PAYMENTREQUEST_0_NUMBER$n"] = $item->getCode(); } $data["PAYMENTREQUEST_0_ITEMAMT"] += $item->getQuantity() * $this->formatCurrency($item->getPrice()); } $data["PAYMENTREQUEST_0_ITEMAMT"] = $this->formatCurrency($data["PAYMENTREQUEST_0_ITEMAMT"]); } return $data; } public function sendData($data) { $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], http_build_query($data, '', '&')); return $this->createResponse($httpResponse->getBody()->getContents()); } protected function getEndpoint() { return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; } protected function createResponse($data) { return $this->response = new Response($this, $data); } /** * Set the items in this order * * @param ItemBag|array $items An array of items in this order */ public function setItems($items) { if ($items && !$items instanceof ItemBag) { $items = new PayPalItemBag($items); } return $this->setParameter('items', $items); } } paypal/src/Message/ProPurchaseRequest.php 0000666 00000000427 15165413756 0014546 0 ustar 00 <?php namespace Omnipay\PayPal\Message; /** * PayPal Pro Purchase Request */ class ProPurchaseRequest extends ProAuthorizeRequest { public function getData() { $data = parent::getData(); $data['PAYMENTACTION'] = 'Sale'; return $data; } } paypal/src/Message/RestCompleteSubscriptionRequest.php 0000666 00000007412 15165413756 0017327 0 ustar 00 <?php /** * PayPal REST Complete Subscription Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Complete Subscription Request * * Use this call to execute an agreement after the buyer approves it. * * Note: This request is only necessary for PayPal payments. Billing * agreements for credit card payments execute automatically at the time * of creation and so this request is not necessary for credit card payments. * * ### Request Data * * Pass the token in the URI of a POST call to execute the subscription * agreement after buyer approval. You can find the token in the execute * link returned by the request to create a billing agreement. * * No other data is required. * * ### Example * * To create the agreement, see the code example in RestCreateSubscriptionRequest. * * At the completion of a createSubscription call, the customer should be * redirected to the redirect URL contained in $response->getRedirectUrl(). Once * the customer has approved the agreement and be returned to the returnUrl * in the call. The returnUrl can contain the following code to complete * the agreement: * * <code> * // Create a gateway for the PayPal REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PayPal_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'clientId' => 'MyPayPalClientId', * 'secret' => 'MyPayPalSecret', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Do a complete subscription transaction on the gateway * $transaction = $gateway->completeSubscription(array( * 'transactionReference' => $subscription_id, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Complete Subscription transaction was successful!\n"; * $subscription_id = $response->getTransactionReference(); * echo "Subscription reference = " . $subscription_id; * } * </code> * * Note that the subscription_id that you get from calling the response's * getTransactionReference() method at the end of the completeSubscription * call will be different to the one that you got after calling the response's * getTransactionReference() method at the end of the createSubscription * call. The one that you get from completeSubscription is the correct * one to use going forwards (e.g. for cancelling or updating the subscription). * * ### Request Sample * * This is from the PayPal web site: * * <code> * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-0JP008296V451950C/agreement-execute \ * -H 'Content-Type:application/json' \ * -H 'Authorization: Bearer <Access-Token>' \ * -d '{}' * </code> * * ### Response Sample * * This is from the PayPal web site: * * <code> * { * "id": "I-0LN988D3JACS", * "links": [ * { * "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS", * "rel": "self", * "method": "GET" * } * ] * } * </code> * * @link https://developer.paypal.com/docs/api/#execute-an-agreement * @see RestCreateSubscriptionRequest * @see Omnipay\PayPal\RestGateway */ class RestCompleteSubscriptionRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference'); $data = array(); return $data; } /** * Get transaction endpoint. * * Subscriptions are executed using the /billing-agreements resource. * * @return string */ protected function getEndpoint() { return parent::getEndpoint() . '/payments/billing-agreements/' . $this->getTransactionReference() . '/agreement-execute'; } } paypal/src/Message/RestCaptureRequest.php 0000666 00000003534 15165413756 0014556 0 ustar 00 <?php /** * PayPal REST Capture Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Capture Request * * Use this resource to capture and process a previously created authorization. * To use this resource, the original payment call must have the intent set to * authorize. * * To capture payment, make a call to /v1/payments/authorization/{authorization_id}/capture * with the authorization ID in the URI along with an amount object. For a * partial capture, you can provide a lower amount. Additionally, you can explicitly * indicate a final capture (prevent future captures) by setting the is_final_capture * value to true. * * ### Example * * Note this example assumes that the authorization has been successful * and that the authorization ID returned from the authorization is held in $auth_id. * See RestAuthorizeRequest for the first part of this example transaction: * * <code> * // Once the transaction has been authorized, we can capture it for final payment. * $transaction = $gateway->capture(array( * 'amount' => '10.00', * 'currency' => 'AUD', * )); * $transaction->setTransactionReference($auth_id); * $response = $transaction->send(); * </code> * * @see RestAuthorizeRequest * @link https://developer.paypal.com/docs/api/#capture-an-authorization */ class RestCaptureRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference', 'amount'); return array( 'amount' => array( 'currency' => $this->getCurrency(), 'total' => $this->getAmount(), ), 'is_final_capture' => true, ); } public function getEndpoint() { return parent::getEndpoint() . '/payments/authorization/' . $this->getTransactionReference() . '/capture'; } } paypal/src/Message/RestRefundCaptureRequest.php 0000666 00000001555 15165413756 0015723 0 ustar 00 <?php /** * PayPal REST Refund Captured Payment Request */ namespace Omnipay\PayPal\Message; /** * PayPal REST Refund Captured Payment Request * * Use this call to refund a captured payment. * * @link https://developer.paypal.com/docs/api/#refund-a-captured-payment * @see RestAuthorizeRequest * @see RestCaptureRequest */ class RestRefundCaptureRequest extends AbstractRestRequest { public function getData() { $this->validate('transactionReference'); return array( 'amount' => array( 'currency' => $this->getCurrency(), 'total' => $this->getAmount(), ), 'description' => $this->getDescription(), ); } public function getEndpoint() { return parent::getEndpoint() . '/payments/capture/' . $this->getTransactionReference() . '/refund'; } } paypal/src/PayPalItem.php 0000666 00000000670 15165413756 0011363 0 ustar 00 <?php /** * Paypal Item */ namespace Omnipay\PayPal; use Omnipay\Common\Item; /** * Class PayPalItem * * @package Omnipay\PayPal */ class PayPalItem extends Item { /** * {@inheritDoc} */ public function getCode() { return $this->getParameter('code'); } /** * Set the item code */ public function setCode($value) { return $this->setParameter('code', $value); } } paypal/src/ExpressGateway.php 0000666 00000011034 15165413756 0012325 0 ustar 00 <?php namespace Omnipay\PayPal; /** * PayPal Express Class */ class ExpressGateway extends ProGateway { public function getName() { return 'PayPal Express'; } public function getDefaultParameters() { $settings = parent::getDefaultParameters(); $settings['solutionType'] = array('Sole', 'Mark'); $settings['landingPage'] = array('Billing', 'Login'); $settings['brandName'] = ''; $settings['headerImageUrl'] = ''; $settings['logoImageUrl'] = ''; $settings['borderColor'] = ''; return $settings; } public function getSolutionType() { return $this->getParameter('solutionType'); } public function setSolutionType($value) { return $this->setParameter('solutionType', $value); } public function getLandingPage() { return $this->getParameter('landingPage'); } public function setLandingPage($value) { return $this->setParameter('landingPage', $value); } public function getBrandName() { return $this->getParameter('brandName'); } public function setBrandName($value) { return $this->setParameter('brandName', $value); } public function getHeaderImageUrl() { return $this->getParameter('headerImageUrl'); } public function getLogoImageUrl() { return $this->getParameter('logoImageUrl'); } public function getBorderColor() { return $this->getParameter('borderColor'); } /** * Header Image URL (Optional) * * URL for the image you want to appear at the top left of the payment page. * The image has a maximum size of 750 pixels wide by 90 pixels high. * PayPal recommends that you provide an image that is stored on a secure * (HTTPS) server. * If you do not specify an image, the business name displays. * Character length and limitations: 127 single-byte alphanumeric characters */ public function setHeaderImageUrl($value) { return $this->setParameter('headerImageUrl', $value); } /** * Logo Image URL (Optional) * * URL for the image to appear above the order summary, in place of the * brand name. * The recommended size is 190 pixels wide and 60 pixels high. */ public function setLogoImageUrl($value) { return $this->setParameter('logoImageUrl', $value); } /** * Border Color (Optional) * * The color of the border gradient on payment pages. * Should be a six character hexadecimal code (i.e. C0C0C0). */ public function setBorderColor($value) { return $this->setParameter('borderColor', $value); } public function setSellerPaypalAccountId($value) { return $this->setParameter('sellerPaypalAccountId', $value); } public function getSellerPaypalAccountId() { return $this->getParameter('sellerPaypalAccountId'); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressAuthorizeRequest', $parameters); } public function completeAuthorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressCompleteAuthorizeRequest', $parameters); } public function purchase(array $parameters = array()) { return $this->authorize($parameters); } public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressCompletePurchaseRequest', $parameters); } public function void(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressVoidRequest', $parameters); } public function fetchCheckout(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressFetchCheckoutRequest', $parameters); } /** * @return Message\ExpressTransactionSearchRequest */ public function transactionSearch(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressTransactionSearchRequest', $parameters); } public function order(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressOrderRequest', $parameters); } public function completeOrder(array $parameters = array()) { return $this->createRequest('\Omnipay\PayPal\Message\ExpressCompleteOrderRequest', $parameters); } } paypal/grumphp.yml 0000666 00000000530 15165413756 0010256 0 ustar 00 parameters: git_dir: . bin_dir: vendor/bin tasks: phpunit: config_file: ~ testsuite: ~ group: [] always_execute: false phpcs: standard: PSR2 warning_severity: ~ ignore_patterns: - tests/ triggered_by: [php] paypal/composer.json 0000666 00000002023 15165413756 0010572 0 ustar 00 { "name": "omnipay/paypal", "type": "library", "description": "PayPal gateway for Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "paypal", "purchase" ], "homepage": "https://github.com/thephpleague/omnipay-paypal", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-paypal/contributors" } ], "autoload": { "psr-4": { "Omnipay\\PayPal\\" : "src/" } }, "require": { "omnipay/common": "^3" }, "require-dev": { "omnipay/tests": "^3", "squizlabs/php_codesniffer": "^3", "phpro/grumphp": "^0.14" }, "extra": { "branch-alias": { "dev-master": "3.0.x-dev" } }, "prefer-stable": true } paypal/makedoc.sh 0000666 00000007565 15165413756 0010027 0 ustar 00 #!/bin/sh # # Smart little documentation generator. # GPL/LGPL # (c) Del 2015 http://www.babel.com.au/ # APPNAME='Omnipay PayPal Gateway Module' CMDFILE=apigen.cmd.$$ DESTDIR=./documents # # Find apigen, either in the path or as a local phar file # if [ -f apigen.phar ]; then APIGEN="php apigen.phar" else APIGEN=`which apigen` if [ ! -f "$APIGEN" ]; then # Search for phpdoc if apigen is not found. if [ -f phpDocumentor.phar ]; then PHPDOC="php phpDocumentor.phar" else PHPDOC=`which phpdoc` if [ ! -f "$PHPDOC" ]; then echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them" echo "see http://www.apigen.org/ or http://www.phpdoc.org/" exit 1 fi fi fi fi # # As of version 4 of apigen need to use the generate subcommand # if [ ! -z "$APIGEN" ]; then APIGEN="$APIGEN generate" fi # # Without any arguments this builds the entire system documentation, # making the cache file first if required. # if [ -z "$1" ]; then # # Check to see that the cache has been made. # if [ ! -f dirlist.cache ]; then echo "Making dirlist.cache file" $0 makecache fi # # Build the apigen/phpdoc command in a file. # if [ ! -z "$APIGEN" ]; then echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE cat dirlist.cache | while read dir; do echo "--source $dir \\" >> $CMDFILE done echo "" >> $CMDFILE elif [ ! -z "$PHPDOC" ]; then echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE cat dirlist.cache | while read dir; do echo "${dir},\\" >> $CMDFILE done echo "" >> $CMDFILE else "Neither apigen nor phpdoc are found, how did I get here?" exit 1 fi # # Run the apigen command # rm -rf $DESTDIR/main mkdir -p $DESTDIR/main . ./$CMDFILE /bin/rm -f ./$CMDFILE # # The "makecache" argument causes the script to just make the cache file # elif [ "$1" = "makecache" ]; then echo "Find application source directories" find src -name \*.php -print | \ ( while read file; do grep -q 'class' $file && dirname $file done ) | sort -u | \ grep -v -E 'config|docs|migrations|phpunit|test|Test|views|web' > dirlist.app echo "Find vendor source directories" find vendor -name \*.php -print | \ ( while read file; do grep -q 'class' $file && dirname $file done ) | sort -u | \ grep -v -E 'config|docs|migrations|phpunit|codesniffer|test|Test|views' > dirlist.vendor # # Filter out any vendor directories for which apigen fails # echo "Filter source directories" mkdir -p $DESTDIR/tmp cat dirlist.app dirlist.vendor | while read dir; do if [ ! -z "$APIGEN" ]; then $APIGEN --quiet --title "Test please ignore" \ --source $dir \ --destination $DESTDIR/tmp && ( echo "Including $dir" echo $dir >> dirlist.cache ) || ( echo "Excluding $dir" ) elif [ ! -z "$PHPDOC" ]; then $PHPDOC --quiet --title "Test please ignore" \ --directory $dir \ --target $DESTDIR/tmp && ( echo "Including $dir" echo $dir >> dirlist.cache ) || ( echo "Excluding $dir" ) fi done echo "Documentation cache dirlist.cache built OK" # # Clean up # /bin/rm -rf $DESTDIR/tmp fi
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings