|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * PayPal REST List Plans Request |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Omnipay\PayPal\Message; |
| 7 | + |
| 8 | +/** |
| 9 | + * PayPal REST List Plans Request |
| 10 | + * |
| 11 | + * Use this call to get a list of plans in any state (CREATED, ACTIVE, etc.). |
| 12 | + * The plans returned are the plans made by the merchant making the call. |
| 13 | + * |
| 14 | + * |
| 15 | + * ### Example |
| 16 | + * |
| 17 | + * #### Initialize Gateway |
| 18 | + * |
| 19 | + * <code> |
| 20 | + * // Create a gateway for the PayPal RestGateway |
| 21 | + * // (routes to GatewayFactory::create) |
| 22 | + * $gateway = Omnipay::create('PayPal_Rest'); |
| 23 | + * |
| 24 | + * // Initialise the gateway |
| 25 | + * $gateway->initialize(array( |
| 26 | + * 'clientId' => 'MyPayPalClientId', |
| 27 | + * 'secret' => 'MyPayPalSecret', |
| 28 | + * 'testMode' => true, // Or false when you are ready for live transactions |
| 29 | + * )); |
| 30 | + * </code> |
| 31 | + * |
| 32 | + * #### List all plans that have state CREATED |
| 33 | + * <code> |
| 34 | + * |
| 35 | + * // List all billing plans |
| 36 | + * $transaction = $gateway->listPlan([ |
| 37 | + * 'state' => CREATED, |
| 38 | + * ]); |
| 39 | + * $response = $transaction->send(); |
| 40 | + * $data = $response->getData(); |
| 41 | + * echo "Gateway listPlan response data == " . print_r($data, true) . "\n"; |
| 42 | + * </code> |
| 43 | + * |
| 44 | + * ### Request Sample |
| 45 | + * |
| 46 | + * This is from the PayPal web site: |
| 47 | + * |
| 48 | + * <code> |
| 49 | + * curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=3&status=ACTIVE&page=1\ |
| 50 | + * -H "Content-Type:application/json" \ |
| 51 | + * -H "Authorization: Bearer Access-Token" |
| 52 | + * </code> |
| 53 | + * |
| 54 | + * ### Response Sample |
| 55 | + * |
| 56 | + * This is from the PayPal web site: |
| 57 | + * |
| 58 | + * <code> |
| 59 | + * { |
| 60 | + * "total_items": "166", |
| 61 | + * "total_pages": "83", |
| 62 | + * "plans": [ |
| 63 | + * { |
| 64 | + * "id": "P-7DC96732KA7763723UOPKETA", |
| 65 | + * "state": "ACTIVE", |
| 66 | + * "name": "Plan with Regular and Trial Payment Definitions", |
| 67 | + * "description": "Plan with regular and trial billing payment definitions.", |
| 68 | + * "type": "FIXED", |
| 69 | + * "create_time": "2017-08-22T04:41:52.836Z", |
| 70 | + * "update_time": "2017-08-22T04:41:53.169Z", |
| 71 | + * "links": [ |
| 72 | + * { |
| 73 | + * "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA", |
| 74 | + * "rel": "self", |
| 75 | + * "method": "GET" |
| 76 | + * } |
| 77 | + * ] |
| 78 | + * }, |
| 79 | + * { |
| 80 | + * "id": "P-1TV69435N82273154UPWDU4I", |
| 81 | + * "state": "ACTIVE", |
| 82 | + * "name": "Plan with Regular Payment Definition", |
| 83 | + * "description": "Plan with one regular payment definition, minimal merchant preferences, and no shipping fee", |
| 84 | + * "type": "INFINITE", |
| 85 | + * "create_time": "2017-08-22T04:41:55.623Z", |
| 86 | + * "update_time": "2017-08-22T04:41:56.055Z", |
| 87 | + * "links": [ |
| 88 | + * { |
| 89 | + * "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-1TV69435N82273154UPWDU4I", |
| 90 | + * "rel": "self", |
| 91 | + * "method": "GET" |
| 92 | + * } |
| 93 | + * ] |
| 94 | + * } |
| 95 | + * ], |
| 96 | + * "links": [ |
| 97 | + * { |
| 98 | + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=1&start=3&status=active", |
| 99 | + * "rel": "start", |
| 100 | + * "method": "GET" |
| 101 | + * }, |
| 102 | + * { |
| 103 | + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=0&status=active", |
| 104 | + * "rel": "previous_page", |
| 105 | + * "method": "GET" |
| 106 | + * }, |
| 107 | + * { |
| 108 | + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=2&status=active", |
| 109 | + * "rel": "next_page", |
| 110 | + * "method": "GET" |
| 111 | + * }, |
| 112 | + * { |
| 113 | + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=82&status=active", |
| 114 | + * "rel": "last", |
| 115 | + * "method": "GET" |
| 116 | + * } |
| 117 | + * ] |
| 118 | + * } |
| 119 | + * |
| 120 | + * </code> |
| 121 | + * |
| 122 | + * @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list |
| 123 | + */ |
| 124 | +class RestListPlanRequest extends AbstractRestRequest |
| 125 | +{ |
| 126 | + /** |
| 127 | + * |
| 128 | + * Get the request page |
| 129 | + * |
| 130 | + * @return integer |
| 131 | + */ |
| 132 | + |
| 133 | + public function getPage() |
| 134 | + { |
| 135 | + return $this->getParameter('page'); |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + /** |
| 140 | + * Set the request page |
| 141 | + * |
| 142 | + * @param integer $value |
| 143 | + * @return AbstractRestRequest provides a fluent interface. |
| 144 | + */ |
| 145 | + public function setPage($value) |
| 146 | + { |
| 147 | + return $this->setParameter('page', $value); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Get the request status |
| 152 | + * |
| 153 | + * @return string |
| 154 | + */ |
| 155 | + public function getStatus() |
| 156 | + { |
| 157 | + return $this->getParameter('status'); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Set the request status |
| 162 | + * |
| 163 | + * @param string $value |
| 164 | + * @return AbstractRestRequest provides a fluent interface. |
| 165 | + */ |
| 166 | + public function setStatus($value) |
| 167 | + { |
| 168 | + return $this->setParameter('status', $value); |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Get the request page size |
| 173 | + * |
| 174 | + * @return string |
| 175 | + */ |
| 176 | + public function getPageSize() |
| 177 | + { |
| 178 | + return $this->getParameter('pageSize'); |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Set the request page size |
| 183 | + * |
| 184 | + * @param string $value |
| 185 | + * @return AbstractRestRequest provides a fluent interface. |
| 186 | + */ |
| 187 | + public function setPageSize($value) |
| 188 | + { |
| 189 | + return $this->setParameter('pageSize', $value); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * Get the request total required |
| 194 | + * |
| 195 | + * @return string |
| 196 | + */ |
| 197 | + public function getTotalRequired() |
| 198 | + { |
| 199 | + return $this->getParameter('totalRequired'); |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Set the request total required |
| 204 | + * |
| 205 | + * @param string $value |
| 206 | + * @return AbstractRestRequest provides a fluent interface. |
| 207 | + */ |
| 208 | + public function setTotalRequired($value) |
| 209 | + { |
| 210 | + return $this->setParameter('totalRequired', $value); |
| 211 | + } |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + public function getData() |
| 217 | + { |
| 218 | + return array( |
| 219 | + 'page' => $this->getPage(), |
| 220 | + 'status' => $this->getStatus(), |
| 221 | + 'page_size' => $this->getPageSize(), |
| 222 | + 'total_required' => $this->getTotalRequired() |
| 223 | + ); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Get HTTP Method. |
| 228 | + * |
| 229 | + * The HTTP method for list plans requests must be GET. |
| 230 | + * |
| 231 | + * @return string |
| 232 | + */ |
| 233 | + protected function getHttpMethod() |
| 234 | + { |
| 235 | + return 'GET'; |
| 236 | + } |
| 237 | + |
| 238 | + public function getEndpoint() |
| 239 | + { |
| 240 | + return parent::getEndpoint() . '/payments/billing-plans'; |
| 241 | + } |
| 242 | +} |
0 commit comments