PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.0
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.0
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / gateways / class-wpfnl-gateway-officeguy.php

class-wpfnl-gateway-officeguy.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.0, at includes/core/gateways/class-wpfnl-gateway-officeguy.php

121 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPFunnels\Gateway;
4
5 use OfficeGuyPayment;
6 use OfficeGuyAPI;
7
8 class Wpfnl_Gateway_OfficeGuy {
9
10
11 function __construct()
12 {
13 add_action('og_payment_request_handle', array($this, 'store_sigle_use_token'), 10 ,2);
14 }
15
16
17 /**
18 * Store token into meta post
19 *
20 * @param mixed $Order
21 * @param mixed $Request
22 *
23 * @return void
24 * @since 1.0.0
25 */
26 public function store_sigle_use_token($order, $Request)
27 {
28 $token = sanitize_text_field( $Request['SingleUseToken'] );
29 $order->update_meta_data('SingleUseToken', $token );
30 }
31
32
33
34 /**
35 * Process the offer payment
36 *
37 * @param mixed $order
38 * @param mixed $offer_product
39 *
40 * @return bool
41 * @since 1.0.0
42 */
43 public function process_payment($order, $offer_product)
44 {
45 $result = array(
46 'is_success' => false,
47 'message' => ''
48 );
49 $Request = $this->PreapreOfferProductPaymentRequest($order, $offer_product);
50 $Gateway = GetOfficeGuyGateway();
51 $IsOfficeGuySubscription = get_post_meta($offer_product['id'], 'OfficeGuySubscription', true) === 'yes';
52 if ($IsOfficeGuySubscription)
53 $Response = OfficeGuyAPI::Post($Request, '/billing/recurring/charge/', $Gateway->settings['environment'], true);
54 else
55 $Response = OfficeGuyAPI::Post($Request, '/billing/payments/charge/', $Gateway->settings['environment'], true);
56
57 if ( ! is_wp_error( $Response ) ) {
58 if ( $Response['Status'] == 0 ) {
59 $result['is_success'] = true;
60 $result['message'] = "Payment Successful";
61 } else {
62 $result['is_success'] = false;
63 $result['message'] = $Response['UserErrorMessage'];
64 }
65 }
66 return $result;
67 }
68
69
70 /**
71 * Prepare an array for SUMIT payment charge API request
72 *
73 * @param mixed $order
74 * @param mixed $product
75 *
76 * @return array
77 * @since 1.0.0
78 */
79 private function PreapreOfferProductPaymentRequest($order, $product)
80 {
81 $Gateway = GetOfficeGuyGateway();
82 $Request = array();
83 $Request['Credentials'] = OfficeGuyPayment::GetCredentials($Gateway);
84 $Request['SingleUseToken'] = $order->get_meta('SingleUseToken');
85
86 $Request['Items'] = array();
87 $Item = OfficeGuyPayment::GetPaymentOrderItem(null, $product['id'], round($product['price'], 2), 1, $order->get_currency(), null, null, $order);
88 array_push($Request['Items'], $Item);
89
90 $Request['VATIncluded'] = 'true';
91 $Request['VATRate'] = OfficeGuyPayment::GetOrderVatRate($order);
92 $Request['Customer'] = array();
93 $Request['Customer']['ID'] = $order->get_meta("OfficeGuyCustomerID");
94 $Request['Customer']['Name'] = $this->getCustomerFullName($order);
95 $Request['Customer']['EmailAddress'] = $order->data['billing']['email'];
96
97 $Request['AuthoriseOnly'] = $Gateway->settings['testing'] != 'no' ? 'true' : 'false';
98 $Request['DraftDocument'] = $Gateway->settings['draftdocument'] != 'no' ? 'true' : 'false';
99 $Request['SendDocumentByEmail'] = $Gateway->settings['emaildocument'] == 'yes' ? 'true' : 'false';
100 $Request['UpdateCustomerByEmail'] = 'false';
101 $Request['DocumentDescription'] = __('Order number', 'officeguy') . ': ' . $order->get_id();
102 $Request['DocumentLanguage'] = OfficeGuyPayment::GetOrderLanguage($Gateway);
103 $Request['MerchantNumber'] = $Gateway->settings['merchantnumber'];
104
105 return $Request;
106 }
107
108
109 /**
110 * Return customer full name
111 *
112 * @param mixed $order
113 *
114 * @return string
115 * @since 1.0.0
116 */
117 private function getCustomerFullName($order)
118 {
119 return $order->data['billing']['first_name'] . ' ' . $order->data['billing']['last_name'];
120 }
121 }