From cc7eb03ce31573feda6df6e079cdb7eb397b1cd7 Mon Sep 17 00:00:00 2001 From: jclausen Date: Tue, 23 Jul 2024 12:19:55 -0600 Subject: [PATCH] format updates --- models/processor/BaseProcessor.cfc | 3 +- models/processor/StripeProcessor.cfc | 55 +++--- .../tests/resources/BaseProcessorTest.cfc | 163 +++++++++--------- 3 files changed, 118 insertions(+), 103 deletions(-) diff --git a/models/processor/BaseProcessor.cfc b/models/processor/BaseProcessor.cfc index 25f6771..04bd44a 100755 --- a/models/processor/BaseProcessor.cfc +++ b/models/processor/BaseProcessor.cfc @@ -10,7 +10,8 @@ component accessors="true" { /** * Get a new reponse object */ - function newResponse() provider="ProcessorResponse@cbpayments"{} + function newResponse() provider="ProcessorResponse@cbpayments"{ + } /** * Retrieve a human readable name for the processor diff --git a/models/processor/StripeProcessor.cfc b/models/processor/StripeProcessor.cfc index 18de368..157d38b 100755 --- a/models/processor/StripeProcessor.cfc +++ b/models/processor/StripeProcessor.cfc @@ -2,8 +2,8 @@ * A cool processor/Stripe entity */ component - extends ="BaseProcessor" - delegates="DateTime@coreDelegates" + extends ="BaseProcessor" + delegates ="DateTime@coreDelegates" implements="IPaymentProcessor" singleton { @@ -81,9 +81,7 @@ component var processorResponse = variables.stripe.charges.capture( charge_id = arguments.chargeId ); // Capture it baby! - oResponse.setContent( - formatChargeResponse( processorResponse.content ) - ); + oResponse.setContent( formatChargeResponse( processorResponse.content ) ); // Check for errors if ( processorResponse.status >= 300 ) { @@ -127,9 +125,7 @@ component var processorResponse = variables.stripe.charges.create( argumentCollection = arguments ); // Charge it baby! - oResponse.setContent( - formatChargeResponse( processorResponse.content ) - ); + oResponse.setContent( formatChargeResponse( processorResponse.content ) ); // Check for errors if ( processorResponse.status >= 300 ) { @@ -145,6 +141,7 @@ component /** * Make a refund on the processor + * * @charge The identifier of the charge to refund. * @amount The amount in cents to refund, if not sent then the entire charge is refunded (Optional) * @reason A reason of why the refund (Optional) @@ -214,9 +211,7 @@ component ); // Create customer - oResponse.setContent( - processorResponse.content - ); + oResponse.setContent( processorResponse.content ); // Check for errors if ( processorResponse.status >= 300 ) { @@ -250,7 +245,10 @@ component log.debug( "Stripe list customers starting: #serializeJSON( arguments )#" ); } - var processorResponse = variables.stripe.customers.list( limit = arguments.limit, offset = arguments.offset ); + var processorResponse = variables.stripe.customers.list( + limit = arguments.limit, + offset = arguments.offset + ); // List customers oResponse.setContent( processorResponse.content ); @@ -362,11 +360,12 @@ component ProcessorResponse function cancelSubscription( required subscriptionId, struct metadata = {} ){ var oResponse = newResponse(); - var processorResponse = variables.stripe.subscriptions.update( arguments.subscriptionId, { cancel_at_period_end : true } ); - // Associate payment method as default - oResponse.setContent( - processorResponse.content + var processorResponse = variables.stripe.subscriptions.update( + arguments.subscriptionId, + { cancel_at_period_end : true } ); + // Associate payment method as default + oResponse.setContent( processorResponse.content ); // Check for errors if ( processorResponse.status >= 300 ) { @@ -387,7 +386,10 @@ component ProcessorResponse function resumeSubscription( required subscriptionId, struct metadata = {} ){ var oResponse = newResponse(); - var processorResponse = variables.stripe.subscriptions.update( arguments.subscriptionId, { cancel_at_period_end : false } ); + var processorResponse = variables.stripe.subscriptions.update( + arguments.subscriptionId, + { cancel_at_period_end : false } + ); // Associate payment method as default oResponse.setContent( processorResponse.content ); @@ -417,12 +419,13 @@ component ){ var oResponse = newResponse(); - var processorResponse = variables.stripe.subscriptions.update( arguments.subscriptionId, { quantity : arguments.quantity } ); + var processorResponse = variables.stripe.subscriptions.update( + arguments.subscriptionId, + { quantity : arguments.quantity } + ); // Associate payment method as default - oResponse.setContent( - processorResponse.content - ); + oResponse.setContent( processorResponse.content ); // Check for errors if ( processorResponse.status >= 300 ) { @@ -575,7 +578,7 @@ component { customer : arguments.providerCustomerId } ).content; - var processorResponse = variables.stripe.customers.update( + var processorResponse = variables.stripe.customers.update( arguments.providerCustomerId, { invoice_settings : { default_payment_method : paymentMethod.id } } ); @@ -651,7 +654,13 @@ component * @epochSeconds */ string function fromUnixSeconds( required numeric epochSeconds ){ - return getISOTime( dateAdd( "s", arguments.epochSeconds, "1970-01-01T00:00:00Z" ) ); + return getISOTime( + dateAdd( + "s", + arguments.epochSeconds, + "1970-01-01T00:00:00Z" + ) + ); } /** diff --git a/test-harness/tests/resources/BaseProcessorTest.cfc b/test-harness/tests/resources/BaseProcessorTest.cfc index dacd59d..2cb8f5c 100644 --- a/test-harness/tests/resources/BaseProcessorTest.cfc +++ b/test-harness/tests/resources/BaseProcessorTest.cfc @@ -55,30 +55,31 @@ component extends="coldbox.system.testing.BaseTestCase" { expect( response.getError() ).toBeFalse(); expect( response.getContent().paid ).toBeTrue(); - expect( response.getContent() ).toBeStruct() - .toHaveKey( "id" ) - .toHaveKey( "object" ) - .toHaveKey( "amount" ) - .toHaveKey( "amount_captured" ) - .toHaveKey( "amount_refunded" ) - .toHaveKey( "balance_transaction" ) - .toHaveKey( "billing_details" ) - .toHaveKey( "processor" ) - .toHaveKey( "captured" ) - .toHaveKey( "created" ) - .toHaveKey( "currency" ) - .toHaveKey( "disputed" ) - .toHaveKey( "fraud_details" ) - .toHaveKey( "livemode" ) - .toHaveKey( "metadata" ) - .toHaveKey( "outcome" ) - .toHaveKey( "paid" ) - .toHaveKey( "payment_method" ) - .toHaveKey( "payment_method_details" ) - .toHaveKey( "receipt_url" ) - .toHaveKey( "refunded" ) - .toHaveKey( "status" ); - variables.testCharge = response.getContent().id; + expect( response.getContent() ) + .toBeStruct() + .toHaveKey( "id" ) + .toHaveKey( "object" ) + .toHaveKey( "amount" ) + .toHaveKey( "amount_captured" ) + .toHaveKey( "amount_refunded" ) + .toHaveKey( "balance_transaction" ) + .toHaveKey( "billing_details" ) + .toHaveKey( "processor" ) + .toHaveKey( "captured" ) + .toHaveKey( "created" ) + .toHaveKey( "currency" ) + .toHaveKey( "disputed" ) + .toHaveKey( "fraud_details" ) + .toHaveKey( "livemode" ) + .toHaveKey( "metadata" ) + .toHaveKey( "outcome" ) + .toHaveKey( "paid" ) + .toHaveKey( "payment_method" ) + .toHaveKey( "payment_method_details" ) + .toHaveKey( "receipt_url" ) + .toHaveKey( "refunded" ) + .toHaveKey( "status" ); + variables.testCharge = response.getContent().id; } ); it( "can make a test preAuth", function(){ @@ -90,67 +91,71 @@ component extends="coldbox.system.testing.BaseTestCase" { expect( response.getError() ).toBeFalse(); expect( response.getContent().paid ).toBeTrue(); - expect( response.getContent() ).toBeStruct() - .toHaveKey( "id" ) - .toHaveKey( "object" ) - .toHaveKey( "amount" ) - .toHaveKey( "amount_captured" ) - .toHaveKey( "amount_refunded" ) - .toHaveKey( "billing_details" ) - .toHaveKey( "processor" ) - .toHaveKey( "captured" ) - .toHaveKey( "created" ) - .toHaveKey( "currency" ) - .toHaveKey( "disputed" ) - .toHaveKey( "fraud_details" ) - .toHaveKey( "livemode" ) - .toHaveKey( "metadata" ) - .toHaveKey( "outcome" ) - .toHaveKey( "paid" ) - .toHaveKey( "payment_method" ) - .toHaveKey( "payment_method_details" ) - .toHaveKey( "receipt_url" ) - .toHaveKey( "refunded" ) - .toHaveKey( "status" ); - expect( response.getContent().captured ).toBeFalse(); - expect( structKeyExists( response.getContent(), "balance_transaction" ) ).toBeFalse(); - variables.testPreAuth = response.getContent().id; + expect( response.getContent() ) + .toBeStruct() + .toHaveKey( "id" ) + .toHaveKey( "object" ) + .toHaveKey( "amount" ) + .toHaveKey( "amount_captured" ) + .toHaveKey( "amount_refunded" ) + .toHaveKey( "billing_details" ) + .toHaveKey( "processor" ) + .toHaveKey( "captured" ) + .toHaveKey( "created" ) + .toHaveKey( "currency" ) + .toHaveKey( "disputed" ) + .toHaveKey( "fraud_details" ) + .toHaveKey( "livemode" ) + .toHaveKey( "metadata" ) + .toHaveKey( "outcome" ) + .toHaveKey( "paid" ) + .toHaveKey( "payment_method" ) + .toHaveKey( "payment_method_details" ) + .toHaveKey( "receipt_url" ) + .toHaveKey( "refunded" ) + .toHaveKey( "status" ); + expect( response.getContent().captured ).toBeFalse(); + expect( structKeyExists( response.getContent(), "balance_transaction" ) ).toBeFalse(); + variables.testPreAuth = response.getContent().id; } ); it( "Can capture a pre-authorization", function(){ - if( !variables.keyExists( "testPreAuth" ) ){ - variables.testPreAuth = variables.model.preAuthorize( - amount = 100, - source = "tok_visa", - description = "Unit test charge" - ).getContent().id; + if ( !variables.keyExists( "testPreAuth" ) ) { + variables.testPreAuth = variables.model + .preAuthorize( + amount = 100, + source = "tok_visa", + description = "Unit test charge" + ) + .getContent() + .id; } var response = variables.model.capture( variables.testPreAuth ); - expect( response.getContent() ).toBeStruct() - .toHaveKey( "id" ) - .toHaveKey( "object" ) - .toHaveKey( "amount" ) - .toHaveKey( "amount_captured" ) - .toHaveKey( "amount_refunded" ) - .toHaveKey( "balance_transaction" ) - .toHaveKey( "billing_details" ) - .toHaveKey( "processor" ) - .toHaveKey( "captured" ) - .toHaveKey( "created" ) - .toHaveKey( "currency" ) - .toHaveKey( "disputed" ) - .toHaveKey( "fraud_details" ) - .toHaveKey( "livemode" ) - .toHaveKey( "metadata" ) - .toHaveKey( "outcome" ) - .toHaveKey( "paid" ) - .toHaveKey( "payment_method" ) - .toHaveKey( "payment_method_details" ) - .toHaveKey( "receipt_url" ) - .toHaveKey( "refunded" ) - .toHaveKey( "status" ); - + expect( response.getContent() ) + .toBeStruct() + .toHaveKey( "id" ) + .toHaveKey( "object" ) + .toHaveKey( "amount" ) + .toHaveKey( "amount_captured" ) + .toHaveKey( "amount_refunded" ) + .toHaveKey( "balance_transaction" ) + .toHaveKey( "billing_details" ) + .toHaveKey( "processor" ) + .toHaveKey( "captured" ) + .toHaveKey( "created" ) + .toHaveKey( "currency" ) + .toHaveKey( "disputed" ) + .toHaveKey( "fraud_details" ) + .toHaveKey( "livemode" ) + .toHaveKey( "metadata" ) + .toHaveKey( "outcome" ) + .toHaveKey( "paid" ) + .toHaveKey( "payment_method" ) + .toHaveKey( "payment_method_details" ) + .toHaveKey( "receipt_url" ) + .toHaveKey( "refunded" ) + .toHaveKey( "status" ); } ); it( "Will error on a fake refund", function(){