Skip to content

Commit

Permalink
using api endpoint. adjusted some types
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeiroguilherme committed Dec 6, 2024
1 parent d1560d2 commit 4f6dc07
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/lib/src/components/PayPalFastlane/FastlaneSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { convertAdyenLocaleToFastlaneLocale } from './utils/convert-locale';
import Script from '../../utils/Script';
import AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';
import type {
ComponentConfiguration,
FastlanePaymentMethodConfiguration,
FastlaneWindowInstance,
FastlaneAuthenticatedCustomerResult,
FastlaneShippingAddressSelectorResult,
Expand Down Expand Up @@ -59,7 +59,7 @@ class FastlaneSDK {
/**
* TODO: Waiting for PayPal to provide the specific methods to fetch sessionId and Consent UI details
*/
public getComponentConfiguration(authResult: FastlaneAuthenticatedCustomerResult): ComponentConfiguration {
public getComponentConfiguration(authResult: FastlaneAuthenticatedCustomerResult): FastlanePaymentMethodConfiguration {
if (!authResult) {
throw new AdyenCheckoutError(
'IMPLEMENTATION_ERROR',
Expand All @@ -76,7 +76,7 @@ class FastlaneSDK {
email: this.authenticatedShopper.email,
tokenId: authResult.profileData.card.id,
lastFour: authResult.profileData.card.paymentSource.card.lastDigits,
brand: authResult.profileData.card.paymentSource.card.brand
brand: authResult.profileData.card.paymentSource.card.brand.toLowerCase()
}
};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ export interface FastlaneTokenData {
function requestFastlaneToken(url: string, clientKey: string): Promise<FastlaneTokenData> {
const path = `utility/v1/payPalFastlane/tokens?clientKey=${clientKey}`;
return httpPost<FastlaneTokenData>({ loadingContext: url, path, errorLevel: 'fatal' });

/**
* TODO: Endpoint is not ready. The only way to test right now is mocking the response here
*/
// return Promise.resolve({
// id: '2747bd08-783a-45c6-902b-3efbda5497b7',
// clientId: 'AXy9hIzWB6h_LjZUHjHmsbsiicSIbL4GKOrcgomEedVjduUinIU4C2llxkW5p0OG0zTNgviYFceaXEnj',
// merchantId: 'C3UCKQHMW4948',
// value: 'eyJraWQiOiJkMTA2ZTUwNjkzOWYxMWVlYjlkMTAyNDJhYzEyMDAwMiIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJpc3MiOiJodHRwczovL2FwaS5zYW5kYm94LnBheXBhbC5jb20iLCJhdWQiOlsiaHR0cHM6Ly9hcGkuYnJhaW50cmVlZ2F0ZXdheS5jb20iLCJjaGVja291dC1wbGF5Z3JvdW5kLm5ldGxpZnkuYXBwIl0sInN1YiI6Ik02VE5BRVNaNUZHTk4iLCJhY3IiOlsiY2xpZW50Il0sInNjb3BlIjpbIkJyYWludHJlZTpWYXVsdCJdLCJvcHRpb25zIjp7fSwiYXoiOiJjY2cxOC5zbGMiLCJleHRlcm5hbF9pZCI6WyJQYXlQYWw6QzNVQ0tRSE1XNDk0OCIsIkJyYWludHJlZTozZGI4aG5rdHJ0bXpzMmd0Il0sImV4cCI6MTczMzIyODY5MSwiaWF0IjoxNzMzMjI3NzkxLCJqdGkiOiJVMkFBTGM5a2VYdFByRTh6OHZPTEptUDI2cV94akcyN24tNHJHdUhCMHB1XzE1aHY0bGlrdmFobmlXdjJzbmN0UWFEdjFscFhxTlk0U1VmYkhwR0tnTjNYTlM5OGpaUnB0WWlFbkhZN1JxS21TQUpXZVFIRFdPc3AxRllaVUd3ZyJ9.3Aw31ttXYSCmUcklNi6BrGqWPTw2Z42XDZW_r4SFTZBXz9aUXu3uy6k2cG7WChGx0vss7qFq_3XYswS8t7T9CQ',
// expiresAt: '2024-11-01T13:34:01.804+00:00'
// });
}

export default requestFastlaneToken;
4 changes: 2 additions & 2 deletions packages/lib/src/components/PayPalFastlane/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type FastlaneComponentConfiguration = {
};
};

type CardComponentConfiguration = {
type FastlaneCardComponentConfiguration = {
paymentType: 'card';
configuration: {
fastlaneConfiguration: {
Expand All @@ -117,7 +117,7 @@ type CardComponentConfiguration = {
};
};

export type ComponentConfiguration = FastlaneComponentConfiguration | CardComponentConfiguration;
export type FastlanePaymentMethodConfiguration = FastlaneComponentConfiguration | FastlaneCardComponentConfiguration;

export interface FastlaneSDKConfiguration {
clientKey: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Default: FastlaneStory = {
paymentMethods: [
{
type: 'scheme',
name: 'Card',
name: 'Cards',
brands: ['mc', 'visa']
},
{
Expand All @@ -30,7 +30,7 @@ export const Default: FastlaneStory = {
type: 'paypal'
},
{
name: 'Fastlane',
name: 'Cards',
type: 'fastlane',
brands: ['mc', 'visa']
}
Expand All @@ -47,7 +47,7 @@ export const WithMockedRecognizedFlow: FastlaneStory = {
paymentMethods: [
{
type: 'scheme',
name: 'Card',
name: 'Cards',
brands: ['mc', 'visa']
},
{
Expand All @@ -56,7 +56,7 @@ export const WithMockedRecognizedFlow: FastlaneStory = {
type: 'paypal'
},
{
name: 'Fastlane',
name: 'Cards',
type: 'fastlane',
brands: ['mc', 'visa']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import Fastlane from '../../../../src/components/PayPalFastlane';
import { Checkout } from '../../Checkout';
import { ComponentContainer } from '../../ComponentContainer';
import { GuestShopperForm } from './components/GuestShopperForm';
import type { FastlanePaymentMethodConfiguration } from '../../../../src/components/PayPalFastlane/types';

interface Props {
checkoutConfig: GlobalStoryProps;
}

export const FastlaneInSinglePageApp = ({ checkoutConfig }: Props) => {
const [componentConfig, setComponentConfig] = useState<any>(null);
const [componentConfig, setComponentConfig] = useState<FastlanePaymentMethodConfiguration>(null);

const handleOnCheckoutStep = config => {
console.log('Component config:', config);
Expand All @@ -36,14 +37,7 @@ export const FastlaneInSinglePageApp = ({ checkoutConfig }: Props) => {
showStoredPaymentMethods: false,
paymentMethodComponents: [Card, PayPal, Fastlane],
paymentMethodsConfiguration: {
fastlane: {
tokenId: 'xxx',
customerId: 'sss',
lastFour: '1111',
brand: 'visa',
email: 'email@adyen.com',
fastlaneSessionId: 'zzz'
}
[componentConfig.paymentType]: componentConfig.configuration
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const CollectEmail = ({ fastlaneSdk, onFastlaneLookup, onEditEmail }: Col
const handleButtonClick = async () => {
try {
const authResult = await fastlaneSdk.authenticate(email);
console.log('triggerAuthenticationFlow result:', authResult);
onFastlaneLookup(authResult);
setViewOnly(true);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const GuestShopperForm = ({ onCheckoutStep }: GuestShopperFormProps) => {

const handleOnCheckoutClick = (shippingAddress?: any) => {
console.log('Shipping address', shippingAddress);

const componentConfig = fastlane.getComponentConfiguration(fastlaneAuthResult);
onCheckoutStep(componentConfig);
};
Expand Down

0 comments on commit 4f6dc07

Please sign in to comment.