本文整理汇总了PHP中PayPal\Api\Payment类的典型用法代码示例。如果您正苦于以下问题:PHP Payment类的具体用法?PHP Payment怎么用?PHP Payment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Payment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: credit_card
public function credit_card()
{
return "Hello?";
$card = new CreditCard();
$card->setType("visa")->setNumber("4148529247832259")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')->setDescription('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setTax(0.3)->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')->setDescription('Granola Bars with Peanuts')->setCurrency('USD')->setQuantity(5)->setTax(0.2)->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
$amount = new Amount();
$amount->setCurrency("USD")->setTotal(20)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (Exception $ex) {
ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using <a href="https://ppmts.custhelp.com/app/answers/detail/a_id/750">Step 4, on this link</a>, and using it.', 'Payment', null, $request, $ex);
exit(1);
}
ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
return $payment;
}
示例2: startPayment
/**
* @return Payment
* @throws CheckoutException
*/
public function startPayment()
{
$total_amount = ($this->request->amount + $this->request->tax_amount - $this->request->discount_amount) * 100;
$apiContext->setConfig(array('service.EndPoint' => "https://test-api.sandbox.paypal.com"));
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item1 = new Item();
$item1->setName('Product1')->setCurrency('EUR')->setPrice(10.0)->setQuantity(2)->setTax(3.0);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
$amount = new Amount();
$amount->setCurrency('EUR')->setTotal(20)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment')->setInvoiceNumber('transactionid');
$baseUrl = getBaseUrl();
$redir = new RedirectUrls();
$redir->setReturnUrl($baseUrl . '/');
$redir->setCancelUrl($baseUrl . '/');
$payment = new Payment();
$payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redir)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (\Exception $e) {
throw new CheckoutException('Paypal error', 500, $e);
}
$approvalUrl = $payment->getApprovalLink();
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment);
return $payment;
}
示例3: CreateTransaction
function CreateTransaction($transactionType, $itemArray, $details)
{
$payer = new Payer();
$payer->setPaymentMethod($GLOBALS['PAYPAL']['payment_method']);
$itemList = new ItemList();
$itemList->setItems($itemArray);
$amount = new Amount();
$amount->setCurrency($GLOBALS['PAYPAL']['currency'])->setTotal(GetDetailsTotal($details))->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription($GLOBALS['TRANSACTION_TYPE']['DONATION']['payment_desc'])->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($GLOBALS['TRANSACTION_TYPE']['DONATION']['return_url'])->setCancelUrl($GLOBALS['TRANSACTION_TYPE']['DONATION']['cancel_url']);
$payment = new Payment();
$payment->setIntent($GLOBALS['TRANSACTION_TYPE']['DONATION']['intent'])->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($GLOBALS['PAYPAL']['api_context']);
} catch (Exception $ex) {
ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
return false;
}
$approvalUrl = $payment->getApprovalLink();
echo $approvalUrl;
return array('request' => $request, 'payment' => $payment, 'approvalUrl' => $approvalUrl);
}
示例4: payment
/**
* @throws \InvalidArgumentException
*
* @return Payment
*/
private function payment() : Payment
{
if ($this->payment === null) {
$this->payment = $this->return->payment();
$this->payment->execute($this->execution(), $this->context);
}
return $this->payment;
}
示例5: addTrackingParameters
public static function addTrackingParameters(Payment $payment)
{
$redirectUrls = $payment->getRedirectUrls();
$url = new Url($redirectUrls->getReturnUrl());
$url->setQueryParameter('utm_nooverride', 1);
$redirectUrls->setReturnUrl($url->getAbsoluteUrl());
$payment->setRedirectUrls($redirectUrls);
return $payment;
}
示例6: createPayment
public function createPayment($card, $transaction)
{
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
$payment->create($this->apiContext);
return $payment;
}
示例7: mockPayPalPayment
/**
* @throws \InvalidArgumentException
*
* @return Payment|MockInterface
*/
private function mockPayPalPayment()
{
if ($this->payPalPayment === null) {
$this->payPalPayment = Mockery::mock(Payment::class);
$this->payPalPayment->shouldIgnoreMissing()->asUndefined();
app()->extend(Payment::class, function () {
return $this->payPalPayment;
});
}
return $this->payPalPayment;
}
示例8: createPayPal
public static function createPayPal($invoiceNumber, \PropelPDO $con)
{
$i18n = Localizer::get('payment');
// ### Payer
// A resource representing a Payer that funds a payment
// For direct credit card payments, set payment method
// to 'credit_card' and add an array of funding instruments.
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName($i18n['item_name'])->setDescription($i18n['item_description'])->setCurrency(TransactionEntity::$BASE_CURRENCY)->setQuantity(1)->setTax(0)->setPrice(TransactionEntity::$MEMBER_FEE);
$itemList = new ItemList();
$itemList->setItems(array($item1));
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency(TransactionEntity::$BASE_CURRENCY)->setTotal(TransactionEntity::$MEMBER_FEE);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it.
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription($i18n['transaction_description'])->setInvoiceNumber($invoiceNumber);
// ### Redirect urls
// Set the urls that the buyer must be redirected to after
// payment approval/ cancellation.
$success = Router::toModule('account', 'index');
$failure = Router::toModule('guide', 'index', ['purchase_failed' => true]);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($success)->setCancelUrl($failure);
// ### Payment
// A Payment Resource; create one using
// the above types and intent set to sale 'sale'
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setExperienceProfileId(self::getPaymentExperienceProfileId())->setTransactions(array($transaction));
// ### Create Payment
// Create a payment by calling the payment->create() method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the state.
$apiContext = self::getApiContext();
$payment->create($apiContext);
return $payment;
}
示例9: paypal
function paypal($data)
{
try {
foreach ($data as $k => $v) {
${$k} = $v;
}
include_once 'config.paypal.php';
$apiContext = new ApiContext(new OAuthTokenCredential(CLIENT_ID, CLIENT_SECRET));
list($m, $y) = explode("/", $card_expiry);
$card = new CreditCard();
$card->setNumber($card_number);
$card->setType(strtolower($card_type));
$card->setExpireMonth($m);
$card->setExpireYear($y);
$card->setCvv2($card_cvv);
$card->setFirstName($first_name);
$card->setLastName($last_name);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod('credit_card');
$payer->setFundingInstruments(array($fi));
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($price);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('Enter your card details and proceed');
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$res = json_decode($payment->create($apiContext));
$this->save($data, __FUNCTION__, $res, 1);
return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $res->state)]);
} catch (Exception $e) {
if ($e instanceof PPConfigurationException) {
} elseif ($e instanceof PPConnectionException) {
} elseif ($e instanceof PayPal\Exception\PayPalConnectionException) {
$res = json_decode($e->getData(), 1);
$this->save($data, __FUNCTION__, $res, 0);
$msg = array_shift(isset($res["details"]) ? $res["details"] : []);
return json_encode(["status" => false, "msg" => $res["name"] == "UNKNOWN_ERROR" || empty($msg["issue"]) ? "An unknown error has occurred" : sprintf("%s %s", ["cvv2" => "CVV2", "expire_year" => "Card expiration", "credit_card" => "", "type" => "Invalid credit card number or", "number" => "Credit card number", "expire_month" => "Expiration month"][end(explode(".", $msg["field"]))], strtolower($msg["issue"]))]);
} else {
throw $e;
}
}
}
示例10: check
/**
* @param PaymentInterface $payment
* @throws InvalidPaymentException
*/
public function check(PaymentInterface $payment)
{
if ($payment->getTransaction()) {
throw new InvalidPaymentException('Payment has already been received.');
}
$credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']);
$apiContext = new ApiContext($credentials);
$apiContext->setConfig(['mode' => $this->options['mode']]);
$paypalPayment = Payment::get($payment->getExtraData('paypal_payment_id'), $apiContext);
$payer = $paypalPayment->getPayer();
if (!$payer || 'verified' !== strtolower($payer->getStatus())) {
throw new InvalidPaymentException('Payer not verified.');
}
if ('created' == $paypalPayment->getState()) {
$execution = new PaymentExecution();
$execution->setPayerId($paypalPayment->getPayer()->getPayerInfo()->getPayerId());
$paypalPayment->execute($execution, $apiContext);
}
if ('approved' != $paypalPayment->getState()) {
throw new InvalidPaymentException('Invalid payment state.');
}
$math = new NativeMath();
$controlSum = 0;
foreach ($paypalPayment->getTransactions() as $transaction) {
if ($transaction->getAmount()->getCurrency() != $payment->getAccount()->getCurrency()) {
throw new InvalidPaymentException('Invalid payment currency.');
}
$controlSum = $math->sum($controlSum, $transaction->getAmount()->getTotal());
}
if (!$math->eq($payment->getPaymentSum(), $controlSum)) {
throw new InvalidPaymentException('Invalid payment sum.');
}
}
示例11: getPaymentStatus
public function getPaymentStatus()
{
// Get the payment ID before session clear
$payment_id = Session::get('paypal_payment_id');
// clear the session payment ID
Session::forget('paypal_payment_id');
if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
return Redirect::route('original.route')->with('error', 'Payment failed');
}
$payment = Payment::get($payment_id, $this->_api_context);
// PaymentExecution object includes information necessary
// to execute a PayPal account payment.
// The payer_id is added to the request query parameters
// when the user is redirected from paypal back to your site
$execution = new PaymentExecution();
$execution->setPayerId(Input::get('PayerID'));
//Execute the payment
$result = $payment->execute($execution, $this->_api_context);
echo '<pre>';
print_r($result);
echo '</pre>';
exit;
// DEBUG RESULT, remove it later
if ($result->getState() == 'approved') {
// payment made
return Redirect::route('original.route')->with('success', 'Payment success');
}
return Redirect::route('original.route')->with('error', 'Payment failed');
}
示例12: testGet
/**
* @depends testCreate
* @param $payment Payment
* @return Payment
*/
public function testGet($payment)
{
$result = Payment::get($payment->getId(), $this->apiContext, $this->mockPayPalRestCall);
$this->assertNotNull($result);
$this->assertEquals($payment->getId(), $result->getId());
return $result;
}
示例13: processResult
public function processResult($data)
{
$paymentId = ArrayHelper::getValue($data, 'paymentId');
if (!$paymentId) {
throw new BadRequestHttpException('Missing payment id');
}
$payerId = ArrayHelper::getValue($data, 'PayerID');
if (!$payerId) {
throw new BadRequestHttpException('Missing payer id');
}
$payment = Payment::get($paymentId, $this->getContext());
$event = new GatewayEvent(['gatewayData' => $data, 'payment' => $payment]);
$this->trigger(GatewayEvent::EVENT_PAYMENT_REQUEST, $event);
if (!$event->handled) {
throw new ServerErrorHttpException('Error processing request');
}
$transaction = \Yii::$app->getDb()->beginTransaction();
try {
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayerId($payerId);
$event->payment = $payment->execute($paymentExecution, $this->getContext());
$this->trigger(GatewayEvent::EVENT_PAYMENT_SUCCESS, $event);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
\Yii::error('Payment processing error: ' . $e->getMessage(), 'PayPal');
throw new ServerErrorHttpException('Error processing request');
}
return true;
}
示例14: createPayment
public function createPayment()
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item_1 = new Item();
$item_1->setName('Item 1')->setCurrency('USD')->setQuantity(2)->setPrice('15');
// unit price
$item_2 = new Item();
$item_2->setName('Item 2')->setCurrency('USD')->setQuantity(4)->setPrice('7');
$item_3 = new Item();
$item_3->setName('Item 3')->setCurrency('USD')->setQuantity(1)->setPrice('20');
// add item to list
$item_list = new ItemList();
$item_list->setItems(array($item_1, $item_2, $item_3));
$amount = new Amount();
$amount->setCurrency('USD')->setTotal(78);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(route('payment.status'))->setCancelUrl(route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
if (\Config::get('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
exit;
} else {
die('Some error occur, sorry for inconvenient');
}
}
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
Session::put('paypal_payment_id', $payment->getId());
if (isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
}
return Redirect::route('original.route')->with('error', 'Unknown error occurred');
}
示例15: execute
/**
* {@inheritDoc}
*/
public function execute($request)
{
/** @var $request Sync */
RequestNotSupportedException::assertSupports($this, $request);
/** @var Payment $model */
$model = $request->getModel();
$payment = Payment::get($model->id);
$model->fromArray($payment->toArray());
}