/** * Extends the Payment object to create future payments * * @param null $apiContext * @param string|null $clientMetadataId * @return $this */ public function create($apiContext = null, $clientMetadataId = null) { if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $headers = array(); if ($clientMetadataId != null) { $headers = array('PAYPAL-CLIENT-METADATA-ID' => $clientMetadataId); } $payLoad = $this->toJSON(); $call = new PayPalRestCall($apiContext); $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/payment", "POST", $payLoad, $headers); $this->fromJson($json); return $this; }
/** * Reauthorizes an expired Authorization. * * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @return Authorization */ public function reauthorize($apiContext = null) { ArgumentValidator::validate($this->getId(), "Id"); $payLoad = $this->toJSON(); if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PayPalRestCall($apiContext); $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/authorization/{$this->getId()}/reauthorize", "POST", $payLoad); $this->fromJson($json); return $this; }
/** * Creates (and processes) a new Refund Transaction added as a related resource. * * @param Refund $refund * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @return Refund */ public function refund($refund, $apiContext = null) { ArgumentValidator::validate($this->getId(), "Id"); ArgumentValidator::validate($refund, 'refund'); $payLoad = $refund->toJSON(); if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PayPalRestCall($apiContext); $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/capture/{$this->getId()}/refund", "POST", $payLoad); $ret = new Refund(); $ret->fromJson($json); return $ret; }
/** * Проверяет реально был выполнен запрос к нашему скрипту IPN от сервера пейпел * или это какото хакерский запрос. * * @return bool */ public function checkIPN() { $postdata = ""; foreach ($_POST as $key => $value) { $postdata .= $key . "=" . urlencode($value) . "&"; } $postdata .= "cmd=_notify-validate"; $restCall = new PayPalRestCall($this->_apiContext); $response = $restCall->execute(['PayPal\\Handler\\RestHandler'], '/cgi-bin/webscr', 'POST', $postdata, [], true); // ++ DEBUG LOG $postdata = ""; foreach ($_POST as $key => $value) { $postdata .= $key . " = " . urlencode($value) . " \n"; } $this->logging_queryes('ipn_answer.txt', $postdata . "\n================\n RESPONSE = " . $response); // -- DEBUG LOG if (strtoupper(trim($response)) == 'VERIFIED') { return true; } return false; }
/** * Obtain the Refund transaction resource for the given identifier. * * @param string $refundId * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @return Refund */ public static function get($refundId, $apiContext = null) { ArgumentValidator::validate($refundId, 'refundId'); $payLoad = ""; if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PayPalRestCall($apiContext); $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/refund/{$refundId}", "GET", $payLoad); $ret = new Refund(); $ret->fromJson($json); return $ret; }