-
Notifications
You must be signed in to change notification settings - Fork 11
GPAPI Subscriptions Sompatibility #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code in this file seems to be indented using spaces and not tabs. This needs to be fixed. |
||
|
|
||
| namespace GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\Requests\Subscriptions; | ||
|
|
||
| use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\Requests\AbstractRequest; | ||
| use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\AbstractGateway; | ||
| use GlobalPayments\Api\PaymentMethods\CreditCardData; | ||
| use GlobalPayments\Api\Entities\Enums\AddressType; | ||
| use GlobalPayments\Api\Entities\Customer; | ||
| use GlobalPayments\Api\Entities\Address; | ||
| use GlobalPayments\Api\Utils\CountryUtils; | ||
| use GlobalPayments\Api\Entities\Enums\PhoneNumberType; | ||
| use GlobalPayments\Api\Entities\PhoneNumber; | ||
| use GlobalPayments\WooCommercePaymentGatewayProvider\Utils\Utils; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Three of the four empty lines can be removed. |
||
| defined('ABSPATH') || exit; | ||
|
|
||
| class SubscriptionRequest extends AbstractRequest { | ||
|
|
||
| public function get_transaction_type() { | ||
| return AbstractGateway::TXN_TYPE_SUBSCRIPTION_PAYMENT; | ||
| } | ||
| public function get_args() { | ||
| return array(); | ||
| } | ||
| public function do_request() { | ||
| $muti_use_token = $this->get_muti_use_token(); | ||
| $tokenizedCard = new CreditCardData(); | ||
| $tokenizedCard->token = $muti_use_token; | ||
| $customer_details = $this->get_customer_data(); | ||
| $tokenizedCard->cardHolderName = $customer_details->firstName . " " . $customer_details->lastName; | ||
| $response = $tokenizedCard->charge( $this->order->get_total() ) | ||
| ->withCurrency( $this->order->get_currency() ) | ||
| ->withOrderId( (string) $this->order->get_id() ) | ||
| ->withAddress( $this->get_shipping_details(), AddressType::SHIPPING ) | ||
| ->withAddress( $this->get_billing_address(), AddressType::BILLING ) | ||
| ->withCustomerData( $customer_details ) | ||
| ->withDynamicDescriptor( sprintf( __( "Subscription payment for order: %s", "globalpayments-gateway-provider-for-woocommerce" ), $this->order->get_id() ) ) | ||
| ->execute(); | ||
|
|
||
| return $response; | ||
| } | ||
| private function get_muti_use_token(){ | ||
|
||
| return $this->order->get_meta( "_GP_multi_use_token" ) ? $this->order->get_meta( "_GP_multi_use_token" ) : $this->config['multi_use_token']; | ||
| } | ||
| private function get_shipping_details(){ | ||
| $shipping_details = new Address(); | ||
| $shipping_details->streetAddress1 = $this->order->get_billing_address_1(); | ||
| $shipping_details->streetAddress2 = $this->order->get_billing_address_2(); | ||
| $shipping_details->city = $this->order->get_billing_city(); | ||
| $shipping_details->state = $this->order->get_billing_state(); | ||
| $shipping_details->postalCode = $this->order->get_billing_postcode(); | ||
| $shipping_details->country = $this->order->get_billing_country(); | ||
|
|
||
| return $shipping_details; | ||
| } | ||
| protected function get_billing_address(){ | ||
| $billing_address = new Address(); | ||
| $billing_address->streetAddress1 = $this->order->get_billing_address_1(); | ||
| $billing_address->streetAddress2 = $this->order->get_billing_address_2(); | ||
| $billing_address->city = $this->order->get_billing_city(); | ||
| $billing_address->state = $this->order->get_billing_state(); | ||
| $billing_address->postalCode = $this->order->get_billing_postcode(); | ||
| $billing_address->country = $this->order->get_billing_country(); | ||
|
|
||
| return $billing_address; | ||
| } | ||
| private function get_customer_data(){ | ||
| $customer = new Customer(); | ||
| $customer->id = $this->order->get_customer_id(); | ||
| $customer->firstName = Utils::sanitize_string( $this->order->get_billing_first_name() ); | ||
| $customer->lastName = Utils::sanitize_string( $this->order->get_billing_last_name() ); | ||
| $customer->email = $this->order->get_billing_email(); | ||
| $phone_code = CountryUtils::getPhoneCodesByCountry( $this->order->get_billing_country() ); | ||
| $customer->phone = new PhoneNumber( $phone_code[0], $this->order->get_billing_phone(), PhoneNumberType::HOME ); | ||
|
|
||
| return $customer; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a space after the 'if' keyword too. This applies to the other files too.