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']; }
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); }
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"); $card->setLast_name("Shopper"); $card->setBilling_address($addr); // ### FundingInstrument // A resource representing a Payer's funding instrument. // Use a Payer ID (A unique identifier of the payer generated