/** * Look up a particular payment resource by passing the payment_id in the request URI. * * @param string $paymentId * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Payment */ public static function get($paymentId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($paymentId, 'paymentId'); $payLoad = ""; $json = self::executeCall("/v1/payments/payment/{$paymentId}", "GET", $payLoad, null, $apiContext, $restCall); $ret = new Payment(); $ret->fromJson($json); return $ret; }
/** * Execute * * @param \Paypal\Api\PaymentExecution $paymentExecution * @param \PayPal\Rest\ApiContext|null $apiContext * * @return Payment * @throws \InvalidArgumentException */ public function execute($paymentExecution, $apiContext = null) { if ($this->getId() == null) { throw new \InvalidArgumentException("Id cannot be null"); } if ($paymentExecution == null) { throw new \InvalidArgumentException("paymentExecution cannot be null or empty"); } $payLoad = $paymentExecution->toJSON(); if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PPRestCall($apiContext); $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad); $ret = new Payment(); $ret->fromJson($json); return $ret; }
/** * @group integration * * Tests Additional_fields, shipping_discount and insurance information. * Additional Information: https://developer.paypal.com/docs/integration/direct/explore-payment-capabilities/ */ public function testECParameters() { $json = '{ "intent": "sale", "redirect_urls": { "return_url": "http://www.return.com", "cancel_url": "http://www.cancel.com" }, "payer": { "payment_method": "paypal", "payer_info": { "tax_id_type": "BR_CPF", "tax_id": "Fh618775690" } }, "transactions": [ { "amount": { "total": "34.07", "currency": "USD", "details": { "subtotal": "30.00", "tax": "0.07", "shipping": "1.00", "handling_fee": "1.00", "shipping_discount": "1.00", "insurance": "1.00" } }, "description": "This is the payment transaction description.", "custom": "EBAY_EMS_90048630024435", "invoice_number": "48787589677", "payment_options": { "allowed_payment_method": "INSTANT_FUNDING_SOURCE" }, "soft_descriptor": "ECHI5786786", "item_list": { "items": [ { "name": "bowling", "description": "Bowling Team Shirt", "quantity": "5", "price": "3", "tax": "0.01", "sku": "1", "currency": "USD" }, { "name": "mesh", "description": "80s Mesh Sleeveless Shirt", "quantity": "1", "price": "15", "tax": "0.02", "sku": "product34", "currency": "USD" } ], "shipping_address": { "recipient_name": "Betsy Buyer", "line1": "111 First Street", "city": "Saratoga", "country_code": "US", "postal_code": "95070", "state": "CA" } } } ] }'; $payment = new Payment(); $payment->fromJson($json); $payment->create(); $result = Payment::get($payment->getId()); $transactions = $result->getTransactions(); $transaction = $transactions[0]; $this->assertEquals($transaction->getAmount()->getDetails()->getShippingDiscount(), '1.00'); $this->assertEquals($transaction->getAmount()->getDetails()->getInsurance(), '1.00'); $this->assertEquals($transaction->getAmount()->getDetails()->getHandlingFee(), '1.00'); }
/** * @path /v1/payments/payment/:payment-id * @method GET * @param string $paymentid */ public static function get($paymentid) { if ($paymentid == null || strlen($paymentid) <= 0) { throw new \InvalidArgumentException("paymentid cannot be null or empty"); } $payLoad = ""; $apiContext = new ApiContext(self::$credential); $call = new Call(); $json = $call->execute("/v1/payments/payment/{$paymentid}", "GET", $payLoad, $apiContext); $ret = new Payment(); $ret->fromJson($json); return $ret; }
public function testSerializeDeserialize() { $p2 = new Payment(); $p2->fromJson($this->payments['full']->toJSON()); $this->assertEquals($p2, $this->payments['full']); }