Giter Club home page Giter Club logo

php-crm-toolkit's Introduction

php-crm-toolkit

CRM Toolkit for PHP provides integration with Microsoft Dynamics CRM in PHP applications.

This toolkit supports only Dynamics 365 SOAP interface. For PHP implementation of the Dynamics 365 Web API, see dynamics-webapi-toolkit project.

Installation

Install the latest version with

$ composer require alexacrm/php-crm-toolkit:dev-master

Examples

/**
 * Use init.php if you didn't install the package via Composer
 */
require_once 'vendor/autoload.php';

use AlexaCRM\CRMToolkit\Client as OrganizationService;
use AlexaCRM\CRMToolkit\Settings;

$contactId = '1d2fc62f-1c56-448b-b546-edfb6d6fec5c';
/* 
* WS-Trust is now deprecated 

$options = [
    'serverUrl' => 'https://org.crmN.dynamics.com',
    'username' => '[email protected]',
    'password' => 'portalPassword',
    'authMode' => 'OnlineFederation',
];

$serviceSettings = new Settings( $options );

*/

$options = [
	'serverUrl' => 'https://org.crmN.dynamics.com',
	'applicationId' => '1111c62f-dead-beef-dead-edfbffffec5c',
	'clientSecret' => 'whateveristhesecretgenerated',
	'authMode' => 'OnlineFederation',
	'authMethod' => 'sharedSecretAuth',
	'cache' => new AlexaCRM\CRMToolkit\NullCache(),
];

// This code uses NullCache which allows to connect and run the operations 
// but it is very inefficient and should not be used in production. 
// You can use any PSR-6 compliant cache implementation. 
$serviceSettings = new OnlineS2SSecretAuthenticationSettings( $options );
$service = new OrganizationService( $serviceSettings );

// retrieve a contact and update its fields
$contact = $service->entity( 'contact', $guid );
$contact->firstname = explode( '@', $contact->emailaddress1 )[0];
$contact->update();
printf( 'Info for %s %s updated.', $contact->firstname, $contact->lastname );

// create a new contact
$contact = $service->entity( 'contact' );
$contact->firstname = 'John';
$contact->lastname = 'Doe';
$contact->emailaddress1 = '[email protected]';
$contactId = $contact->create();

// delete a contact
$contact->delete();

// execute an action
$whoAmIResponse = $service->executeAction( 'WhoAmI' );
echo 'Organization ID: ' . $whoAmIResponse->OrganizationId;

// inject cache repo
// must be instance of AlexaCRM\CRMToolkit\CacheInterface
$cacheRepo = Cache::instance();
$service = new Client( $serviceSettings, $cacheRepo );

In /examples/ you can find a few examples of toolkit usage. Copy config.example.php to config.php, set up credentials for your CRM and you are ready to go!

Contributing

Pull requests are gladly accepted in the GitHub repository.

License

Copyright (c) 2016 AlexaCRM.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Lesser Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.

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.