· 7 years ago · Aug 14, 2018, 02:16 PM
1{
2 "name": "BUSINESS_VALIDATION_ERROR",
3 "details": [
4 {
5 "field": "validation_error",
6 "issue": "Incorrect Plan Id."
7 }
8 ],
9 "message": "Validation Error.",
10 "information_link": "https://developer.paypal.com/docs/api/payments.billing-agreements#errors",
11 "debug_id": "xxxxxxxxxxxx"
12}
13
141. public function createAgreement($planId, $startDate = null)
152. {
163. $agreement = new Agreement();
174.
185. $startDate = $startDate ?: new DateTime('+1 hour');
196.
207. if ($startDate < new DateTime()) {
218. $startDate = new DateTime('+1 hour');
229. }
2310.
2411. $agreement->setName('Base Agreement')
2512. ->setDescription('Basic Agreement')
2613. ->setStartDate($startDate->format('c'));
2714.
2815. // Add Plan ID
2916. // Please note that the plan Id should be only set in this case.
3017. $plan = new Plan();
3118. $plan->setId($planId);
3219. $agreement->setPlan($plan);
3320.
3421. // Add Payer
3522. $payer = new Payer();
3623. $payer->setPaymentMethod('paypal');
3724. $agreement->setPayer($payer);
3825.
3926. // Add Shipping Address
4027. // $shippingAddress = new ShippingAddress();
4128. // $shippingAddress->setLine1('111 First Street')
4229. // ->setCity('Saratoga')
4330. // ->setState('CA')
4431. // ->setPostalCode('95070')
4532. // ->setCountryCode('US');
4633. // $agreement->setShippingAddress($shippingAddress);
4734.
4835.
4936. // ### Create Agreement
5037. try {
5138. // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
5239. $temp = $this->getApiContext();
5340. $agreement = $agreement->create( $temp );
5441.
5542. } catch (Exception $ex) {
5643. throw $ex;
5744. }
5845.
5946. return $agreement;
6047. }
61
62$temp = {PayPalRestApiContext} [2]
63 requestId = null
64 credential = {PayPalAuthOAuthTokenCredential} [11]
65 CACHE_PATH = "/../../../var/auth.cache"
66 AUTH_HANDLER = "PayPalHandlerOauthHandler"
67 expiryBufferTime = 120
68 credential = null
69 clientId = "xxxx"
70 clientSecret = "xxxx"
71 accessToken = null
72 tokenExpiresIn = null
73 tokenCreateTime = null
74 cipher = {PayPalSecurityCipher} [1]
75 secretKey = "xxxx"
76 *PayPalCommonPayPalModel*_propMap = {array} [0]
77
78/**
79 * Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON.
80 *
81 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
82 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
83 * @return Agreement
84 */
85public function create($apiContext = null, $restCall = null)
86{
87 $payLoad = $this->toJSON();
88 $json = self::executeCall(
89 "/v1/payments/billing-agreements/",
90 "POST",
91 $payLoad,
92 null,
93 $apiContext,
94 $restCall
95 );
96 $this->fromJson($json);
97 return $this;
98}
99
1001. /**
1012. * @param array $handlers Array of handlers
1023. * @param string $path Resource path relative to base service endpoint
1034. * @param string $method HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
1045. * @param string $data Request payload
1056. * @param array $headers HTTP headers
1067. * @return mixed
1078. * @throws PayPalExceptionPayPalConnectionException
1089. */
10910. public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
11011. {
11112. $config = $this->apiContext->getConfig();
11213. $httpConfig = new PayPalHttpConfig(null, $method, $config);
11314. $headers = $headers ? $headers : array();
11415. $httpConfig->setHeaders($headers +
11516. array(
11617. 'Content-Type' => 'application/json'
11718. )
11819. );
11920.
12021. // if proxy set via config, add it
12122. if (!empty($config['http.Proxy'])) {
12223. $httpConfig->setHttpProxy($config['http.Proxy']);
12324. }
12425.
12526. /** @var PaypalHandlerIPayPalHandler $handler */
12627. foreach ($handlers as $handler) {
12728. if (!is_object($handler)) {
12829. $fullHandler = "\" . (string)$handler;
12930. $handler = new $fullHandler($this->apiContext);
13031. }
13132. $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
13233. }
13334. $connection = new PayPalHttpConnection($httpConfig, $config);
13435. $response = $connection->execute($data);
13536.
13637. return $response;
13738. }
138
139{
140 "name": "Base Agreement",
141 "description": "Basic Agreement",
142 "start_date": "2018-08-14T17:01:25+03:00",
143 "plan": {
144 "id": "P-03R665271A787135CPIXIURI"
145 },
146 "payer": {
147 "payment_method": "paypal"
148 }
149 }
150
151Content-Type = "application/json"
152 Expect = null
153 User-Agent = "PayPalSDK/PayPal-PHP-SDK 1.13.0 (platform-ver=7.1.12; bit=32; os=Windows_NT_10.0; machine=i586; crypto-lib-ver=1.0.2m; curl=7.56.0)"
154 Authorization = "Bearer LONG-LONG-TOCKEN"
155
156{
157 "name": "BUSINESS_VALIDATION_ERROR",
158 "details": [
159 {
160 "field": "validation_error",
161 "issue": "Incorrect Plan Id."
162 }
163 ],
164 "message": "Validation Error.",
165 "information_link": "https://developer.paypal.com/docs/api/payments.billing-agreements#errors",
166 "debug_id": "3e4eadccf0d9"
167 }
168
169paypal:
170 clientId: "xxxx"
171 clientSecret: "xxxxx"
172 mode: "sandbox"
173 LogEnabled: true
174 LogFileName: "%kernel.root_dir%/../var/logs/payPal.log"
175 LogLevel: "DEBUG" # PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
176 cache_enabled: false