-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from woocommerce/PCP-288-vaulting-token-creat…
…ion-fails Allow customers to see and delete their saved payments in My Account.
- Loading branch information
Showing
26 changed files
with
5,372 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,2 @@ | ||
node_modules | ||
/assets |
This file contains 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,12 @@ | ||
<?php | ||
/** | ||
* The vaulting module extensions. | ||
* | ||
* @package WooCommerce\PayPalCommerce\Vaulting | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\Vaulting; | ||
|
||
return array(); |
This file contains 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,16 @@ | ||
<?php | ||
/** | ||
* The vaulting module. | ||
* | ||
* @package WooCommerce\PayPalCommerce\Vaulting | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\Vaulting; | ||
|
||
use Dhii\Modular\Module\ModuleInterface; | ||
|
||
return static function (): ModuleInterface { | ||
return new VaultingModule(); | ||
}; |
This file contains 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,23 @@ | ||
{ | ||
"name": "ppcp-vaulting", | ||
"version": "1.0.0", | ||
"license": "GPL-3.0-or-later", | ||
"main": "resources/js/myaccount-payments.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.5", | ||
"babel-loader": "^8.1.0", | ||
"cross-env": "^5.0.1", | ||
"file-loader": "^4.2.0", | ||
"node-sass": "^4.13.0", | ||
"sass-loader": "^8.0.0", | ||
"webpack": "^4.42.1", | ||
"webpack-cli": "^3.1.2", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0" | ||
}, | ||
"scripts": { | ||
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack", | ||
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch", | ||
"dev": "cross-env BABEL_ENV=default webpack --watch" | ||
} | ||
} |
This file contains 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,41 @@ | ||
document.addEventListener( | ||
'DOMContentLoaded', | ||
() => { | ||
jQuery('.ppcp-delete-payment-button').click(async (event) => { | ||
event.preventDefault(); | ||
jQuery(this).prop('disabled', true); | ||
const token = event.target.id; | ||
|
||
const response = await fetch( | ||
PayPalCommerceGatewayVaulting.delete.endpoint, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json' | ||
}, | ||
body: JSON.stringify( | ||
{ | ||
nonce: PayPalCommerceGatewayVaulting.delete.nonce, | ||
token, | ||
} | ||
) | ||
} | ||
); | ||
|
||
const reportError = error => { | ||
alert(error); | ||
} | ||
|
||
if (!response.ok) { | ||
try { | ||
const result = await response.json(); | ||
reportError(result.data); | ||
} catch (exc) { | ||
console.error(exc); | ||
reportError(response.status); | ||
} | ||
} | ||
|
||
window.location.reload(); | ||
}); | ||
}); |
This file contains 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,42 @@ | ||
<?php | ||
/** | ||
* The vaulting module services. | ||
* | ||
* @package WooCommerce\PayPalCommerce\Vaulting | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\Vaulting; | ||
|
||
use WooCommerce\PayPalCommerce\Vaulting\Assets\MyAccountPaymentsAssets; | ||
use WooCommerce\PayPalCommerce\Vaulting\Endpoint\DeletePaymentTokenEndpoint; | ||
|
||
return array( | ||
'vaulting.module-url' => static function ( $container ): string { | ||
return plugins_url( | ||
'/modules/ppcp-vaulting/', | ||
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php' | ||
); | ||
}, | ||
'vaulting.assets.myaccount-payments' => function( $container ) : MyAccountPaymentsAssets { | ||
return new MyAccountPaymentsAssets( | ||
$container->get( 'vaulting.module-url' ) | ||
); | ||
}, | ||
'vaulting.payment-tokens-renderer' => static function (): PaymentTokensRendered { | ||
return new PaymentTokensRendered(); | ||
}, | ||
'vaulting.repository.payment-token' => static function ( $container ): PaymentTokenRepository { | ||
$factory = $container->get( 'api.factory.payment-token' ); | ||
$endpoint = $container->get( 'api.endpoint.payment-token' ); | ||
return new PaymentTokenRepository( $factory, $endpoint ); | ||
}, | ||
'vaulting.endpoint.delete' => function( $container ) : DeletePaymentTokenEndpoint { | ||
return new DeletePaymentTokenEndpoint( | ||
$container->get( 'vaulting.repository.payment-token' ), | ||
$container->get( 'button.request-data' ), | ||
$container->get( 'woocommerce.logger.woocommerce' ) | ||
); | ||
}, | ||
); |
67 changes: 67 additions & 0 deletions
67
modules/ppcp-vaulting/src/Assets/class-myaccountpaymentsassets.php
This file contains 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,67 @@ | ||
<?php | ||
/** | ||
* Register and configure assets for My account PayPal payments page. | ||
* | ||
* @package WooCommerce\PayPalCommerce\Vaulting\Assets | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\Vaulting\Assets; | ||
|
||
use WooCommerce\PayPalCommerce\Vaulting\Endpoint\DeletePaymentTokenEndpoint; | ||
|
||
/** | ||
* Class MyAccountPaymentsAssets | ||
*/ | ||
class MyAccountPaymentsAssets { | ||
|
||
/** | ||
* The URL to the module. | ||
* | ||
* @var string | ||
*/ | ||
private $module_url; | ||
|
||
/** | ||
* WebhooksStatusPageAssets constructor. | ||
* | ||
* @param string $module_url The URL to the module. | ||
*/ | ||
public function __construct( | ||
string $module_url | ||
) { | ||
$this->module_url = untrailingslashit( $module_url ); | ||
} | ||
|
||
/** | ||
* Enqueues the necessary scripts. | ||
* | ||
* @return void | ||
*/ | ||
public function enqueue(): void { | ||
wp_enqueue_script( | ||
'ppcp-vaulting-myaccount-payments', | ||
$this->module_url . '/assets/js/myaccount-payments.js', | ||
array( 'jquery' ), | ||
'1', | ||
true | ||
); | ||
} | ||
|
||
/** | ||
* Localize script. | ||
*/ | ||
public function localize() { | ||
wp_localize_script( | ||
'ppcp-vaulting-myaccount-payments', | ||
'PayPalCommerceGatewayVaulting', | ||
array( | ||
'delete' => array( | ||
'endpoint' => home_url( \WC_AJAX::get_endpoint( DeletePaymentTokenEndpoint::ENDPOINT ) ), | ||
'nonce' => wp_create_nonce( DeletePaymentTokenEndpoint::nonce() ), | ||
), | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.