use PayPal\Api\ShippingAddress;
$agreement = new Agreement();
$now = new DateTime();
$now->add(DateInterval::createFromDateString('10 hour'));
$agreement->setName('Base Agreement')->setDescription($agree_desc)->setStartDate($now->format('Y-m-d') . 'T' . $now->format('G:i:s') . 'Z');
//    ->setStartDate('2019-06-17T9:45:04Z');
// Add Plan ID
// Please note that the plan Id should be only set in this case.
$plan = new Plan();
$plan->setId($plan_id);
$agreement->setPlan($plan);
// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
$agreement->setDescription($agree_desc . ". ID: {$user_id}");
// Add Shipping Address
//$shippingAddress = new ShippingAddress();
//$shippingAddress->setLine1('111 First Street')
//    ->setCity('Saratoga')
//    ->setState('CA')
//    ->setPostalCode('95070')
//    ->setCountryCode('US');
//$agreement->setShippingAddress($shippingAddress);
//$merchant_override_pref = new \PayPal\Api\MerchantPreferences();
//$merchant_override_pref->setReturnUrl(getBaseUrl(). "pp/billing/UpdateBillingAgreement.php?user_id=$user_id");
//$agreement->setOverrideMerchantPreferences($merchant_override_pref);
// For Sample Purposes Only.
$request = clone $agreement;
// ### Create Agreement
try {
Esempio n. 2
0
 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);
 }