项目作者: w3guy

项目描述 :
2Checkout driver for the Omnipay PHP payment processing library
高级语言: PHP
项目地址: git://github.com/w3guy/omnipay-2checkout.git
创建时间: 2015-12-18T20:13:15Z
项目社区:https://github.com/w3guy/omnipay-2checkout

开源协议:MIT License

下载


Omnipay: 2checkout

2checkout gateway for the Omnipay PHP payment processing library

Latest Version on Packagist
Software License
Build Status
Coverage Status
Code Climate
Dependency Status
Total Downloads

Omnipay is a framework agnostic, multi-gateway payment
processing library for PHP 5.3+. This package implements 2checkout support for Omnipay.

Install

Via Composer

  1. $ composer require collizo4sky/omnipay-2checkout

Usage

The following gateways are provided by this package:

  • TwoCheckoutPlus
  • TwoCheckoutPlus_Token

TwoCheckoutPlus

  1. use Omnipay\Omnipay;
  2. $gateway = Omnipay::create('TwoCheckoutPlus');
  3. $gateway->setAccountNumber($this->account_number);
  4. $gateway->setSecretWord($this->secret_word);
  5. $gateway->setTestMode($this->is_sandbox_test());
  6. // activate test mode by passing demo parameter to checkout parameters.
  7. $gateway->setDemoMode($this->is_test_mode());
  8. try {
  9. $formData = array(
  10. 'firstName' => $order->get_billing_first_name(),
  11. 'lastName' => $order->get_billing_last_name(),
  12. 'email' => $order->get_billing_email(),
  13. 'address1' => $order->get_billing_address_1(),
  14. 'address2' => $order->get_billing_address_2(),
  15. 'city' => $order->get_billing_city(),
  16. 'state' => $order->get_billing_state(),
  17. 'postcode' => $order->get_billing_postcode(),
  18. 'country' => $order->get_billing_country(),
  19. );
  20. $order_cart = $order->get_items();
  21. $cart = array();
  22. $i = 0;
  23. foreach ($order_cart as $order_item_id => $product) {
  24. $product_id = $product['product_id'];
  25. $cart[$i]['name'] = $product['name'];
  26. $cart[$i]['quantity'] = $product['qty'];
  27. $cart[$i]['type'] = 'product';
  28. $cart[$i]['price'] = round($product['line_subtotal'] / $product['qty'], 2);
  29. $cart[$i]['product_id'] = $product_id;
  30. $i++;
  31. }
  32. if (($shipping_total = $order->get_shipping_total()) > 0) {
  33. $cart[] = array(
  34. 'name' => 'Shipping Fee',
  35. 'quantity' => 1,
  36. 'type' => 'shipping',
  37. 'price' => round($shipping_total, 2),
  38. );
  39. }
  40. if (($discount_total = $order->get_total_discount()) > 0) {
  41. $cart[] = array(
  42. 'name' => 'Discount',
  43. 'quantity' => 1,
  44. 'type' => 'coupon',
  45. 'price' => round($discount_total, 2),
  46. );
  47. }
  48. if (($tax_total = $order->get_total_tax()) > 0) {
  49. $cart[] = array(
  50. 'name' => 'Tax Fee',
  51. 'type' => 'tax',
  52. 'quantity' => 1,
  53. 'price' => round($tax_total, 2),
  54. );
  55. }
  56. $gateway->setCart($cart);
  57. $response = $gateway->purchase(
  58. array(
  59. 'card' => $formData,
  60. 'transactionId' => $order->get_order_number(),
  61. 'currency' => 'USD',
  62. // add a query parameter to the returnUrl to listen and complete payment
  63. 'returnUrl' => $this->returnUrl,
  64. )
  65. )->send();
  66. if ($response->isRedirect()) {
  67. $response->getRedirectUrl();
  68. } else {
  69. $error = $response->getMessage();
  70. }
  71. } catch (Exception $e) {
  72. $e->getMessage();
  73. }

TwoCheckoutPlus_Token

  1. use Omnipay\Omnipay;
  2. try {
  3. $gateway = Omnipay::create('TwoCheckoutPlus_Token');
  4. $gateway->setAccountNumber($this->account_number);
  5. $gateway->setTestMode($this->is_sandbox_test());
  6. $gateway->setPrivateKey($this->private_key);
  7. $formData = array(
  8. 'firstName' => $order->get_billing_first_name(),
  9. 'lastName' => $order->get_billing_last_name(),
  10. 'email' => $order->get_billing_email(),
  11. 'billingAddress1' => $order->get_billing_address_1(),
  12. 'billingAddress2' => $order->get_billing_address_2(),
  13. 'billingCity' => $order->get_billing_city(),
  14. 'billingPostcode' => $order->get_billing_postcode(),
  15. 'billingState' => $order->get_billing_state(),
  16. 'billingCountry' => $order->get_billing_country(),
  17. );
  18. $purchase_request_data = array(
  19. 'card' => $formData,
  20. 'token' => sanitize_text_field($_POST['twocheckout_token']),
  21. 'transactionId' => $order->get_order_number(),
  22. 'currency' => 'USD',
  23. 'amount' => $order->order_total,
  24. );
  25. $response = $gateway->purchase($purchase_request_data)->send();
  26. if ($response->isSuccessful()) {
  27. $transaction_ref = $response->getTransactionReference();
  28. } else {
  29. $error = $response->getMessage();
  30. }
  31. } catch (Exception $e) {
  32. $e->getMessage();
  33. }

For general usage instructions, please see the main Omnipay repository.

Support

If you are having general issues with Omnipay, we suggest posting on
Stack Overflow. Be sure to add the
omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project,
or ask more detailed questions, there is also a mailing list which
you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker,
or better yet, fork the library and submit a pull request.

Testing

  1. $ composer test

Security

If you discover any security related issues, please email me@w3guy.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.