Pay Pal

Unofficial pay pal SDK Hecho en 🇵🇷 por Radamés J. Valentín Reyes


Import

import 'package:unofficial_paypal_sdk/unofficial_paypal_sdk.dart';

Initiate an instance of PayPay

Uses the client ID and client secret to fetch an access token. init() Must be called before any other function. Tokens expire so this function has to be called again before expirations to avoid errors when performing API calls.

PayPal payPal = PayPal(
  clientID: appKey, 
  clientSecret: appSecret,
  sandboxMode: false,//Sandbox mode false to go live. Perform real transactions
);
PayPalAccessToken payPalAccessToken = await payPal.init();
print(payPalAccessToken.access_token);

Catalog Products API


List Products

Gets a list of products saved into your paypal app

PayPalProductsList productsList = await payPal.listProducts();

Create Product

PayPalProduct createdProduct = await payPal.createProduct(
  prefer: Prefer.representation,
  id: id,
  payPalRequestID: id,
  name: "Pay Pal Logo",
  description: "The logo of Pay Pal",
  category: ProductCatogory.ANIMATION,
);
print("Created " + createdProduct.name);
print("Category " + createdProduct.category!);

Update Product

await payPal.updateProduct(
  product_id: createdProduct.id, 
  operation: UpdateProductOperation.replace, 
  attributeToModify: UpdateProductAttribute.category,
  newValue: ProductCatogory.ACCOUNTING,
);

Show Product Details

PayPalProduct updatedProduct = await payPal.showProductDetails(
  product_id: createdProduct.id,
);

Subscriptions API


List plans

ListOfPayPalPlans allPlans = await payPal.listPlans();

Create Subscription Plan

SubscriptionPlan createdSubscription = await payPal.createPlan(
  payPalRequestId: id, 
  product_id: productsList.products.first.id, 
  name: "A test subscription", 
  description: "Just testing the API", 
  billingCycles: [
    BillingCycle(
      frequency: Frequency(
        interval_count: 1,
        interval_unit: "MONTH",
      ), 
      pricing_scheme: PricingScheme(
        value: "5.99",
        currency_code: "USD",
      ), 
      sequence: 1, 
      tenure_type: TenureType.TRIAL, 
      total_cycles: 1,
    ),
    BillingCycle(
      frequency: Frequency(
        interval_count: 1,
        interval_unit: "MONTH",
      ), 
      pricing_scheme: PricingScheme(
        value: "5.99",
        currency_code: "USD",
      ), 
      sequence: 2, 
      tenure_type: TenureType.REGULAR, 
      total_cycles: 1,
    ),
  ], 
  paymentPreferences: PaymentPreferences(
    auto_bill_outstanding: true, 
    setup_fee: SetupFee(
      value: "5",
      currency_code: "USD",
    ), 
    setup_fee_failure_action: SetupFeeFailureAction.CANCEL, 
    payment_failure_threshold: 1,
  ), 
  taxes: Taxes(
    percentage: "11.5", 
    inclusive: false,
  ), 
  quantity_supported: false,
);

Update plan

ListOfPayPalPlans allPlans = await payPal.listPlans();
await payPal.updatePlan(
  id:allPlans.plans.first.id, 
  operation: UpdateSubscriptionPlanOperation.replace,
  attributeToModify: UpdateSubscriptionPlanAttribute.description,
  newValue: "Mi perrito ladra",
);

Show plan details

ListOfPayPalPlans allPlans = await payPal.listPlans();
SubscriptionPlan planWithDetails = await payPal.showPlanDetails(id: allPlans.plans.first.id);

Activate plan

ListOfPayPalPlans allPlans = await payPal.listPlans();
await payPal.activatePlan(id: allPlans.plans.first.id);

Deactivate plan

ListOfPayPalPlans allPlans = await payPal.listPlans();
await payPal.deactivatePlan(id: allPlans.plans.first.id);

Payouts API



Contribute/donate by tapping on the Pay Pal logo/image


Examples

Example 1

String id = uniqueAlphanumeric(tokenLength: 30);
PayPalProduct createdProduct = await payPal.createProduct(
  prefer: Prefer.representation,
  id: id,
  payPalRequestID: id,
  name: "Pay Pal Logo",
  description: "The logo of Pay Pal",
  category: ProductCatogory.ANIMATION,
);
print("Created " + createdProduct.name);
print("Category " + createdProduct.category!);
//Test 
await payPal.updateProduct(
  product_id: createdProduct.id,
  operation: UpdateProductOperation.replace, 
  attributeToModify: UpdateProductAttribute.category,
  newValue: ProductCatogory.ACCOUNTING,
);
PayPalProduct updatedProduct = await payPal.showProductDetails(
  product_id: createdProduct.id,
);
print(updatedProduct.category);

Example 2

String id = uniqueAlphanumeric(tokenLength: 30);
await payPal.init();
PayPalProductsList productsList = await payPal.listProducts();
SubscriptionPlan createdSubscription = await payPal.createPlan(
  payPalRequestId: id, 
  product_id: productsList.products.first.id, 
  name: "A test subscription", 
  description: "Just testing the API", 
  billingCycles: [
    BillingCycle(
      frequency: Frequency(
        interval_count: 1,
        interval_unit: "MONTH",
      ), 
      pricing_scheme: PricingScheme(
        value: "5.99",
        currency_code: "USD",
      ), 
      sequence: 1, 
      tenure_type: TenureType.TRIAL, 
      total_cycles: 1,
    ),
    BillingCycle(
      frequency: Frequency(
        interval_count: 1,
        interval_unit: "MONTH",
      ), 
      pricing_scheme: PricingScheme(
        value: "5.99",
        currency_code: "USD",
      ), 
      sequence: 2, 
      tenure_type: TenureType.REGULAR, 
      total_cycles: 1,
    ),
  ], 
  paymentPreferences: PaymentPreferences(
    auto_bill_outstanding: true, 
    setup_fee: SetupFee(
      value: "5",
      currency_code: "USD",
    ), 
    setup_fee_failure_action: SetupFeeFailureAction.CANCEL, 
    payment_failure_threshold: 1,
  ), 
  taxes: Taxes(
    percentage: "11.5", 
    inclusive: false,
  ), 
  quantity_supported: false,
);
print(createdSubscription.name);

References

Libraries

parsing
unofficial_paypal_sdk