public function init($arr = null) { if ($arr != null) { foreach ($arr as $arry) { if ($arry != null && isset($arry['text']) && $arry['name'] == 'custom') { $this->Custom = $arry["text"]; } if ($arry != null && isset($arry['text']) && $arry['name'] == 'invoiceid') { $this->InvoiceID = $arry["text"]; } if (is_array($arry["children"]) && $arry["children"] != null) { if ($arry["name"] == 'payerinfo') { $this->PayerInfo = new PayerInfoType(); $this->PayerInfo->init($arry["children"]); } } if (is_array($arry["children"]) && $arry["children"] != null) { if ($arry["name"] == 'paymentinfo') { $this->PaymentInfo = new PaymentInfoType(); $this->PaymentInfo->init($arry["children"]); } } } } }
public function purchase() { // Note, we used to add extensions/ to include_path here, that should either // be standardized in Loader or we need to load more files here to make // up for whatever the PayPal code would otherwise try to load require_once 'extensions/PayPal.php'; require_once 'extensions/PayPal/Profile/Handler/Array.php'; require_once 'extensions/PayPal/Profile/API.php'; require_once 'extensions/PayPal/Type/DoDirectPaymentRequestType.php'; require_once 'extensions/PayPal/Type/DoDirectPaymentRequestDetailsType.php'; require_once 'extensions/PayPal/Type/DoDirectPaymentResponseType.php'; // Add all of the types require_once 'extensions/PayPal/Type/BasicAmountType.php'; require_once 'extensions/PayPal/Type/PaymentDetailsType.php'; require_once 'extensions/PayPal/Type/AddressType.php'; require_once 'extensions/PayPal/Type/CreditCardDetailsType.php'; require_once 'extensions/PayPal/Type/PayerInfoType.php'; require_once 'extensions/PayPal/Type/PersonNameType.php'; require_once 'extensions/PayPal/CallerServices.php'; $environment = $this->live ? 'live' : 'sandbox'; $dp_request = new DoDirectPaymentRequestType(); $OrderTotal = new BasicAmountType(); $OrderTotal->setattr('currencyID', 'USD'); $OrderTotal->setval($this->amount, 'iso-8859-1'); $PaymentDetails = new PaymentDetailsType(); $PaymentDetails->setOrderTotal($OrderTotal); $shipTo = new AddressType(); $shipTo->setName($this->firstName . ' ' . $this->lastName); $shipTo->setStreet1($this->address1); $shipTo->setStreet2($this->address2); $shipTo->setCityName($this->city); $shipTo->setStateOrProvince($this->state); $shipTo->setCountry('US'); $shipTo->setPostalCode($this->zip); $PaymentDetails->setShipToAddress($shipTo); $dp_details = new DoDirectPaymentRequestDetailsType(); $dp_details->setPaymentDetails($PaymentDetails); // Credit Card info $card_details = new CreditCardDetailsType(); $card_details->setCreditCardType($this->creditCardType); $card_details->setCreditCardNumber($this->creditCardNumber); $card_details->setExpMonth($this->expirationMonth); $card_details->setExpYear($this->expirationYear); $card_details->setCVV2($this->cvv2Number); $payer = new PayerInfoType(); $person_name = new PersonNameType(); $person_name->setFirstName($this->firstName); $person_name->setLastName($this->lastName); $payer->setPayerName($person_name); $payer->setPayerCountry('US'); $payer->setAddress($shipTo); $card_details->setCardOwner($payer); $dp_details->setCreditCard($card_details); $dp_details->setIPAddress($_SERVER['SERVER_ADDR']); $dp_details->setPaymentAction('Sale'); $dp_request->setDoDirectPaymentRequestDetails($dp_details); $handler = ProfileHandler_Array::getInstance(array('username' => $this->apiUsername, 'certificateFile' => null, 'subject' => null, 'environment' => $environment)); $pid = ProfileHandler::generateID(); $profile = new APIProfile($pid, $handler); $profile->setAPIUsername($this->apiUsername); $profile->setAPIPassword($this->apiPassword); $profile->setSignature($this->apiSignature); $profile->setEnvironment($environment); $caller = new CallerServices($profile); $response = $caller->DoDirectPayment($dp_request); if (PayPal::isError($response)) { Site::getPage()->addWarning($response->message); return false; } if ($response->Ack == 'Success') { return true; } if (is_array($response->Errors)) { foreach ($response->Errors as $error) { Site::getPage()->addWarning($error->LongMessage); } } else { Site::getPage()->addWarning($response->Errors->LongMessage); } return false; }