-
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
Open
Moseley258
wants to merge
3
commits into
globalpayments:master
Choose a base branch
from
Moseley258:gpapi_subscriptions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Gateways/Requests/Subscriptions/SubscriptionRequest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The code in this file seems to be indented using spaces and not tabs. This needs to be fixed.