debugteam / paypalrest
该包的最新版本(dev-beta)没有可用的许可信息。
Paypal Rest API 抽象
dev-beta
2015-09-21 13:42 UTC
Requires
- php: >=5.4
- debugteam/baselib: 1.0.x-dev
- paypal/rest-api-sdk-php: v1.4.0
This package is auto-updated.
Last update: 2024-09-21 00:28:51 UTC
README
创建订单、客户和产品对象并使用paypal rest api
我创建了一些特性,以使实现接口更加容易。
由于我不知道你的后端,因此你必须实现客户和订单的保存方法 :P
config.inc.php
<?php define('PAYPAL_RETURN_URL',BASE_URL.'?page=book&action=paypalreturn'); define('PAYPAL_CANCLE_URL',BASE_URL.'?page=book&action=paypalcancle'); define('PAYPAL_CLIENT_SECRET','fdsgfdgkd345gfdfg321FSddfDasbgndfkbgnWdffk'); define('PAYPAL_CLIENT_ID','kjwQohfldasncFSDniandkn24nnrlewfknlsdklnGFnsdw'); define('PAYPAL_HELPER_MODE','sandbox'); define('PAYPAL_HELPER_LOG_ENABLED',true); define('PAYPAL_HELPER_LOG_FILENAME',LOG_PATH.'paypal.log'); define('PAYPAL_HELPER_LOG_LEVEL','DEBUG'); define('PAYPAL_HELPER_VALIDATION_LEVEL','log'); define('PAYPAL_HELPER_CACHE_ENABLED',true); define('PAYPAL_HELPER_CURLOPT_CONNECTTIMEOUT',30); define('PAYPAL_HELPER_PARTNER_ATTRIBUTION_ID','123123123'); ?>
⬆️
创建支付链接
<?php include('config.inc.php') $bookingid = '1'; $invoicenumber = '1'; class Order implements \Debugteam\Paypalrest\Interfaces\iOrder { use \Debugteam\Paypalrest\Traits\tOrder; public function save() { // save order via API or database... } static public function factory() { return new Order(); } public function __construct() { } } class Customer implements \Debugteam\Paypalrest\Interfaces\iCustomer { use \Debugteam\Paypalrest\Traits\tCustomer; public function save() { // save customer via API or database... } static public function factory() { return new Customer(); } public function __construct() { } } class Product implements \Debugteam\Paypalrest\Interfaces\iProduct { use \Debugteam\Paypalrest\Traits\tCustomer; static public function factory() { return new Product(); } public function __construct() { } } // create order $order = Order::factory() ->setCurrency('EUR') ->setDescription('Anzahlung auf Hotelbuchung mit Buchungsnummer:'.$bookingid) ->setHandlingFee(0) ->setInvoiceNumber($invoicenumber) ->setShipping(0); // add products for ($i=0,$cnt<count($data);$i<$cnt;$i++) { $order->setProduct(Product::factory() ->setCurrency($data[$i]['currency']) ->setDescription($data[$i]['description']) ->setName($data[$i]['name']) ->setPrice($data[$i]['price']) ->setQuantity($data[$i]['quantity']) ->setSku($data[$i]['sku']) ->setTax($data[$i]['tax']) ); } // create paymentlink - customer clicks it and processes payment // we get a paymentid, which gets saved into order object $paymentlink = \Debugteam\Paypalrest\PaypalRestOrder::factory() ->create_payment_link($order); echo $paymentlink; ?>
⬆️
执行创建的支付 -> PAYPAL_RETURN_URL
<?php include('config.inc.php'); // the payment is checked on paypal server with paymentid saved in the order object // plus the payers data is recieved and saved in customer object within the order object // If you don't want to save the order/customer data, just return 'foo'; on save methods $paymentcompleted = PaypalRestOrder::factory()->execute_payment($order); if ($paymentcompleted->next!==false) { if ($paymentcompleted->next=='completed') { do_stuff_when_payment_completed(); } else { do_stuff_when_payment_pending(); } } ?>
⬆️