public static function createAddress() { $addr = new Address(); $addr->setLine1(self::$line1); $addr->setLine2(self::$line2); $addr->setCity(self::$city); $addr->setState(self::$state); $addr->setPostalCode(self::$postalCode); $addr->setCountryCode(self::$countryCode); $addr->setPhone(self::$phone); return $addr; }
public static function authorize() { $addr = new Address(); $addr->setLine1("3909 Witmer Road"); $addr->setLine2("Niagara Falls"); $addr->setCity("Niagara Falls"); $addr->setState("NY"); $addr->setPostalCode("14305"); $addr->setCountryCode("US"); $addr->setPhone("716-298-1822"); $card = new CreditCard(); $card->setType("visa"); $card->setNumber("4417119669820331"); $card->setExpireMonth("11"); $card->setExpireYear("2019"); $card->setCvv2("012"); $card->setFirstName("Joe"); $card->setLastName("Shopper"); $card->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod("credit_card"); $payer->setFundingInstruments(array($fi)); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription("This is the payment description."); $payment = new Payment(); $payment->setIntent("authorize"); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $paymnt = $payment->create(); $resArray = $paymnt->toArray(); return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; }
function complete_cart($order_exists = true) { global $insert_id; // check $check_query = xtc_db_query("SELECT * \n FROM " . TABLE_PAYPAL_PAYMENT . "\n WHERE payment_id = '" . xtc_db_input($_SESSION['paypal']['paymentId']) . "'"); if (xtc_db_num_rows($check_query) > 0) { $status_id = $this->order_status_tmp; if ($status_id < 0) { $check_query = xtc_db_query("SELECT orders_status\n FROM " . TABLE_ORDERS . " \n WHERE orders_id = '" . (int) $insert_id . "'"); $check = xtc_db_fetch_array($check_query); $status_id = $check['orders_status']; } $this->update_order('duplicate call, cancel', $status_id, $insert_id); return; } // auth $apiContext = $this->apiContext(); try { // Get the payment Object by passing paymentId $payment = Payment::get($_SESSION['paypal']['paymentId'], $apiContext); } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $this->remove_order($insert_id); unset($_SESSION['paypal']); unset($_SESSION['tmp_oID']); xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL')); } // set order $order = new order($insert_id); $patches_array = array(); $patchRequest = new PatchRequest(); $payment_address = new Address(); $payment_address->setLine1($this->encode_utf8($order->billing['street_address']))->setCity($this->encode_utf8($order->billing['city']))->setState($this->encode_utf8($order->billing['state'] != '' ? xtc_get_zone_code($order->billing['country_id'], $order->billing['zone_id'], $order->billing['state']) : ''))->setPostalCode($this->encode_utf8($order->billing['postcode']))->setCountryCode($this->encode_utf8(isset($order->billing['country_iso_2']) ? $order->billing['country_iso_2'] : $order->billing['country']['iso_code_2'])); if ($order->billing['suburb'] != '') { $payment_address->setLine2($this->encode_utf8($order->billing['suburb'])); } $patch_payment = new Patch(); $patch_payment->setOp('add')->setPath('/potential_payer_info/billing_address')->setValue($payment_address); $patches_array[] = $patch_payment; // set address $shipping_address = new ShippingAddress(); $shipping_address->setRecipientName($this->encode_utf8($order->delivery['firstname'] . ' ' . $order->delivery['lastname']))->setLine1($this->encode_utf8($order->delivery['street_address']))->setCity($this->encode_utf8($order->delivery['city']))->setCountryCode($this->encode_utf8(isset($order->delivery['country_iso_2']) ? $order->delivery['country_iso_2'] : $order->delivery['country']['iso_code_2']))->setPostalCode($this->encode_utf8($order->delivery['postcode']))->setState($this->encode_utf8($order->delivery['state'] != '' ? xtc_get_zone_code($order->delivery['country_id'], $order->delivery['zone_id'], $order->delivery['state']) : '')); if ($order->delivery['suburb'] != '') { $shipping_address->setLine2($this->encode_utf8($order->delivery['suburb'])); } $patch_shipping = new Patch(); $patch_shipping->setOp('add')->setPath('/transactions/0/item_list/shipping_address')->setValue($shipping_address); $patches_array[] = $patch_shipping; $patch_invoice = new Patch(); $patch_invoice->setOp('replace')->setPath('/transactions/0/invoice_number')->setValue($this->get_config('PAYPAL_CONFIG_INVOICE_PREFIX') . $insert_id); $patches_array[] = $patch_invoice; // set details $this->details = new Details(); // set amount $this->amount = new Amount(); // set totals $this->get_totals($order->totals); $this->amount->setCurrency($order->info['currency'])->setDetails($this->details); $patch_amount = new Patch(); $patch_amount->setOp('replace')->setPath('/transactions/0/amount')->setValue($this->amount); $patches_array[] = $patch_amount; // set ItemList if ($this->get_config('PAYPAL_ADD_CART_DETAILS') == '0' || $this->check_discount() === true) { $item = array(); $item[0] = new Item(); $item[0]->setName($this->encode_utf8(MODULE_PAYMENT_PAYPAL_TEXT_ORDER))->setCurrency($order->info['currency'])->setQuantity(1)->setPrice($this->details->getSubtotal()); } else { for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { $item[$i] = new Item(); $item[$i]->setName($this->encode_utf8($order->products[$i]['name']))->setCurrency($order->info['currency'])->setQuantity($order->products[$i]['qty'])->setPrice($order->products[$i]['price'])->setSku($order->products[$i]['model'] != '' ? $order->products[$i]['model'] : $order->products[$i]['id']); } } $patch_items = new Patch(); $patch_items->setOp('replace')->setPath('/transactions/0/item_list/items')->setValue($item); $patches_array[] = $patch_items; $patchRequest->setPatches($patches_array); try { // update payment $payment->update($patchRequest, $apiContext); } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); if ($order_exists === false) { unset($_SESSION['paypal']); xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL')); } $this->remove_order($insert_id); unset($_SESSION['paypal']); unset($_SESSION['tmp_oID']); xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL')); } $payment = Payment::get($_SESSION['paypal']['paymentId'], $apiContext); // PaymentExecution $execution = new PaymentExecution(); $execution->setPayerId($_SESSION['paypal']['PayerID']); try { // Execute the payment $payment->execute($execution, $apiContext); } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $this->remove_order($insert_id); unset($_SESSION['paypal']); unset($_SESSION['tmp_oID']); xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL')); } // capture if (($this->transaction_type == 'order' || $this->transaction_type == 'authorize') && $this->get_config('PAYPAL_CAPTURE_MANUELL') == '0') { $this->capture_payment($payment); } $sql_data_array = array('orders_id' => $insert_id, 'payment_id' => $_SESSION['paypal']['paymentId'], 'payer_id' => $_SESSION['paypal']['PayerID']); xtc_db_perform(TABLE_PAYPAL_PAYMENT, $sql_data_array); try { // Get the payment Object by passing paymentId $payment = Payment::get($_SESSION['paypal']['paymentId'], $apiContext); } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $this->remove_order($insert_id); unset($_SESSION['paypal']); unset($_SESSION['tmp_oID']); xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'NONSSL')); } $status = $this->get_orders_status($payment); if ($status['status_id'] < 0) { $check_query = xtc_db_query("SELECT orders_status\n FROM " . TABLE_ORDERS . " \n WHERE orders_id = '" . (int) $insert_id . "'"); $check = xtc_db_fetch_array($check_query); $status['status_id'] = $check['orders_status']; } $this->update_order($status['comment'], $status['status_id'], $insert_id); }
/** * Creates an address object * * @param OrderInterface $order * * @return Address */ protected function createAddress(OrderInterface $order) : Address { $address = new Address(); $address->setLine1($order->getBillingAddress()->getLine1()); $address->setLine2($order->getBillingAddress()->getLine2()); $address->setCity($order->getBillingAddress()->getCity()); $address->setPostalCode($order->getBillingAddress()->getPostalCode()); $address->setCountryCode($order->getBillingAddress()->getCountry()); return $address; }
public function createBillingAgreement($planId, $shippingAddress, $billingAddress, $productName, $cartSummary, $cardDetails, $apiContext) { $billingPlanDefaultValues = $this->getBillingPlanDefaultValues(); $billingAgreement = new Agreement(); $billingAgreement->setName('Billing Agreement For ' . $productName); $billingAgreement->setDescription($cartSummary->paymentPlanTitle); $startDate = new Zend_Date(); $startDate->addDay($billingPlanDefaultValues->startDateInterval); $billingAgreement->setStartDate($startDate->get(Zend_Date::ISO_8601)); $payerInfo = new PayerInfo(); $payerInfo->setFirstName($billingAddress->firstname); $payerInfo->setLastName($billingAddress->lastname); $payerInfo->setEmail($billingAddress->emailAddress); /* Fields not supported yet */ //$payerInfo->setEmail($cart->address->billing['billing_email']); //$payerInfo->setPhone($cart->address->billing['billing_contactNo']); /* Get a MALFORMED_REQUEST error when using this field */ //$payerInfo->setCountryCode($cart->address->billing['billing_countryCode']); $cardName = $cardDetails->cardName; $cardNumber = $cardDetails->cardNumber; $cardType = strtolower($cardDetails->cardType); $cardExpiryMonth = $cardDetails->cardExpiryMonth; $cardExpiryYear = $cardDetails->cardExpiryYear; $cardSecurityCode = $cardDetails->cardSecurityCode; $nameParser = new Om_Model_Name(); $name = $nameParser->parse_name($cardName); $card = new CreditCard(); $card->setType($cardType); $card->setNumber($cardNumber); $card->setExpireMonth($cardExpiryMonth); $card->setExpireYear($cardExpiryYear); $card->setCvv2($cardSecurityCode); $card->setFirstName($name['fname']); $card->setLastName($name['lname']); $fundingInstrument = new FundingInstrument(); $fundingInstrument->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod("credit_card"); $payer->setFundingInstruments(array($fundingInstrument)); $payer->setPayerInfo($payerInfo); $billingAgreement->setPayer($payer); $shippingAddressPayPal = new Address(); $shippingAddressPayPal->setLine1($shippingAddress->addressLine1); $shippingAddressPayPal->setLine2($shippingAddress->addressLine2 . ' ' . $shippingAddress->addressLine3); $shippingAddressPayPal->setCity($shippingAddress->city); $shippingAddressPayPal->setCountryCode($shippingAddress->getCountry()->code); $shippingAddressPayPal->setPostalCode($shippingAddress->postcode); $shippingAddressPayPal->setState($shippingAddress->county); $shippingAddressPayPal->setPhone($shippingAddress->contactNumber); $billingAgreement->setShippingAddress($shippingAddressPayPal); $plan = new Plan(); $plan->setId($planId); $billingAgreement->setPlan($plan); return $billingAgreement->create($apiContext); }
// a payment with a credit card. // API used: /v1/payments/payment require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Address; use PayPal\Api\Amount; use PayPal\Api\CreditCard; use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; // ### Address // Base Address object used as shipping or billing // address in a payment. [Optional] $addr = new Address(); $addr->setLine1("3909 Witmer Road"); $addr->setLine2("Niagara Falls"); $addr->setCity("Niagara Falls"); $addr->setState("NY"); $addr->setPostal_code("14305"); $addr->setCountry_code("US"); $addr->setPhone("716-298-1822"); // ### CreditCard // A resource representing a credit card that can be // used to fund a payment. $card = new CreditCard(); $card->setType("visa"); $card->setNumber("4417119669820331"); $card->setExpire_month("11"); $card->setExpire_year("2019"); $card->setCvv2("012"); $card->setFirst_name("Joe");
/** * [execTransaction description] * * Pass in array of data, get Paypal transaction result * * @param array $paramData [description] * @return [type] [description] */ public function execTransaction(array $paramData) { if (is_array($this->checkTransactionData($paramData))) { // to do collapse multi recursive errors into a string - DJE - 2015-11-28 \Yii::$app->getSession()->addFlash('warning', current($paramData) . ' missing.'); return \Yii::$app->response->redirect(\yii::$app->request->referrer); } $addr = new Address(); $addr->setLine1($paramData['Address']['Line1']); $addr->setLine2($paramData['Address']['Line2']); $addr->setCity($paramData['Address']['City']); $addr->setCountryCode($paramData['Address']['CountryCode']); $addr->setPostalCode($paramData['Address']['PostalCode']); $addr->setState($paramData['Address']['State']); $card = new CreditCard(); $card->setNumber($paramData['CreditCard']['Number']); $card->setType($paramData['CreditCard']['Type']); $card->setExpireMonth($paramData['CreditCard']['Month']); $card->setExpireYear($paramData['CreditCard']['Year']); $card->setCvv2($paramData['CreditCard']['Cvv2']); $card->setFirstName($paramData['CreditCard']['FirstName']); $card->setLastName($paramData['CreditCard']['LastName']); $card->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod(isset($paramData['Payer']['Method']) ? $paramData['Payer']['Method'] : 'credit_card'); $payer->setFundingInstruments(array($fi)); $amountDetails = new Details(); $amountDetails->setSubtotal(isset($paramData['Details']['SubTotal']) ? $paramData['Details']['SubTotal'] : 0); $amountDetails->setTax(isset($paramData['Details']['Tax']) ? $paramData['Details']['Tax'] : 0); $amountDetails->setShipping(isset($paramData['Details']['Shipping']) ? $paramData['Details']['Shipping'] : 0); $amount = new Amount(); $amount->setCurrency(isset($paramData['Amount']['Currency']) ? $paramData['Amount']['Currency'] : 'USD'); $amount->setTotal(isset($paramData['Amount']['Total']) ? $paramData['Amount']['Total'] : $this->getTotal($paramData)); $amount->setDetails($amountDetails); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription(isset($paramData['Transaction']['Description']) ? $paramData['Transaction']['Description'] : 'Online transaction.'); $payment = new Payment(); $payment->setIntent(isset($paramData['Payment']['Intent']) ? $paramData['Payment']['Intent'] : 'sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); return $payment->create($this->_apiContext); }
public function setPaypalAddress($line1, $line2, $city, $countryCode, $postalCode, $state) { $address = new Address(); $address->setLine1($line1); $address->setLine2($line2); $address->setCity($city); $address->setCountryCode($countryCode); $address->setPostalCode($postalCode); $address->setState($state); return $address; }