Code Monkey home page Code Monkey logo

cybersource-sdk-php's Introduction

CyberSource PHP Client

This is the PHP client for the CyberSource SOAP Toolkit API.

Build Status

Packagist

The cybersource/sdk-php is available at Packagist. If you want to install SDK from Packagist,add the following dependency to your application's 'composer.json'.

"require": {
  "cybersource/sdk-php": "*"
  }, 

Prerequisites

  • PHP 7.3 or above
  • A CyberSource account. You can create an evaluation account here.
  • A CyberSource transaction key. You will need to set your merchant ID and transaction key in the cybs.ini file in lib/conf. Instructions on obtaining a transaction key can be found here.

Installation

You can install the client either via Composer or manually. Before installing, make sure to configure the merchant ID, transaction key, and the appropriate WSDL file URL in cybs.ini. By default, the WSDL file for the client is for API version 1.120 (the latest when this package was updated). Available WSDL file URLs can be browsed at the following locations:

Installing with Composer

You'll first need to make sure you have Composer installed. You can follow the instructions on the official web site. Once Composer is installed, you can enter the project root and run:

Linux: composer.phar install 
Windows: composer install 

If you already have composer installed for the project, you'll need to run the update command as below

Linux: composer.phar update 
Windows: composer update

Then, to use the client, you'll need to include the Composer-generated autoload file:

require_once('/path/to/project/vendor/autoload.php');

Manual installation

To use the client manually, include the CyberSource client in your project:

require_once('/path/to/project/lib/CybsSoapClient.php');

Getting Started

The PHP client will generate the request message headers for you, and will contain the methods specified by the WSDL file.

Creating a simple request

The main method you'll use is runTransaction(). To run a transaction, you'll first need to construct a client to generate a request object, which you can populate with the necessary fields (see documentation for sample requests). The object will be converted into XML, so the properties of the object will need to correspond to the correct XML format.

$client = new CybsSoapClient();
$request = $client->createRequest();

$card = new stdClass();
$card->accountNumber = '4111111111111111';
$card->expirationMonth = '12';
$card->expirationYear = '2020';
$request->card = $card;

// Populate $request here with other necessary properties

$reply = $client->runTransaction($request);

Creating a request from XML

You can create a request from XML either in a file or from an XML string. The XML request format is described in the Using XML section here. Here's how to run a transaction from an XML file:

$referenceCode = 'your_merchant_reference_code';
$client = new CybsSoapClient();
$reply = $client->runTransactionFromFile('path/to/my.xml', $referenceCode);

Or, you can create your own XML string and use that instead:

$xml = "";
// Populate $xml
$client = new CybsSoapClient();
$client->runTransactionFromXml($xml);

Using name-value pairs

In order to run transactions using name-value pairs, make sure to set the value for the WSDL for the NVP transaction processor in cybs.ini. Then use the CybsNameValuePairClient as so:

$client = new CybsNameValuePairClient();
$request = array();
$request['ccAuthService_run'] = 'true';
$request['merchantID'] = 'my_merchant_id';
$request['merchantReferenceCode'] = $'my_reference_code';
// Populate $request
$reply = $client->runTransaction($request);

Running the Samples

After configuring your merchant ID and transaction key in cybs.ini, the samples in the samples directory can be run from the project root. For example:

php samples/Sale.php

The samples will output the response object for each request if successful. Note that the samples contain test data and should not be run in a live environment.

Meta Key support

Meta Key is a key generated by an entity that can be used to authenticate on behalf of other entities provided that the entity which holds key is a parent entity or associated as a partner.

SOAP PHP SDK supports meta key by default. Additional detail regarding cybs.ini changes.

merchantID=<Refers to portfolio or account MID>
transaction_key=<Soap password generated for meta key>
Send transacting merchantID in the sample request.

Tests

In order to run tests, you'll need PHPUnit. You'll also need to use Composer for autoloading. If you used Composer to install the client, this should already be set up. Otherwise, to use Composer for autoloading only, from the project root run

composer.phar dump-autoload

If you installed PHPUnit with Composer, run the tests from the project root with the command vendor/bin/phpunit.

Documentation

For more information about CyberSource services, see http://www.cybersource.com/developers/documentation

For all other support needs, see http://www.cybersource.com/support

cybersource-sdk-php's People

Contributors

amie-gao avatar brianmc avatar dhimandeepak avatar djvaldez avatar gauravmokhasi avatar mahendya1002 avatar senagant 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  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  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  avatar  avatar  avatar  avatar

cybersource-sdk-php's Issues

XML Parsing Error

This is my XML

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="urn:schemas-cybersource-com:transaction-data-1.120" xmlns:tns="urn:schemas-cybersource-com:transaction-data:TransactionProcessor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.120">
         <merchantReferenceCode>Unknown</merchantReferenceCode>
         <purchaseTotals>
            <currency>USD</currency>
            <grandTotalAmount>5.55</grandTotalAmount>
         </purchaseTotals>
         <billTo>
            <firstName>John</firstName>
            <lastName>Tester</lastName>
            <street1>123 Main Street</street1>
            <city>Columbia</city>
            <state>Sindh</state>
            <postalCode>75080</postalCode>
            <country>PK</country>
            <email>[email protected]</email>
            <ipAddress>0.0.0.0</ipAddress>
         </billTo>
         <card>
            <accountNumber>4111111111111111</accountNumber>
            <expirationMonth>12</expirationMonth>
            <expirationYear>2018</expirationYear>
            <cvNumber>111</cvNumber>
         </card>
      </requestMessage>
   </soap:Body>
</soap:Envelope>

Not sure why its throwing a Parsing Error. Is it because its wrapped in a <soap:envelope> and <soap:Body> tags

Refunds

How to implement refunds using SOAP? Any PHP example would be appreciated. Thanks.

runTransaction

I can not seem to find the runTransaction method declared anywhere. Could you point me to where it is declared.

UsernameToken authentication failed error while using composer for sdk php

I was repeatedly getting the following error while using composer autoloader:

PHP Fatal error:  Uncaught SoapFault exception: [wsse:FailedCheck]
Security Data : UsernameToken authentication failed.
 in /var/www/ca/3d/cybsource/samples/Sale.php:51
Stack trace:
#0 /var/www/ca/3dd/cybsource/samples/Sale.php(51): SoapClient->__call('runTransaction', Array)
#1 {main}
  thrown in /var/www/ca/3d/cybsource/samples/Sale.php on line 51

It was resolved when I loaded it manually via CybsSoapClient.php instead of using autoloader.

I am guessing it has something to do with autloader using wrong directory path, since the directory paths are correctly named in CybsClient.php and thus no error with it.

getting error message via error code in API not manually

I wan to get error message from payment reject error code.
I want this message in differnt language. I have seen in api doc that they are providing locale.
How do I get error message not error code via API not custom message. Is there any API available for this?

How to pass custom params? Because not receiving same in response .

Hello , before runTransaction I added custom params/data fields,
but not receiving them back in response,

$definedData = new \stdClass();
$definedData->field1 = "123";
$definedData->field2 = "ABC";
$definedData->field3 = "4";
$request->MerchantDefinedData =$definedData;

Do help me on this.

Thanks in advance.

Does the subscription sample still work?

Use a sandbox merchant ID to test subscription, it was always return the error code 150, I can got detail errors from sandbox manger pane:

Recurring Billing or Secure Storage service is not enabled for the merchant

or 

Misconfigured paymentech processor

what happened with that? so how can I enable the recurring permission on my sandbox account?

Thanks.

Cybs.ini should be picked up from current or configurable directory

Having cybs.ini inside the sdk itself is great for tests and built-in samples but you really want to have the configuration within your application. In addition if you use something like Azure/heroku auto-deploys you really can't change anything in the SDK/vendor dirs.

What I was able to do to work around was just set the include path to the current dir, where my config was and maybe that's enough if it is documented.

set_include_path(getcwd());

XML parse exception is thrown when subsequentAuth tag is passed in TransactionProcessor request for Cybersource

Iam getting SOAP fault exception : XML parse error when passing subsequentAuth tag in the XML payload.

Endpoint used: https://ics2wstesta.ic3.com/commerce/1.x/transactionProcessor/

XML request used:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken>
            <wsse:Username>steelbrickbilling</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">**MASKED**</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </s:Header>
   <s:Body>
      <requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.161">
         <merchantID>steelbrickbilling</merchantID>
         <subsequentAuth>true</subsequentAuth>
         <merchantReferenceCode>steelbrickbilling</merchantReferenceCode>
         <purchaseTotals>
            <currency>USD</currency>
            <grandTotalAmount>5</grandTotalAmount>
         </purchaseTotals>
         <recurringSubscriptionInfo>
            <subscriptionID>**MASKED**</subscriptionID>
         </recurringSubscriptionInfo>
         <ccAuthService run="true">
            <authType>AUTOCAPTURE</authType>
         </ccAuthService>
         <ccCaptureService run="true" />
      </requestMessage>
   </s:Body>
</s:Envelope>

Response:

HTTP/1.1 500 Internal Server Error
Server=Apache-Coyote/1.1
X-OPNET-Transaction-Trace=a2_79ec7399-e512-4ccd-b261-c1085012c3de
Strict-Transport-Security=max-age=31536000
X-Frame-Options=DENY
X-Content-Type-Options=nosniff
X-XSS-Protection=1; mode=block
v-c-response-time=1580829613
Content-Type=text/xml
Content-Length=773
Date=Tue, 04 Feb 2020 15:20:13 GMT
X-Cnection=close

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-216660870"><wsu:Created>2020-02-04T15:20:13.702Z</wsu:Created></wsu:Timestamp></wsse:Security></soap:Header>
<soap:Body>
<soap:Fault xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:c="urn:schemas-cybersource-com:transaction-data-1.0">
<faultcode>soap:Client</faultcode>
<faultstring>
XML parse error.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>

However, the same request works when subsequentAuth tag is removed from the request. Please suggest a fix.

Error - General system failure (150)

The merchant_id and transaction keys has been setup properly. But when i create transaction response from cybersource is General system failure (150). What is missing? thanks

empty XML field causes PHP Catchable fatal error

Observed behavior:
with a billTo block in an XML request like this:

  <billTo>
    <firstName>Friday</firstName>
    <lastName>Test</lastName>
    <street1>123 Test St</street1>
    <street2></street2>
    <city>My City</city>
    <state>CA</state>
    <postalCode>12345</postalCode>
    <country>US</country>
    <email>[email protected]</email>
    <customerID>56</customerID>
  </billTo>

I get
PHP Catchable fatal error: Object of class stdClass could not be converted to string in lib/CybsSoapClient.php on line 89
This is because the street2 field has no data. Removing that field causes the request to succeed.

Expected behavior:
the request will succeed even with an empty field.

NVP reply would be great as a dictionary

Right now its just a big string. Some simple processing in the NVP client could return an array. e.g.

$reply_array = explode("\n", $reply);

foreach($reply_array as $val) {
$item_array = explode("=", $val, 2);
$reply_dictionary[$item_array[0]] = $item_array[1];
}

now you can access the reply just like the request: $reply['name']

missingField ics_applications

Hello! I'm trying use runTransactionFromXml but when but when execute return this message from desision manager:

REJECT
missingField => ics_applications

How to add field in xml string?

I run the subscription.php example and I have the same message

Thanks for your help.

Namespaces

Why does the clients live in the global namespace?

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.