xwiz/omnipay-2checkout
Omnipay支付处理库的2Checkout驱动程序
v3.0
2022-12-08 13:15 UTC
Requires
- ext-json: *
- omnipay/common: ^3.0
Requires (Dev)
- omnipay/tests: ^3.0
- satooshi/php-coveralls: ^0.7.1
README
Omnipay PHP支付处理库的2checkout网关
Omnipay是一个与框架无关的、支持多网关的PHP 5.3+支付处理库。本包实现了Omnipay对2checkout的支持。
安装
通过Composer
$ composer require xwiz/omnipay-2checkout
用法
本包提供了以下网关
- TwoCheckoutPlus
- TwoCheckoutPlus_Token
TwoCheckoutPlus
use Omnipay\Omnipay; $gateway = Omnipay::create('TwoCheckoutPlus'); $gateway->setAccountNumber($this->account_number); $gateway->setSecretWord($this->secret_word); $gateway->setTestMode($this->is_sandbox_test()); // activate test mode by passing demo parameter to checkout parameters. $gateway->setDemoMode($this->is_test_mode()); try { $formData = array( 'firstName' => $order->get_billing_first_name(), 'lastName' => $order->get_billing_last_name(), 'email' => $order->get_billing_email(), 'address1' => $order->get_billing_address_1(), 'address2' => $order->get_billing_address_2(), 'city' => $order->get_billing_city(), 'state' => $order->get_billing_state(), 'postcode' => $order->get_billing_postcode(), 'country' => $order->get_billing_country(), ); $order_cart = $order->get_items(); $cart = array(); $i = 0; foreach ($order_cart as $order_item_id => $product) { $product_id = $product['product_id']; $cart[$i]['name'] = $product['name']; $cart[$i]['quantity'] = $product['qty']; $cart[$i]['type'] = 'product'; $cart[$i]['price'] = round($product['line_subtotal'] / $product['qty'], 2); $cart[$i]['product_id'] = $product_id; $i++; } if (($shipping_total = $order->get_shipping_total()) > 0) { $cart[] = array( 'name' => 'Shipping Fee', 'quantity' => 1, 'type' => 'shipping', 'price' => round($shipping_total, 2), ); } if (($discount_total = $order->get_total_discount()) > 0) { $cart[] = array( 'name' => 'Discount', 'quantity' => 1, 'type' => 'coupon', 'price' => round($discount_total, 2), ); } if (($tax_total = $order->get_total_tax()) > 0) { $cart[] = array( 'name' => 'Tax Fee', 'type' => 'tax', 'quantity' => 1, 'price' => round($tax_total, 2), ); } $gateway->setCart($cart); $response = $gateway->purchase( array( 'card' => $formData, 'transactionId' => $order->get_order_number(), 'currency' => 'USD', // add a query parameter to the returnUrl to listen and complete payment 'returnUrl' => $this->returnUrl, ) )->send(); if ($response->isRedirect()) { $response->getRedirectUrl(); } else { $error = $response->getMessage(); } } catch (Exception $e) { $e->getMessage(); }
TwoCheckoutPlus_Token
use Omnipay\Omnipay; try { $gateway = Omnipay::create('TwoCheckoutPlus_Token'); $gateway->setAccountNumber($this->account_number); $gateway->setTestMode($this->is_sandbox_test()); $gateway->setPrivateKey($this->private_key); $formData = array( 'firstName' => $order->get_billing_first_name(), 'lastName' => $order->get_billing_last_name(), 'email' => $order->get_billing_email(), 'billingAddress1' => $order->get_billing_address_1(), 'billingAddress2' => $order->get_billing_address_2(), 'billingCity' => $order->get_billing_city(), 'billingPostcode' => $order->get_billing_postcode(), 'billingState' => $order->get_billing_state(), 'billingCountry' => $order->get_billing_country(), ); $purchase_request_data = array( 'card' => $formData, 'token' => sanitize_text_field($_POST['twocheckout_token']), 'transactionId' => $order->get_order_number(), 'currency' => 'USD', 'amount' => $order->order_total, ); $response = $gateway->purchase($purchase_request_data)->send(); if ($response->isSuccessful()) { $transaction_ref = $response->getTransactionReference(); } else { $error = $response->getMessage(); } } catch (Exception $e) { $e->getMessage(); }
有关一般用法说明,请参阅Omnipay主存储库。
支持
此存储库最初是从https://github.com/w3guy/omnipay-2checkout/分叉的,该存储库不再维护。
如果您认为您找到了一个错误,请使用GitHub问题跟踪器报告它,或者更好的是,分叉库并提交拉取请求。
如果您在使用Omnipay时遇到一般性问题,我们建议您在Stack Overflow上发帖。请务必添加omnipay标签,以便可以轻松找到。
如果您想了解发布公告,讨论项目想法或提出更详细的问题,还有一个您可以订阅的邮件列表。
测试
$ composer test
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件me@w3guy.com联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。