Subscribes your webhook listener to events. A successful call returns a webhook object, which includes the webhook ID for later use.
public create ( |
||
$apiContext | is the APIContext for this call. It can be used to pass dynamic configuration and credentials. | |
$restCall | PayPalRestCall | is the Rest Call Service that is used to make rest calls |
Результат |
/** * @dataProvider mockProvider * @param Webhook $obj */ public function testCreate($obj, $mockApiContext) { $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock(); $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(self::getJson())); $result = $obj->create($mockApiContext, $mockPayPalRestCall); $this->assertNotNull($result); }
public function testCreate() { $request = $this->operation['request']['body']; $obj = new Webhook($request); // Adding a random url request to make it unique $obj->setUrl($obj->getUrl() . '?rand=' . uniqid()); $result = null; try { $result = $obj->create($this->apiContext, $this->mockPayPalRestCall); } catch (PayPalConnectionException $ex) { $data = $ex->getData(); if (strpos($data, 'WEBHOOK_NUMBER_LIMIT_EXCEEDED') !== false) { $this->deleteAll(); $result = $obj->create($this->apiContext, $this->mockPayPalRestCall); } else { $this->fail($ex->getMessage()); } } $this->assertNotNull($result); return $result; }
function create_webhook($data) { // auth $apiContext = $this->apiContext(); $webhookEventTypes = array(); for ($i = 0, $n = count($data['data']); $i < $n; $i++) { if ($data['data'][$i]['name'] != '') { $webhookEvent = new WebhookEventType(); $webhookEvent->setName($data['data'][$i]['name']); $webhookEventTypes[] = $webhookEvent; } } // set webhook $webhook = new Webhook(); $webhook->setUrl(xtc_catalog_href_link('callback/paypal/webhook.php', '', 'SSL', false))->setEventTypes($webhookEventTypes); try { $WebhookList = $webhook->create($apiContext); } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); } $sql_data_array = array(); for ($i = 0, $n = count($data['data']); $i < $n; $i++) { if ($data['data'][$i]['name'] != '') { $sql_data_array[] = array('config_key' => $data['data'][$i]['name'], 'config_value' => $data['data'][$i]['orders_status']); } } $this->save_config($sql_data_array); }