Giter Club home page Giter Club logo

heartland-php's Introduction

Heartland logo

Heartland PHP SDK

This SDK makes it easy to integrate your PHP application with Heartland’s Portico Gateway API, as well as other APIs such as MasterPass. Additionally, this SDK also facilitates integration with Heartland Secure: Out-of-Scope devices, providing for simple semi- integrated EMV acceptance, enabling a true single point of integration for omni-channel developers.

Supported features include:

Data Security API Reference Testing &
Certification
API Keys Links
Register an Account
Partner with Heartland

Developer Support

You are not alone! If you have any questions while you are working through your development process, please feel free to reach out to our team for assistance!

Installation

Add this SDK to your PHP project and require it once.

<?php
require_once 'Hps.php';
?>

Using Composer? Require this library in your composer.json:

{
    "require": {
        "hps/heartland-php": "*"
    }
}

and run composer update to pull down the dependency and update your autoloader.

API Keys

Integrations that use card not present transactions, such as eCommerce web applications, will use API keys to authenticate. There are exceptions, such as card present POS integrations. For these projects please contact us for more information.

To begin creating test transactions you will need to obtain a set of public and private keys. These are easily obtained by creating an account on our developer portal. Your keys are located under your profile information.

Developer Keys

You will use your public key when implementing card tokenization and your private key will be used when communicating with our Portico Gateway. More details can be found in our documentation.

Note: Multi-Use tokenization is not enabled by default when creating an account. You can contact Heartland's Specialty Products Team to have this enabled. This is also true if you wish to use Gift & Loyalty, ACH, and Debit.

Data Security

If your app stores, processes, or transmits cardholder data in cleartext then it is in-scope for PA-DSS. If your app is hosted, or the data in question otherwise comes into your organization, then the app and your entire company are in-scope for PCI DSS (either as a merchant or a service provider). Heartland offers a suite of solutions to help keep integrators' applications and/or environments shielded from cardholder data, whether it motion or at rest.
  • Secure Submit for eCommerce web or mobile applications ("card-not-present"), which leverages single-use tokenization to prevent card data from passing through the merchant or integrator's webserver. It only requires a simple JavaScript inclusion and provides two options for payment field hosting:

  • Self-Hosted Fields - this approach relies upon the standard, appropriately named, HTML form controls on the integrator's served web page.

  • Heartland Hosted Fields - this approach combines the Secure Submit service with iframes to handle presentation of the form fields and collection of sensitive data on Heartland servers. Since PCI version 3.1 the PCI Council and many QSAs advocate the iframe-based approach as enabling a merchant to more readily achieve PCI compliance via the simplified SAQ A-EP form. Check out the CoalFire's whitepaper for more information.

  • Heartland Secure for card-present retailers, hospitality, and other "POS" applications, comprises three distinct security technologies working in concert:

  • End-to-End Encryption (E3) - combines symmetric and asymmetric cryptography to form an "Identity-Based Encryption" methodology which keeps cardholder data encrypted from the moment of the swipe.

  • Tokenization - replaces sensitive data values with non-sensitive representations which may be stored for recurring billing, future orders, etc.

  • EMV - though less about data security and more about fraud prevention, EMV or chip card technology guarantees the authenticity of the payment card and is thus an important concern for retailers.

Depending on your (or your customers') payment acceptance environment, you may need to support one or more of these technologies in addition to this SDK. This SDK also supports the ability to submit cleartext card numbers as input, but any developer who does so will be expected to demonstrate compliance with PA-DSS. Likewise any third party integrator who is planning on handling cleartext card data on behalf of other merchants will be expected to demonstrate their PCI DSS compliance as a Service Provider prior to completing certification with Heartland.

If you implement Secure Submit tokenization for your web or mobile application you will never have to deal with handling a card number - Heartland will take care of it for you and return a token to initiate the charge from your servers.

Similarly, if you implement Heartland Secure with E3 (for both swiped and keyed entry methods) then your POS application will be out-of-scope for PA-DSS. Heartland Secure certified devices will only ever return E3 encrypted data which can safely be passed through your systems as input to this SDK. Heartland Secure devices include many popular models manufactured by PAX and Ingenico.

To summarize, when you create a paymentMethod using this SDK you have the following options for securely avoiding interaction with sensitive cardholder data:

  • Card data (track or PAN) may be sent directly from a web browser to Heartland, returning a SecureSubmit single use token that is then sent to your server.

  • Encrypted card data (track or PAN) may be obtained directly from a Heartland Secure device and passed to the SDK

Documentation and Examples

You can find the latest SDK documentation along with code examples on our [Developer Portal](http://developer.heartlandpaymentsystems.com/documentation). In addition you can find many examples in the SDK itself, located under the examples directory:

Quick Tip: The included test suite can be a great source of code samples for using the SDK!

Fluent Interface

Note that our SDK provides a Fluent Interface which allows you to replace a charge call that looks like this:

$response = $chargeSvc->charge(17.01, "usd", TestCreditCard::validVisaCreditCard(), TestCardHolder::certCardHolderShortZip());

With one that reads like this:

$response = $this->service
                 ->charge()
                 ->withAmount(17.01)
                 ->withCurrency("usd")
                 ->withCard(TestCreditCard::validVisaCreditCard())
                 ->withCardHolder(TestCardHolder::certCardHolderShortZip())
                 ->execute();

Between the two samples you can more easily read and understand what the code is doing in the second example than the first. That is a big advantage and helps speed development and reduce errors when using methods that allow a large number of parameters.

Quick Tip: You will find Fluent and Non-Fluent examples in the included test suite.

Testing & Certification

Testing your implementation in our Certification/Sandbox environment helps to identify and squash bugs before you begin processing transactions in the production environment. While you are encouraged to run as many test transactions as you can, Heartland provides a specific series of tests that you are required to complete before receiving Certification. Please contact Heartland to initiate certification for your integration. For eComm integrations please email our Specialty Products Team, for POS developers please email Integrations.

Quick Tip: You can get a head start on your certification by reviewing the certification tests in the included test suite.

Test Card Data

The following card numbers are used by our Certification environment to verify that your tests worked. Note that while variations (such as 4111111111111111) will work for general testing the cards listed below are required to complete certification. For card present testing Heartland can provide you with EMV enabled test cards.

Name Number Exp Month Exp Year CVV Address Zip
Visa 4012002000060016 12 2025 123 6860 Dallas Pkwy 75024
MasterCard 5473500000000014 12 2025 123 6860 Dallas Pkwy 75024
Discover 6011000990156527 12 2025 123 6860 Dallas Pkwy 75024
Amex 372700699251018 12 2025 1234 6860 Dallas Pkwy 75024
JCB 3566007770007321 12 2025 123 6860 Dallas Pkwy 75024

Testing Exceptions

During your integration you will want to test for specific issuer responses such as 'Card Declined'. Because our sandbox does not actually reach out to card brands for authorizations we have devised specific transaction amounts that will trigger issuer response codes and gateway response codes. Please contact Heartland for a complete listing of values you can charge to simulate AVS, CVV and Transaction declines, errors, and other responses that you can catch in your code:

     try
            {
                 $response = $this->service
                                  ->charge()
                                  ->withAmount(5)
                                  ->execute();
            }
            catch (HpsInvalidRequestException $e)
            {
                // handle errors for invalid arguments such as a charge amount less than zero dollars
            }
            catch (HpsAuthenticationException $e)
            {
                // handle errors related to your HpsServiceConfig (username, pw, api keys etc.)
            }
            catch (HpsCreditException $e)
            {
                // handle card-related exceptions: card declined, processing error, etc                 
            }

Contributing

All our code is open sourced and we encourage fellow developers to contribute and help improve it!

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Ensure SDK tests are passing
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

Included Test Suite

The included test suite can help ensure your contribution doesn't cause unexpected errors and is a terrific resource of working examples that you can reference.

Clone this repository locally, install dependencies with Composer, and run PHPUnit against the provided tests.

$ git clone https://github.com/SecureSubmit/heartland-php.git
$ cd heartland-php
$ composer install
$ php vendor/bin/phpunit -c tests/phpunit.xml

This will run through all of our test suites by default. To run a single test suite, pass the --testsuite option to php vendor/bin/phpunit with one of the following values:

  • fluent
  • gateway-check
  • gateway-credit
  • gateway-debit
  • gateway-giftcard
  • gateway-token
  • general
  • certification

Example:

$ php vendor/bin/phpunit -c tests/phpunit.xml --testsuite certification

heartland-php's People

Contributors

andyrooster avatar bertoncobb avatar clinttepe avatar eric-vest avatar markhagan avatar russelleverett avatar securesubmit-buildmaster avatar slogsdon avatar stoph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heartland-php's Issues

transactionsStatus?

Where can I see all the transactionsStatus? What is the transactionsStatus after "Authorization" and what is after a capture? An authorization could be capture twice?

Details passed in as the 5th param of a charge call aren't returned in the HpsAuthorisation

If a details object is passed into the charge call I would expect those details to be returned in the HpsAuthorization however the HpsAuthorization returned from the certification gateway always contains NULL for the three values.

Example charge call:
$details = (object) array('memo' => 'My description', 'invoiceNumber' => 'IN_1234', 'customerId' => '9090');
$auth = $chargeService->charge(50, 'usd', $token], null, false, $details);

Returned auth object:
object(HpsAuthorization)#99 (19) {
["avsResultCode"]=> string(1) "0"
["avsResultText"]=> string(18) "AVS Not Requested."
["cvvResultCode"]=> string(1) "M"
["cvvResultText"]=> string(6) "Match."
["cpcIndicator"]=> NULL
["authorizationCode"]=> string(6) "27445A"
["authorizedAmount"]=> NULL
["cardType"]=> string(4) "Visa"
["description"]=> NULL
["invoiceNumber"]=> NULL
["customerId"]=> NULL
["descriptor"]=> NULL
["tokenData"]=> NULL
["transactionId"]=> string(10) "1011918135"
["clientTransactionId"]=> NULL
["responseCode"]=> string(2) "00"
["responseText"]=> string(8) "APPROVAL"
["referenceNumber"]=> string(12) "618712011447"
["_header":protected]=>
object(HpsTransactionHeader)#107 (4) {
["gatewayResponseCode"]=> string(1) "0"
["gatewayResponseMessage"]=> string(7) "Success"
["responseDt"]=> string(27) "2016-07-05T03:41:16.1065041"
["clientTxnId"]=> NULL
}
}

I believe the same goes for the 6th parameter $txnDescriptor also.

inefficient autoloader

Installed via composer.

heartland-php's composer.json :

{
  "autoload":{
    "files": [
      "Hps.php"
    ]
  }
}

As a result my site now loads 184 files associated with the heartland-php sdk on every request (regardless of whether or not the request will even use the sdk, and regardless of what features I need)

the Hps.php file should only be necessary / used when composer isn't being used

Is there a reason heartland-php's composer.json doesn't define classmap rather than files?

ie

{
    "autoload": {
        "classmap": ["src/"]
    }
}

https://getcomposer.org/doc/04-schema.md#classmap

Files

If you want to require certain files explicitly on every request then you can use the files autoloading mechanism. This is useful if your package includes PHP functions that cannot be autoloaded by PHP.

(this isn't the case... the heartland-php sdk doesn't define any global functions. it only defines classes (and classes can be autoloaded)

Classmap

The classmap references are all combined, during install/update, into a single key => value array which may be found in the generated file vendor/composer/autoload_classmap.php. This map is built by scanning for classes in all .php and .inc files in the given directories/files.

You can use the classmap generation support to define autoloading for all libraries that do not follow PSR-0/4. To configure this you specify all directories or files to search for classes.

A Reflected XSS vulnerability in this sdk

Hello:
I found a Reflected XSS vulnerability in this sdk.

The vulnerability exists due to directly output user-supplied data in HTTP GET parameter, this happended in the file "heartland-php-master\examples\consumer-authentication\cruise.php". The infected source code is line 27, there is no protection on $_GET;
code1

if $_GET contains evil js code, line 27 will trigger untrusted code to be excuted on the browser side.

So if a attacker construct a special url as follow and send it to a victim, when the victim click the url, the code which is contained in the url will be executed on the victim's browser side to do some evil.
http://your-web-root/heartland-php-master/examples/consumer-authentication/cruise.php?cavv="><script>alert(1);</script><"

The follow scrrenshot is the result to click the upper url ( win7 sp1 x64 + firefox 51.0.1 32bit ):
sc

Discoverer: ADLab of Venustech

pass gratuity in HpsCreditService

Hello,

Thanks for this great work. I am trying to pass gratuity by using HpsCreditService capture function. But it looking like not working. can you please add and example of tip on process and tip on settlement process.

Regards

echeck Payment failes

I'm getting below error while using eCheck Payment.

Processor Configuration error. : Code : 51

Can any budy help me what is this error say and how can I fixed it ?

I'm passing test data in my form like below:

Array
(
[holder_firstname] => vids
[holder_lastname] => sinojiya
[holder_phone] => 8888888888
[holder_dobyear] => 1209
[holder_ssl4] => 8765
[holder_dlnumber] => ijij
[holder_dlstate] => AL
[holder_address_address] => ijioj
[holder_address_city] => fvgh
[holder_address_state] => AK
[holder_address_zip] => 78777
[payment_amount] => 10
[check_accountnumber] => 24413815
[check_routingnumber] => 490000018
)

Can anybudy help me please ?

Thanks

CentOS 6.7 curl version 7.19.7 SSL Handshake Issue

The latest version of curl available on a base CentOS 6.7 (using epel repo) is version 7.19.7. I am receiving an SSL error using curl from cli for the webserver.

Example:

# curl -v [redacted heartland api url]
* About to connect() to [redacted] port 443 (#0)
*   Trying [redacted]... connected
* Connected to [redacted] ([redacted]) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -5938
* Closing connection #0
* SSL connect error
curl: (35) SSL connect error

This is causing an error when attempted to run a transaction:
HpsGatewayException in HpsGatewayServiceAbstract.php line 86: Unexpected response (SSL connect error).

Specifying the CUROPT_SSLVERSION to 6 (which equates to constant CURL_SSLVERSION_TLSv1_2) corrects the issue (in src/Abstractions/HpsGatewayServiceAbstract.php)

I understand that this is an issue with the version of curl provided in CentOS 6.7 (packages are all up to date at time of testing).

Would you prefer to not address this issue in the library for web hosts running CentOS 6.7 and have us fork this library (or require that web hosts using this build a newer version of curl/nss from source) or patch this PHP library to specify the TLS version?

Charge request throws Unexpected response error

I am Yohit, the lead developer of J2Store.
We have a payment plugin for Heartland, which uses the PHP SDK 2.8.2 release.

Here is the J2Store plugin for heartland : https://www.dropbox.com/s/z7x4nus8r1kp8ps/plg_j2store_payment_heartland.zip?dl=0
Here is the complete details of the error .

Unexpected responseHpsGatewayException Object
(
    [code] => 6
    [details] => 
    [innerException] => 
    [message:protected] => Unexpected response
    [string:Exception:private] => 
    [file:protected] => /homepages/42/d508524250/htdocs/laposta-upgrade-final/plugins/j2store/payment_heartland
/library/src/Abstractions/HpsGatewayServiceAbstract.php
    [line:protected] => 83
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /homepages/42/d508524250/htdocs/laposta-upgrade-final/plugins/j2store/payment_heartland
/library/src/Services/Gateway/HpsSoapGatewayService.php
                    [line] => 55
                    [function] => submitRequest
                    [class] => HpsGatewayServiceAbstract
                    [type] => ->
                    [args] => Array
                        (
                            [0] => https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService
.asmx
                            [1] => Array
                                (
                                    [0] => Content-type: text/xml;charset="utf-8"
                                    [1] => Accept: text/xml
                                    [2] => SOAPAction: ""
                                    [3] => Content-length: 1300
                                )

                            [2] => <?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hps="http://Hps.Exchange
.PosGateway"><soapenv:Body><hps:PosRequest><hps:Ver1.0><hps:Header><hps:SecretAPIKey>skapi_cert_MfaWAQBjeV4Ax1_PyAlUWvt0fVnhT4sFlgX-K6_V0Q
</hps:SecretAPIKey><hps:DeveloperID>002914</hps:DeveloperID><hps:VersionNbr>1929</hps:VersionNbr><hps
:SiteTrace></hps:SiteTrace></hps:Header><hps:Transaction><hps:CreditSale><hps:Block1><hps:AllowDup>Y
</hps:AllowDup><hps:AllowPartialAuth>N</hps:AllowPartialAuth><hps:Amt>19.45</hps:Amt><hps:CardHolderData
><hps:CardHolderFirstName>Ramesh</hps:CardHolderFirstName><hps:CardHolderLastName>Elamathi</hps:CardHolderLastName
><hps:CardHolderEmail>[email protected]</hps:CardHolderEmail><hps:CardHolderPhone></hps:CardHolderPhone
><hps:CardHolderAddr>22, East Street</hps:CardHolderAddr><hps:CardHolderCity>San Jose</hps:CardHolderCity
><hps:CardHolderState>California</hps:CardHolderState><hps:CardHolderZip>95101</hps:CardHolderZip></hps
:CardHolderData><hps:CardData><hps:TokenData><hps:TokenValue>supt_rJE3dHeWDS192DMENgPxk7kY</hps:TokenValue
></hps:TokenData><hps:TokenRequest>N</hps:TokenRequest></hps:CardData></hps:Block1></hps:CreditSale>
</hps:Transaction></hps:Ver1.0></hps:PosRequest></soapenv:Body></soapenv:Envelope>

                        )

                )

Cannot charge 0 dollar transaction

The check that is made for zero dollar transactions is using a '==' instead of '===' in HpsInputValidation.

Additionally, bypassing the check and sending to the gateway results in returning an invalid exception during the validation of a gateway response. I think this could also be due to a '==' not being a '==='

Reproducing this should be as simple as passing in '0' to a charge transaction.

Apple Pay

It looks like there's no support for Apple Pay in this library, correct?

I'm assuming that if we obtain a payment token on the iOS device and send to our server, we can decrypt outside of the Heartland libs using something like: https://github.com/etsy/applepay-php

But then once we have that decrypted payment info, do we just pass it in like any other card? I haven't done this, so I'm not positive of the actual decrypted payment token format. I'm assuming it's not the original PAN, but some kind of tokenized / alias PAN that Apple gets and stores when you first add your card to Apple Pay. In that case, I'm assuming Heartland doesn't care whether it originated with Apple Pay or somewhere else, correct?

Obviously, it would be far superior to be able to push the encrypted token all the way to Heartland and have you decrypt it, instead of doing so on our server, the way that other processors / gateways offer. Do you have plans to offer that? Any timeline?

Scalar type hints are available only in PHP 7

Files:
/src/Abstractions/HpsConfigInterface.php
/src/Services/HpsServicesConfig.php
/src/Services/HpsCentinelConfig.php

public function setServiceUri(string $value);

Consider changing this as many of the merchants still use PHP 5.x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.