2009-12-02 16:44:18 +00:00
|
|
|
# -*- mode: cperl -*-
|
|
|
|
use Test::More;
|
2014-03-23 02:31:50 +00:00
|
|
|
if ( !$ENV{WPP_TEST} || !-f $ENV{WPP_TEST} ) {
|
|
|
|
plan skip_all =>
|
|
|
|
'No WPP_TEST env var set. Please see README to run tests';
|
2009-12-02 16:44:18 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-12-07 07:10:55 +00:00
|
|
|
plan tests => 3;
|
2009-12-02 16:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
use_ok( 'Business::PayPal::API::RecurringPayments' );
|
|
|
|
#########################
|
|
|
|
|
|
|
|
require 't/API.pl';
|
|
|
|
|
|
|
|
my %args = do_args();
|
|
|
|
|
2014-03-23 02:31:50 +00:00
|
|
|
my $pp = new Business::PayPal::API::RecurringPayments( %args );
|
2009-12-02 16:44:18 +00:00
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
#$Business::PayPal::API::Debug = 1;
|
2014-03-23 02:31:50 +00:00
|
|
|
my %response = $pp->SetCustomerBillingAgreement(
|
|
|
|
BillingType => 'RecurringPayments',
|
|
|
|
BillingAgreementDescription => '10.00 per month for 1 year',
|
|
|
|
ReturnURL => 'http://www.google.com/',
|
|
|
|
CancelURL => 'http://www.google.com/',
|
|
|
|
BuyerEmail => $args{BuyerEmail},
|
|
|
|
);
|
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
#$Business::PayPal::API::Debug = 0;
|
2009-12-02 16:44:18 +00:00
|
|
|
|
|
|
|
my $token = $response{Token};
|
|
|
|
|
|
|
|
ok( $token, "Got token" );
|
2014-03-23 02:31:50 +00:00
|
|
|
like( $response{Ack}, qr/Success/, "SetCustomerBillingAgreement successful" );
|
2009-12-02 16:44:18 +00:00
|
|
|
|
|
|
|
exit;
|
|
|
|
|
2014-03-23 02:31:50 +00:00
|
|
|
die
|
|
|
|
"No token from PayPal! Check your authentication information and try again."
|
|
|
|
unless $token;
|
2009-12-02 16:44:18 +00:00
|
|
|
|
2014-03-23 02:31:50 +00:00
|
|
|
my $pp_url
|
|
|
|
= "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_customer-billing-agreement&token=$token";
|
2009-12-02 16:44:18 +00:00
|
|
|
|
|
|
|
=pod
|
|
|
|
|
|
|
|
print STDERR <<"_TOKEN_";
|
|
|
|
|
|
|
|
Now paste the following URL into your browser (you'll need to have
|
|
|
|
another browser window already logged into the PayPal developer site):
|
|
|
|
|
|
|
|
$pp_url
|
|
|
|
|
|
|
|
Login to PayPal as the Buyer you specified in '$ENV{WPP_TEST}' and
|
|
|
|
proceed to checkout (this authorizes the transaction represented by
|
|
|
|
the token). When finished, PayPal will redirect you to a non-existent
|
|
|
|
URL:
|
|
|
|
|
|
|
|
http://localhost/return.html?token=$token&PayerID=XXXXXXXXXXXXX
|
|
|
|
|
|
|
|
Notice the *PayerID* URL argument (XXXXXXXXXXXXX) on the redirect from
|
|
|
|
PayPal.
|
|
|
|
_TOKEN_
|
|
|
|
|
|
|
|
print STDERR "\nType or paste that PayerID here and hit Enter: \n";
|
|
|
|
|
|
|
|
my $payerid = <STDIN>; chomp $payerid;
|
|
|
|
|
|
|
|
die "Need a PayerID.\n" unless $payerid;
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
## CreateRecurringPaymentsProfile
|
2009-12-07 07:10:55 +00:00
|
|
|
#$Business::PayPal::API::Debug = 1;
|
2014-03-23 02:31:50 +00:00
|
|
|
my %profile = $pp->CreateRecurringPaymentsProfile(
|
|
|
|
Token => $token,
|
2009-12-02 16:44:18 +00:00
|
|
|
|
|
|
|
## RecurringPaymentProfileDetails
|
|
|
|
SubscriberName => 'Joe Schmoe',
|
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
SubscriberShipperName => 'Schmoe House',
|
2009-12-02 16:44:18 +00:00
|
|
|
SubscriberShipperStreet1 => '1234 Street St.',
|
|
|
|
SubscriberShipperCityName => 'Orem',
|
|
|
|
SubscriberShipperStateOrProvince => 'UT',
|
|
|
|
SubscriberShipperPostalCode => '84222',
|
|
|
|
SubscriberShipperCountry => 'USA',
|
|
|
|
SubscriberShipperPhone => '123-123-1234',
|
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
BillingStartDate => '2009-12-01Z',
|
2009-12-02 16:44:18 +00:00
|
|
|
ProfileReference => 'BH12341234',
|
|
|
|
|
|
|
|
## ScheduleDetails
|
2009-12-07 07:10:55 +00:00
|
|
|
Description => '12 Month Hosting Package: We Love You!',
|
2009-12-02 16:44:18 +00:00
|
|
|
|
2014-03-23 02:31:50 +00:00
|
|
|
InitialAmount => '12.34',
|
2009-12-02 16:44:18 +00:00
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
TrialBillingPeriod => 'Month',
|
2009-12-02 16:44:18 +00:00
|
|
|
TrialBillingFrequency => 1,
|
|
|
|
TrialTotalBillingCycles => 1,
|
|
|
|
TrialAmount => 0.00,
|
|
|
|
TrialShippingAmount => 0.00,
|
|
|
|
TrialTaxAmount => 0.00,
|
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
PaymentBillingPeriod => 'Year',
|
2009-12-02 16:44:18 +00:00
|
|
|
PaymentBillingFrequency => 1,
|
|
|
|
PaymentTotalBillingCycles => 1,
|
|
|
|
PaymentAmount => 95.40,
|
|
|
|
PaymentShippingAmount => 0.00,
|
|
|
|
PaymentTaxAmount => 0.00,
|
|
|
|
|
2014-03-23 02:31:50 +00:00
|
|
|
# MaxFailedPayments => 1,
|
|
|
|
# AutoBillOutstandingAmount => 'AddToNextBilling',
|
|
|
|
);
|
2009-12-02 16:44:18 +00:00
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
#$Business::PayPal::API::Debug = 0;
|
2009-12-02 16:44:18 +00:00
|
|
|
|
|
|
|
## GetBillingAgreementCustomerDetails
|
|
|
|
#$Business::PayPal::API::Debug = 1;
|
2014-03-23 02:31:50 +00:00
|
|
|
my %details = $pp->GetBillingAgreementCustomerDetails( $token );
|
|
|
|
|
2009-12-07 07:10:55 +00:00
|
|
|
#$Business::PayPal::API::Debug = 0;
|
2009-12-02 16:44:18 +00:00
|
|
|
|
2014-03-23 02:31:50 +00:00
|
|
|
like( $details{Ack}, qr/Success/, "details ok" );
|
2009-12-02 16:44:18 +00:00
|
|
|
|