diff --git a/README.md b/README.md index 2fe4649..b4d1727 100755 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Description: For making PayPal API calls with ease ```php // PayPalHelper construct (with endpoint url and version passed) -$PayPalHelper = new PayPalHelper("https://api-3t.sandbox.paypal.com/nvp", "109.0"); +$PayPalHelper = new PayPalHelper("https://api-3t.sandbox.paypal.com/nvp", "202"); // Config that will be passed to all API calls $PayPalHelper->SetConfig(array( @@ -33,24 +33,28 @@ else **Example of using different modes** +Note that ENDPOINT is a special config property that will override the default passed in the constructor. + ```php // Define PayPal config modes define("SANDBOXMODE", 0); define("LIVEMODE", 1); -// PayPalHelper construct (with endpoint url and version passed) -$PayPalHelper = new PayPalHelper("https://api-3t.sandbox.paypal.com/nvp", "109.0"); +// PayPalHelper construct (no endpoint or version passed, version is currently 202 by default) +$PayPalHelper = new PayPalHelper(); // Set sandbox config -$PayPalHelper->SetConfig(array( +$PayPalHelper->SetConfig(array( + "ENDPOINT" => "https://api-3t.sandbox.paypal.com/nvp", "USER" => "SANDBOX-USERNAME", "PWD" => "SANDBOX-PASSWORD", "SIGNATURE" => "SANDBOX-SIGNATURE" ), SANDBOXMODE); // Set live config -$PayPalHelper->SetConfig(array( +$PayPalHelper->SetConfig(array( + "ENDPOINT" => "https://api-3t.paypal.com/nvp", "USER" => "USERNAME", "PWD" => "PASSWORD", "SIGNATURE" => "SIGNATURE" diff --git a/class.paypalhelper.php b/class.paypalhelper.php index 1295ebc..d645902 100755 --- a/class.paypalhelper.php +++ b/class.paypalhelper.php @@ -12,7 +12,7 @@ class PayPalHelper public $Result; // Construct - public function __construct($Endpoint = "", $Version = "109.0") + public function __construct($Endpoint = "", $Version = "202") { $this->SetMode(0); $this->SetEndpoint($Endpoint); @@ -80,6 +80,14 @@ public function GetVersion() public function SetMode($Mode) { $this->Mode = $Mode; + + // Update endpoint if set in this config mode + if(isset($this->Config[$this->Mode]["ENDPOINT"]) + && is_string($this->Config[$this->Mode]["ENDPOINT"]) + && strlen($this->Config[$this->Mode]["ENDPOINT"]) > 0) + { + $this->Endpoint = $this->Config[$this->Mode]["ENDPOINT"]; + } } /* @@ -127,6 +135,13 @@ public function DoCall() // Get all parameters $Args = func_get_args(); + // Unset ENDPOINT in if set so it doesn't get passed as an option + if(isset($this->Config[$this->Mode]["ENDPOINT"])) + { + $this->Endpoint = $this->Config[$this->Mode]["ENDPOINT"]; + unset($this->Config[$this->Mode]["ENDPOINT"]); + } + // Apply VERSION and current config array to RequestParams $RequestParams = array_merge( array("VERSION" => $this->Version), @@ -175,6 +190,10 @@ public function DoCall() else $this->Success = false; + // Put ENDPOINT back into array + if(isset($this->Endpoint)) + $this->Config[$this->Mode]["ENDPOINT"] = $this->Endpoint; + return $this->Result; } }