setName('Base Agreement') ->setDescription('Basic Agreement') ->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($createdPlan->getId()); $agreement->setPlan($plan); // Add Payer $payer = new Payer(); $payer->setPaymentMethod('paypal'); $agreement->setPayer($payer); // Add Shipping Address $shippingAddress = new ShippingAddress(); $shippingAddress->setLine1('111 First Street') ->setCity('Saratoga') ->setState('CA') ->setPostalCode('95070') ->setCountryCode('US'); $agreement->setShippingAddress($shippingAddress); // For Sample Purposes Only. $request = clone $agreement; // ### Create Agreement try { // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet. $agreement = $agreement->create($apiContext); // ### Get redirect url // The API response provides the url that you must redirect // the buyer to. Retrieve the url from the $agreement->getApprovalLink() // method $approvalUrl = $agreement->getApprovalLink(); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Created Billing Agreement. Please visit the URL to Approve.", "Agreement", "$approvalUrl", $request, $agreement); return $agreement;