本文整理汇总了PHP中PayPal\Api\Payment::fromJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Payment::fromJson方法的具体用法?PHP Payment::fromJson怎么用?PHP Payment::fromJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Payment
的用法示例。
在下文中一共展示了Payment::fromJson方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* 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;
}
示例2: execute
/**
* 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;
}
示例3: testECParameters
/**
* @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');
}
示例4: get
/**
* @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;
}
示例5: testSerializeDeserialize
public function testSerializeDeserialize()
{
$p2 = new Payment();
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}