Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Making First Call

Jay edited this page Dec 22, 2015 · 14 revisions

Once you have completed the Installation, we could make the first call. To write an app that uses the SDK, we will create our first PHP script that will store a Credit Card in our Vault.

Instructions

First, Create file first.php in our project root location. You could alternatively copy the completed file here : first.php

  1. Autoload the SDK Package. This will include all the files and classes to your autoloader. Please note, If your downloaded our SDK using composer, replace PayPal-PHP-SDK with vendor. This applies for all sample code in our SDK.

setType("visa") ->setNumber("4417119669820331") ->setExpireMonth("11") ->setExpireYear("2019") ->setCvv2("012") ->setFirstName("Joe") ->setLastName("Shopper"); ``` 4. Make a Create Call and Print the Card ```php // After Step 3 try { $creditCard->create($apiContext); echo $creditCard; } catch (\PayPal\Exception\PayPalConnectionException $ex) { // This will print the detailed information on the exception. //REALLY HELPFUL FOR DEBUGGING echo $ex->getData(); } ``` 5. Run `php -f first.php` from command line. This will successfully create a credit card in your vault. The output would look similar to this: ```sh > php -f first.php { "type": "visa", "number": "xxxxxxxxxxxx0331", "expire_month": "11", "expire_year": "2019", "cvv2": "012", "first_name": "Joe", "last_name": "Shopper", "id": "CARD-53D88620CF909614MKSYZJ5Q", "state": "ok", "valid_until": "2018-01-09T00:00:00Z", "create_time": "2015-01-10T21:09:10Z", "update_time": "2015-01-10T21:09:10Z", "links": [ { "href": "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-53D88620CF909614MKSYZJ5Q", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-53D88620CF909614MKSYZJ5Q", "rel": "delete", "method": "DELETE" }, { "href": "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-53D88620CF909614MKSYZJ5Q", "rel": "patch", "method": "PATCH" } ] } ``` ##### NOTE * To reduce redundant code and minimize security risks, you could create a file `bootstrap.php` and move step 1 and 2 there, and just `include` bootstrap.php. * All the calls made currently are defaulted to sandbox environment. Sandbox Environment replicates the exact behavior you get from our PayPal APIs, but here, it allows you to create dummy accounts and test your integration, before running your code on live PayPal APIs. For more information visit Developer Portal ## Next Step * Adding Configurations