3 use PayPal\Exception\PPMissingCredentialException;
4 use PayPal\Auth\IPPCredential;
7 * Client certificate based credentials
9 class PPCertificateCredential extends IPPCredential {
24 * Path to PEM encoded API certificate on local filesystem
27 protected $certificatePath;
30 * Password used to protect the API certificate
33 protected $certificatePassPhrase;
36 * Application Id that uniquely identifies an application that uses the
37 * Platform APIs - Not required for Express Checkout / MassPay / DCC etc
38 * The application Id is issued by PayPal.
39 * Test application Ids are available for the sandbox environment
42 protected $applicationId;
45 * Constructs a new certificate credential object
47 * @param string $userName API username
48 * @param string $password API password
49 * @param string $certPath Path to PEM encoded client certificate file
50 * @param string $certificatePassPhrase password need to use the certificate
52 public function __construct($userName, $password, $certPath, $certificatePassPhrase=NULL) {
53 $this->userName = trim($userName);
54 $this->password = trim($password);
55 $this->certificatePath = trim($certPath);
56 $this->certificatePassPhrase = $certificatePassPhrase;
60 public function validate() {
62 if (empty($this->userName)) {
63 throw new PPMissingCredentialException("username cannot be empty");
65 if (empty($this->password)) {
66 throw new PPMissingCredentialException("password cannot be empty");
68 if (empty($this->certificatePath)) {
69 throw new PPMissingCredentialException("certificate cannot be empty");
73 public function getUserName() {
74 return $this->userName;
77 public function getPassword() {
78 return $this->password;
81 public function getCertificatePath() {
82 if (realpath($this->certificatePath)) {
83 return realpath($this->certificatePath);
84 } else if(defined('PP_CONFIG_PATH')) {
85 return constant('PP_CONFIG_PATH') . DIRECTORY_SEPARATOR . $this->certificatePath;
87 return realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . ".." .DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . $this->certificatePath);
91 public function getCertificatePassPhrase() {
92 return $this->certificatePassPhrase;
95 public function setApplicationId($applicationId) {
96 $this->applicationId = trim($applicationId);
99 public function getApplicationId() {
100 return $this->applicationId;